OpenCores
URL https://opencores.org/ocsvn/rsa_512/rsa_512/trunk

Subversion Repositories rsa_512

[/] [rsa_512/] [trunk/] [src/] [constant_gen.c] - Blame information for rev 4

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 jcastillo
#include <stdio.h>
2
#include <gmp.h>
3
#include <string.h>
4
#include <sys/types.h>
5
#include <sys/stat.h>
6
#include <fcntl.h>
7
#include <unistd.h>
8
#include <sys/mman.h>
9
 
10
#define uint16 unsigned short int
11
#define uint32 unsigned int
12
#define uint64 unsigned long long int
13
#define WORD_SIZE 32
14
 
15
 
16
uint32 getMpzSize(mpz_t n)
17
{
18
 
19
   return (mpz_size(n)*2);
20
 
21
}
22
 
23
uint16 getlimb(mpz_t n, int i)
24
{
25
   uint32 aux=mpz_getlimbn(n,i/2);
26
   if(i%2 == 0)
27
     return (uint16) (aux&0xffff);
28
   return (uint16) (aux>>16);
29
 
30
}
31
 
32
 
33
 
34
int main()
35
{
36
 
37
    int i;
38
 
39
    mpz_t m,x,y,r,r_aux, n_cons, zero, recons;
40
 
41
    char *template;
42
 
43
    mpz_init_set_str(m,"8de7066f67be16fcacd05d319b6729cd85fe698c07cec504776146eb7a041d9e3cacbf0fcd86441981c0083eed1f8f1b18393f0b186e47ce1b7b4981417b491",16); //mpz_init_set_str(m,"c3217fff",16);
44
 
45
    mpz_init(r);
46
    mpz_init(r_aux);
47
    mpz_init(n_cons);
48
    mpz_init_set_ui(zero,0);
49
 
50
    //Calculo de la constante para salir de la representacion de montgomery
51
    mpz_ui_pow_ui(r,2,16*(getMpzSize(m)+1));
52
    mpz_mul(r_aux,r,r);
53
    mpz_mod(r_aux,r_aux,m);
54
 
55
    mpz_sub(n_cons,zero,m);
56
    mpz_invert(n_cons,n_cons,r);
57
 
58
 
59
 
60
    printf    ("n_c <= %x;\n\n", (uint32)mpz_getlimbn(n_cons,0)&0xffff);
61
    gmp_printf("r_c <= %Zx\n\n", r_aux);
62
 
63
    return 0;
64
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.