Mercurial > dropbear
comparison gendss.c @ 299:740e782679be ucc-axis-hack
Various changes to compile+kind of run on UCC's axis board.
Note that fprintf(stdin -> printf( accounts for many of the changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 25 Mar 2006 12:57:09 +0000 |
parents | c9483550701b |
children |
comparison
equal
deleted
inserted
replaced
266:e37b160c414c | 299:740e782679be |
---|---|
79 | 79 |
80 bytes_to_mp(key->q, buf, QSIZE); | 80 bytes_to_mp(key->q, buf, QSIZE); |
81 | 81 |
82 /* 18 rounds are required according to HAC */ | 82 /* 18 rounds are required according to HAC */ |
83 if (mp_prime_next_prime(key->q, 18, 0) != MP_OKAY) { | 83 if (mp_prime_next_prime(key->q, 18, 0) != MP_OKAY) { |
84 fprintf(stderr, "dss key generation failed\n"); | 84 printf( "dss key generation failed\n"); |
85 exit(1); | 85 exit(1); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 static void getp(dss_key *key, unsigned int size) { | 89 static void getp(dss_key *key, unsigned int size) { |
98 m_mp_init_multi(&tempX, &tempC, &tempP, &temp2q, NULL); | 98 m_mp_init_multi(&tempX, &tempC, &tempP, &temp2q, NULL); |
99 | 99 |
100 | 100 |
101 /* 2*q */ | 101 /* 2*q */ |
102 if (mp_mul_d(key->q, 2, &temp2q) != MP_OKAY) { | 102 if (mp_mul_d(key->q, 2, &temp2q) != MP_OKAY) { |
103 fprintf(stderr, "dss key generation failed\n"); | 103 printf( "dss key generation failed\n"); |
104 exit(1); | 104 exit(1); |
105 } | 105 } |
106 | 106 |
107 buf = (unsigned char*)m_malloc(size); | 107 buf = (unsigned char*)m_malloc(size); |
108 | 108 |
115 /* X is a random mp_int */ | 115 /* X is a random mp_int */ |
116 bytes_to_mp(&tempX, buf, size); | 116 bytes_to_mp(&tempX, buf, size); |
117 | 117 |
118 /* C = X mod 2q */ | 118 /* C = X mod 2q */ |
119 if (mp_mod(&tempX, &temp2q, &tempC) != MP_OKAY) { | 119 if (mp_mod(&tempX, &temp2q, &tempC) != MP_OKAY) { |
120 fprintf(stderr, "dss key generation failed\n"); | 120 printf( "dss key generation failed\n"); |
121 exit(1); | 121 exit(1); |
122 } | 122 } |
123 | 123 |
124 /* P = X - (C - 1) = X - C + 1*/ | 124 /* P = X - (C - 1) = X - C + 1*/ |
125 if (mp_sub(&tempX, &tempC, &tempP) != MP_OKAY) { | 125 if (mp_sub(&tempX, &tempC, &tempP) != MP_OKAY) { |
126 fprintf(stderr, "dss key generation failed\n"); | 126 printf( "dss key generation failed\n"); |
127 exit(1); | 127 exit(1); |
128 } | 128 } |
129 | 129 |
130 if (mp_add_d(&tempP, 1, key->p) != MP_OKAY) { | 130 if (mp_add_d(&tempP, 1, key->p) != MP_OKAY) { |
131 fprintf(stderr, "dss key generation failed\n"); | 131 printf( "dss key generation failed\n"); |
132 exit(1); | 132 exit(1); |
133 } | 133 } |
134 | 134 |
135 /* now check for prime, 5 rounds is enough according to HAC */ | 135 /* now check for prime, 5 rounds is enough according to HAC */ |
136 /* result == 1 => p is prime */ | 136 /* result == 1 => p is prime */ |
137 if (mp_prime_is_prime(key->p, 5, &result) != MP_OKAY) { | 137 if (mp_prime_is_prime(key->p, 5, &result) != MP_OKAY) { |
138 fprintf(stderr, "dss key generation failed\n"); | 138 printf( "dss key generation failed\n"); |
139 exit(1); | 139 exit(1); |
140 } | 140 } |
141 } while (!result); | 141 } while (!result); |
142 | 142 |
143 mp_clear_multi(&tempX, &tempC, &tempP, &temp2q, NULL); | 143 mp_clear_multi(&tempX, &tempC, &tempP, &temp2q, NULL); |
153 | 153 |
154 m_mp_init_multi(&div, &h, &val, NULL); | 154 m_mp_init_multi(&div, &h, &val, NULL); |
155 | 155 |
156 /* get div=(p-1)/q */ | 156 /* get div=(p-1)/q */ |
157 if (mp_sub_d(key->p, 1, &val) != MP_OKAY) { | 157 if (mp_sub_d(key->p, 1, &val) != MP_OKAY) { |
158 fprintf(stderr, "dss key generation failed\n"); | 158 printf( "dss key generation failed\n"); |
159 exit(1); | 159 exit(1); |
160 } | 160 } |
161 if (mp_div(&val, key->q, &div, NULL) != MP_OKAY) { | 161 if (mp_div(&val, key->q, &div, NULL) != MP_OKAY) { |
162 fprintf(stderr, "dss key generation failed\n"); | 162 printf( "dss key generation failed\n"); |
163 exit(1); | 163 exit(1); |
164 } | 164 } |
165 | 165 |
166 /* initialise h=1 */ | 166 /* initialise h=1 */ |
167 mp_set(&h, 1); | 167 mp_set(&h, 1); |
168 do { | 168 do { |
169 /* now keep going with g=h^div mod p, until g > 1 */ | 169 /* now keep going with g=h^div mod p, until g > 1 */ |
170 if (mp_exptmod(&h, &div, key->p, key->g) != MP_OKAY) { | 170 if (mp_exptmod(&h, &div, key->p, key->g) != MP_OKAY) { |
171 fprintf(stderr, "dss key generation failed\n"); | 171 printf( "dss key generation failed\n"); |
172 exit(1); | 172 exit(1); |
173 } | 173 } |
174 | 174 |
175 if (mp_add_d(&h, 1, &h) != MP_OKAY) { | 175 if (mp_add_d(&h, 1, &h) != MP_OKAY) { |
176 fprintf(stderr, "dss key generation failed\n"); | 176 printf( "dss key generation failed\n"); |
177 exit(1); | 177 exit(1); |
178 } | 178 } |
179 | 179 |
180 } while (mp_cmp_d(key->g, 1) != MP_GT); | 180 } while (mp_cmp_d(key->g, 1) != MP_GT); |
181 | 181 |
188 } | 188 } |
189 | 189 |
190 static void gety(dss_key *key) { | 190 static void gety(dss_key *key) { |
191 | 191 |
192 if (mp_exptmod(key->g, key->x, key->p, key->y) != MP_OKAY) { | 192 if (mp_exptmod(key->g, key->x, key->p, key->y) != MP_OKAY) { |
193 fprintf(stderr, "dss key generation failed\n"); | 193 printf( "dss key generation failed\n"); |
194 exit(1); | 194 exit(1); |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 #endif /* DROPBEAR_DSS */ | 198 #endif /* DROPBEAR_DSS */ |