Mercurial > dropbear
comparison libtomcrypt/src/pk/katja/katja_make_key.c @ 1511:5916af64acd4 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 17 Feb 2018 19:29:51 +0800 |
parents | 6dba84798cd5 |
children |
comparison
equal
deleted
inserted
replaced
1457:32f990cc96b1 | 1511:5916af64acd4 |
---|---|
3 * LibTomCrypt is a library that provides various cryptographic | 3 * LibTomCrypt is a library that provides various cryptographic |
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | |
9 * Tom St Denis, [email protected], http://libtom.org | |
10 */ | 8 */ |
11 #include "tomcrypt.h" | 9 #include "tomcrypt.h" |
12 | 10 |
13 /** | 11 /** |
14 @file katja_make_key.c | 12 @file katja_make_key.c |
15 Katja key generation, Tom St Denis | 13 Katja key generation, Tom St Denis |
16 */ | 14 */ |
17 | 15 |
18 #ifdef MKAT | 16 #ifdef LTC_MKAT |
19 | 17 |
20 /** | 18 /** |
21 Create a Katja key | 19 Create a Katja key |
22 @param prng An active PRNG state | 20 @param prng An active PRNG state |
23 @param wprng The index of the PRNG desired | 21 @param wprng The index of the PRNG desired |
24 @param size The size of the modulus (key size) desired (octets) | 22 @param size The size of the modulus (key size) desired (octets) |
25 @param key [out] Destination of a newly created private key pair | 23 @param key [out] Destination of a newly created private key pair |
27 */ | 25 */ |
28 int katja_make_key(prng_state *prng, int wprng, int size, katja_key *key) | 26 int katja_make_key(prng_state *prng, int wprng, int size, katja_key *key) |
29 { | 27 { |
30 void *p, *q, *tmp1, *tmp2; | 28 void *p, *q, *tmp1, *tmp2; |
31 int err; | 29 int err; |
32 | 30 |
33 LTC_ARGCHK(key != NULL); | 31 LTC_ARGCHK(key != NULL); |
34 LTC_ARGCHK(ltc_mp.name != NULL); | 32 LTC_ARGCHK(ltc_mp.name != NULL); |
35 | 33 |
36 if ((size < (MIN_KAT_SIZE/8)) || (size > (MAX_KAT_SIZE/8))) { | 34 if ((size < (MIN_KAT_SIZE/8)) || (size > (MAX_KAT_SIZE/8))) { |
37 return CRYPT_INVALID_KEYSIZE; | 35 return CRYPT_INVALID_KEYSIZE; |
66 | 64 |
67 /* n=p^2q and 1/n mod pq */ | 65 /* n=p^2q and 1/n mod pq */ |
68 if ((err = mp_copy( p, key->p)) != CRYPT_OK) { goto error2; } | 66 if ((err = mp_copy( p, key->p)) != CRYPT_OK) { goto error2; } |
69 if ((err = mp_copy( q, key->q)) != CRYPT_OK) { goto error2; } | 67 if ((err = mp_copy( q, key->q)) != CRYPT_OK) { goto error2; } |
70 if ((err = mp_mul(key->p, key->q, key->pq)) != CRYPT_OK) { goto error2; } /* tmp1 = pq */ | 68 if ((err = mp_mul(key->p, key->q, key->pq)) != CRYPT_OK) { goto error2; } /* tmp1 = pq */ |
71 if ((err = mp_mul(key->pq, key->p, key->N)) != CRYPT_OK) { goto error2; } /* N = p^2q */ | 69 if ((err = mp_mul(key->pq, key->p, key->N)) != CRYPT_OK) { goto error2; } /* N = p^2q */ |
72 if ((err = mp_sub_d( p, 1, tmp1)) != CRYPT_OK) { goto error2; } /* tmp1 = q-1 */ | 70 if ((err = mp_sub_d( p, 1, tmp1)) != CRYPT_OK) { goto error2; } /* tmp1 = q-1 */ |
73 if ((err = mp_sub_d( q, 1, tmp2)) != CRYPT_OK) { goto error2; } /* tmp2 = p-1 */ | 71 if ((err = mp_sub_d( q, 1, tmp2)) != CRYPT_OK) { goto error2; } /* tmp2 = p-1 */ |
74 if ((err = mp_lcm(tmp1, tmp2, key->d)) != CRYPT_OK) { goto error2; } /* tmp1 = lcd(p-1,q-1) */ | 72 if ((err = mp_lcm(tmp1, tmp2, key->d)) != CRYPT_OK) { goto error2; } /* tmp1 = lcd(p-1,q-1) */ |
75 if ((err = mp_invmod( key->N, key->d, key->d)) != CRYPT_OK) { goto error2; } /* key->d = 1/N mod pq */ | 73 if ((err = mp_invmod( key->N, key->d, key->d)) != CRYPT_OK) { goto error2; } /* key->d = 1/N mod pq */ |
76 | 74 |
94 return err; | 92 return err; |
95 } | 93 } |
96 | 94 |
97 #endif | 95 #endif |
98 | 96 |
99 /* $Source$ */ | 97 /* ref: $Format:%D$ */ |
100 /* $Revision$ */ | 98 /* git commit: $Format:%H$ */ |
101 /* $Date$ */ | 99 /* commit time: $Format:%ai$ */ |