Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* NOTE: private should contain random data a-priori! */
- int ecdh_generate_keys(uint8_t* public_key, uint8_t* private_key)
- {
- /* Get copy of "base" point 'G' */
- gf2point_copy((uint32_t*)public_key, (uint32_t*)(public_key + BITVEC_NBYTES), base_x, base_y);
- /* Abort key generation if random number is too small */
- if (bitvec_degree((uint32_t*)private_key) < (CURVE_DEGREE / 2))
- {
- return 0;
- }
- else
- {
- /* Clear bits > CURVE_DEGREE in highest word to satisfy constraint 1 <= exp < n. */
- int nbits = bitvec_degree(base_order);
- int i;
- for (i = (nbits - 1); i < (BITVEC_NWORDS * 32); ++i)
- {
- bitvec_clr_bit((uint32_t*)private_key, i);
- }
- /* Multiply base-point with scalar (private-key) */
- gf2point_mul((uint32_t*)public_key, (uint32_t*)(public_key + BITVEC_NBYTES), (uint32_t*)private_key);
- return 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement