Advertisement
AnthonyCagliano

Untitled

Nov 30th, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. /* NOTE: private should contain random data a-priori! */
  2. int ecdh_generate_keys(uint8_t* public_key, uint8_t* private_key)
  3. {
  4. /* Get copy of "base" point 'G' */
  5. gf2point_copy((uint32_t*)public_key, (uint32_t*)(public_key + BITVEC_NBYTES), base_x, base_y);
  6.  
  7. /* Abort key generation if random number is too small */
  8. if (bitvec_degree((uint32_t*)private_key) < (CURVE_DEGREE / 2))
  9. {
  10. return 0;
  11. }
  12. else
  13. {
  14. /* Clear bits > CURVE_DEGREE in highest word to satisfy constraint 1 <= exp < n. */
  15. int nbits = bitvec_degree(base_order);
  16. int i;
  17.  
  18. for (i = (nbits - 1); i < (BITVEC_NWORDS * 32); ++i)
  19. {
  20. bitvec_clr_bit((uint32_t*)private_key, i);
  21. }
  22.  
  23. /* Multiply base-point with scalar (private-key) */
  24. gf2point_mul((uint32_t*)public_key, (uint32_t*)(public_key + BITVEC_NBYTES), (uint32_t*)private_key);
  25.  
  26. return 1;
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement