- 0BD7662525269421638C3CF0B5013C4E89B3181BE9D081FD6CE4CAC5AFD731AE831EEAE39F854BCBD5D31A134C47D1083F3C92A44F6DDF64D6160DE04E4D561C
+ 9C01F9EA1E1A4A1DC1397AEA8621C926DCBAADB9FB07B2356E0DF61F3C7FFAF2CEE2CBE2D036850A2CAD4EE5B51AB532B9F3D263F0271B21C9AC86B013D17457
smg_comms/c_wrappers/c_wrappers.c
(27 . 10)(27 . 10)
5 MPI u = mpi_alloc(nlimbs_a);
6 MPI v = mpi_alloc(nlimbs_b);
7
8 //set the given octets as the values of the 2 MPIs
9 //set the given octets as the values of the 2 MPIs and normalize
10 //the sign is set to 0 (last parameter).
11 mpi_set_buffer(u, a, len_a, 0);
12 mpi_set_buffer(v, b, len_b, 0);
13 mpi_set_normalized(u, a, len_a, 0);
14 mpi_set_normalized(v, b, len_b, 0);
15
16 //compare the MPIs as numbers and store the result
17 result = mpi_cmp(u, v);
(66 . 17)(66 . 16)
19 MPI out_mpi = mpi_alloc(nlimbs_out);
20
21 //set input as buffer for in_mpi
22 mpi_set_buffer(in_mpi, input, len_input, 0);
23
24 mpi_set_normalized(in_mpi, input, len_input, 0);
25 //create public key structure and set its contents to given n, e
26 RSA_public_key pk;
27 unsigned int nlimbs_n = mpi_nlimb_hint_from_nbytes( len_n );
28 unsigned int nlimbs_e = mpi_nlimb_hint_from_nbytes( len_e );
29 pk.n = mpi_alloc(nlimbs_n);
30 pk.e = mpi_alloc(nlimbs_e);
31 mpi_set_buffer(pk.n, n, len_n, 0);
32 mpi_set_buffer(pk.e, e, len_e, 0);
33
34 //NB MPI lib gets STUCK on 0-leading MPIs so set + normalize
35 mpi_set_normalized(pk.n, n, len_n, 0);
36 mpi_set_normalized(pk.e, e, len_e, 0);
37 //call rsa public_key encryption and retrieve the result, storing it in out
38 public_rsa( out_mpi, in_mpi, &pk);
39 int len = len_out;
(118 . 7)(117 . 7)
41 MPI out_mpi = mpi_alloc(nlimbs_out);
42
43 //set input as buffer for in_mpi
44 mpi_set_buffer(in_mpi, input, len_input, 0);
45 mpi_set_normalized(in_mpi, input, len_input, 0);
46
47 //create private key structure and set its contents to given n,e,d,p,q,u
48 RSA_secret_key sk;
(134 . 12)(133 . 13)
50 sk.p = mpi_alloc(nlimbs_p);
51 sk.q = mpi_alloc(nlimbs_q);
52 sk.u = mpi_alloc(nlimbs_u);
53 mpi_set_buffer(sk.n, n, len_n, 0);
54 mpi_set_buffer(sk.e, e, len_e, 0);
55 mpi_set_buffer(sk.d, d, len_d, 0);
56 mpi_set_buffer(sk.p, p, len_p, 0);
57 mpi_set_buffer(sk.q, q, len_q, 0);
58 mpi_set_buffer(sk.u, u, len_u, 0);
59 //HAVE TO set AND normalize those or lib MPI gets stuck idiotically on 0-led
60 mpi_set_normalized(sk.n, n, len_n, 0);
61 mpi_set_normalized(sk.e, e, len_e, 0);
62 mpi_set_normalized(sk.d, d, len_d, 0);
63 mpi_set_normalized(sk.p, p, len_p, 0);
64 mpi_set_normalized(sk.q, q, len_q, 0);
65 mpi_set_normalized(sk.u, u, len_u, 0);
66
67 //call rsa secret_key encryption and retrieve the result, storing it in out
68 secret_rsa( out_mpi, in_mpi, &sk );
(220 . 3)(220 . 9)
70
71 xfree( buffer ); //free the buffer that was allocated by mpi_get_buffer
72 }
73
74 void mpi_set_normalized(MPI m, const char *buffer,
75 unsigned int noctets, int sign) {
76 mpi_set_buffer( m, buffer, noctets, sign );
77 mpi_normalize( m );
78 }