Mercurial > dropbear
comparison curve25519.c @ 1707:41a0ff8d5a89
void return types for curve25519
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 30 May 2020 00:05:49 +0800 |
parents | d32bcb5c557d |
children |
comparison
equal
deleted
inserted
replaced
1706:3f80da5fe0b4 | 1707:41a0ff8d5a89 |
---|---|
206 FOR(a,16) o[a]=c[a]; | 206 FOR(a,16) o[a]=c[a]; |
207 } | 207 } |
208 #endif /* DROPBEAR_ED25519 && DROPBEAR_SIGNKEY_VERIFY */ | 208 #endif /* DROPBEAR_ED25519 && DROPBEAR_SIGNKEY_VERIFY */ |
209 | 209 |
210 #if DROPBEAR_CURVE25519 | 210 #if DROPBEAR_CURVE25519 |
211 int dropbear_curve25519_scalarmult(u8 *q,const u8 *n,const u8 *p) | 211 void dropbear_curve25519_scalarmult(u8 *q,const u8 *n,const u8 *p) |
212 { | 212 { |
213 u8 z[32]; | 213 u8 z[32]; |
214 i64 x[80],r,i; | 214 i64 x[80],r,i; |
215 gf a,b,c,d,e,f; | 215 gf a,b,c,d,e,f; |
216 FOR(i,31) z[i]=n[i]; | 216 FOR(i,31) z[i]=n[i]; |
254 x[i+64]=d[i]; | 254 x[i+64]=d[i]; |
255 } | 255 } |
256 inv25519(x+32,x+32); | 256 inv25519(x+32,x+32); |
257 M(x+16,x+16,x+32); | 257 M(x+16,x+16,x+32); |
258 pack25519(q,x+16); | 258 pack25519(q,x+16); |
259 return 0; | |
260 } | 259 } |
261 #endif /* DROPBEAR_CURVE25519 */ | 260 #endif /* DROPBEAR_CURVE25519 */ |
262 | 261 |
263 #if DROPBEAR_ED25519 | 262 #if DROPBEAR_ED25519 |
264 static int crypto_hash(u8 *out,const u8 *m,u64 n) | 263 static int crypto_hash(u8 *out,const u8 *m,u64 n) |
336 set25519(q[2],gf1); | 335 set25519(q[2],gf1); |
337 M(q[3],X,Y); | 336 M(q[3],X,Y); |
338 scalarmult(p,q,s); | 337 scalarmult(p,q,s); |
339 } | 338 } |
340 | 339 |
341 int dropbear_ed25519_make_key(u8 *pk,u8 *sk) | 340 void dropbear_ed25519_make_key(u8 *pk,u8 *sk) |
342 { | 341 { |
343 u8 d[64]; | 342 u8 d[64]; |
344 gf p[4]; | 343 gf p[4]; |
345 | 344 |
346 genrandom(sk, 32); | 345 genrandom(sk, 32); |
350 d[31] &= 127; | 349 d[31] &= 127; |
351 d[31] |= 64; | 350 d[31] |= 64; |
352 | 351 |
353 scalarbase(p,d); | 352 scalarbase(p,d); |
354 pack(pk,p); | 353 pack(pk,p); |
355 | |
356 return 0; | |
357 } | 354 } |
358 | 355 |
359 static const u64 L[32] = {0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10}; | 356 static const u64 L[32] = {0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10}; |
360 | 357 |
361 sv modL(u8 *r,i64 x[64]) | 358 sv modL(u8 *r,i64 x[64]) |
390 FOR(i,64) x[i] = (u64) r[i]; | 387 FOR(i,64) x[i] = (u64) r[i]; |
391 FOR(i,64) r[i] = 0; | 388 FOR(i,64) r[i] = 0; |
392 modL(r,x); | 389 modL(r,x); |
393 } | 390 } |
394 | 391 |
395 int dropbear_ed25519_sign(const u8 *m,u32 mlen,u8 *s,u32 *slen,const u8 *sk, const u8 *pk) | 392 void dropbear_ed25519_sign(const u8 *m,u32 mlen,u8 *s,u32 *slen,const u8 *sk, const u8 *pk) |
396 { | 393 { |
397 hash_state hs; | 394 hash_state hs; |
398 u8 d[64],h[64],r[64]; | 395 u8 d[64],h[64],r[64]; |
399 i64 x[64]; | 396 i64 x[64]; |
400 gf p[4]; | 397 gf p[4]; |
424 | 421 |
425 FOR(i,64) x[i] = 0; | 422 FOR(i,64) x[i] = 0; |
426 FOR(i,32) x[i] = (u64) r[i]; | 423 FOR(i,32) x[i] = (u64) r[i]; |
427 FOR(i,32) FOR(j,32) x[i+j] += h[i] * (u64) d[j]; | 424 FOR(i,32) FOR(j,32) x[i+j] += h[i] * (u64) d[j]; |
428 modL(s + 32,x); | 425 modL(s + 32,x); |
429 | |
430 return 0; | |
431 } | 426 } |
432 | 427 |
433 #if DROPBEAR_SIGNKEY_VERIFY | 428 #if DROPBEAR_SIGNKEY_VERIFY |
434 static int unpackneg(gf r[4],const u8 p[32]) | 429 static int unpackneg(gf r[4],const u8 p[32]) |
435 { | 430 { |