- D3DF108B121830777634FA225DD26165762168EE632C81906B9FEB22B43017360F77FAE03CE53F4EEEC2B81EB28249BCC6542D50AE0FEC9F3F1C0D33EB6B3C20
+ F0D2AC0848E2E2B0EF2826F5E5D747A4E9A8FC20B79C2FCCDB02B390C14F2B1B59902024F294E28710844F6B3512537C23F9B46B887015F4556C8C31262CCFF4
eucrypt/smg_rsa/include/smg_rsa.h
(15 . 6)(15 . 21)
5 */
6 static const int KEY_LENGTH_OCTETS = 512;
7
8 typedef struct {
9 MPI n; /* modulus */
10 MPI e; /* public exponent */
11 } RSA_public_key;
12
13 typedef struct {
14 MPI n; /* public modulus */
15 MPI e; /* public exponent */
16 MPI d; /* private exponent: e*d=1 mod phi */
17 MPI p; /* prime p */
18 MPI q; /* prime q */
19 MPI u; /* inverse of p mod q */
20 } RSA_secret_key;
21
22
23 /*********truerandom.c*********/
24
25 /*
(86 . 6)(101 . 68)
27 */
28 void gen_random_prime( unsigned int noctets, MPI output);
29
30 /*********rsa.c*********/
31 /*
32 * Generates a pair of public+private RSA keys using directly the entropy source
33 * specified in eucrypt/smg_rsa/include/knobs.h
34 *
35 * ALL RSA keys are 4096 bits out of 2 2048 bits primes, as per TMSR spec.
36 *
37 * @param sk a fully-allocated structure to hold the generated keypair (secret
38 key structure holds all the elements anyway, public key is a subset of this)
39 *
40 * NB: this procedure does NOT allocate memory for components in sk!
41 * caller should ALLOCATE enough memory for all the MPIs in sk
42 * Precondition:
43 * MPIs in sk have known allocated memory for the nlimbs fitting their TMSR size
44 */
45 void gen_keypair( RSA_secret_key *sk );
46
47 /****************
48 * Public key operation. Encrypt input with pk and store result into output.
49 *
50 * output = input^e mod n , where e,n are elements of pkey.
51 * NB: caller should allocate *sufficient* memory for output to hold the result.
52 * NB: NO checks are made on input!
53 *
54 * @param output MPI with enough allocated memory to hold result of encryption
55 * @param input MPI containing content to encrypt; it *has to be* different from
56 output!
57 * @param pk the public key that will be used to encrypt input
58 *
59 * Precondition:
60 * output != input
61 * Output and input have to be two distinct MPIs because of the sorry state of
62 the underlying mpi lib that can't handle properly the case when those are the
63 same.
64 */
65 void public_rsa( MPI output, MPI input, RSA_public_key *pk );
66
67
68 /****************
69 * Secret key operation. Decrypt input with sk and store result in output.
70 *
71 * output = input^d mod n , where d, n are elements of skey.
72 *
73 * This implementation uses the Chinese Remainder Theorem (CRT):
74 *
75 * out1 = input ^ (d mod (p-1)) mod p
76 * out2 = input ^ (d mod (q-1)) mod q
77 * h = u * (out2 - out1) mod q
78 * output = out1 + h * p
79 *
80 * where out1, out2 and h are intermediate values, d,n,p,q,u are elements of
81 skey. By using CRT, encryption is *faster*. Decide for yourself if this fits
82 your needs though!
83 * NB: it is the caller's responsibility to allocate memory for output!
84 * NB: NO checks are made on input!
85 *
86 * @param output MPI with enough allocated memory to hold result of decryption
87 * @param input MPI containing content to decrypt
88 * @param sk the secret key that will be used to decrypt input
89 */
90 void secret_rsa( MPI output, MPI input, RSA_secret_key *sk );
91
92
93 #endif /*SMG_RSA*/
94