Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- a tiny-ecdh implementation for the ez80 CPU
- ## CURVE SPEC ##
- using curve secp224k1
- define curve T = (p, a, b, G, n, h), where
- finite field Fp is defined by:
- p = FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFE56D
- f(x) = 2^224 − 2^32 − 2^12 − 2^11 − 2^9 − 2^7 − 2^4 − 2 − 1
- curve E: y^2 = x^3 + ax + b over Fp is defined by:
- a = 00000000 00000000 00000000 00000000 00000000 00000000 00000000
- b = 00000000 00000000 00000000 00000000 00000000 00000000 00000005
- G(x) = A1455B33 4DF099DF 30FC28A1 69A467E9 E47075A9 0F7E650E B6B7A45C
- G(y) = 7E089FED 7FBA3442 82CAFBD6 F7E319F7 C0B0BD59 E2CA4BDB 556D61A5
- n = 00000000 00000000 00000000 0001DCE8 D2EC6184 CAF0A971 769FB1F7
- h = 01
- ## KEYGEN ## generate key pair (d, Q)
- d is secret. Assert d in range [1, n-1] (random).
- Q = d*G
- output (d, Q)
- ## PUBKEY VALID ##
- assert Q != infinity point
- assert xQ, yQ are of degree <= m-1
- assert nQ = infinity point
- if h = 1, skip final assertion
- ## SECRET COMPUTE ##
- inputs:
- private key d(alice) associated with T(alice)
- public key Q(bob) associated with T(bob)
- P = (x, y) = h * d(alice) * Q(bob)
- if P = infinite point, invalid
- output x as shared secret field
- (optional, but recommended) pass x to a KDF to generate symmetric key
- */
- #define ECC_PRV_KEY_SIZE 28
- #define ECC_PUB_KEY_SIZE (ECC_PRV_KEY_SIZE<<1)
- #define CURVE_DEGREE 224
- #define PTFM_WORD_SIZE sizeof(uint8_t)
- #define ECC_GF_LEN (ECC_PRV_KEY_SIZE / PTFM_WORD_SIZE)
- // main type definitions for variables
- typedef uint32_t vec_t[ECC_GF_LEN]; // should be 24 bytes
- struct Point {
- vec_t x;
- vec_t y;
- };
- struct Curve {
- vec_t polynomial;
- vec_t coeff_a;
- vec_t coeff_b;
- Point base;
- vec_t b_order;
- uint8_t cofactor;
- };
- Curve secp224k1 = {
- {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFE56D}, // p
- {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, // a
- {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000005}, // b
- {
- {0xA1455B33, 0x4DF099DF, 0x30FC28A1, 0x69A467E9, 0xE47075A9, 0x0F7E650E, 0xB6B7A45C},
- {0x7E089FED, 0x7FBA3442, 0x82CAFBD6, 0xF7E319F7, 0xC0B0BD59, 0xE2CA4BDB, 0x556D61A5}
- }, // G (x, y)
- {0x00000000, 0x00000000, 0x00000000, 0x0001DCE8, 0xD2EC6184, 0xCAF0A971, 0x769FB1F7}, // n
- 1
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement