libsec: add diffie-hellman functions

This commit is contained in:
cinap_lenrek 2014-09-14 02:29:18 +02:00
parent 4cf00ca6cb
commit 6c68876db6
3 changed files with 60 additions and 0 deletions

View file

@ -439,3 +439,22 @@ void base58enc(uchar *, char *, int);
int base58dec(char *, uchar *, int);
DigestState* ripemd160(uchar *, ulong, uchar *, DigestState *);
/*
* Diffie-Hellman key exchange
*/
typedef struct DHstate DHstate;
struct DHstate
{
mpint *g; /* base g */
mpint *p; /* large prime */
mpint *x; /* random secret */
mpint *y; /* public key y = g ^ x % p */
};
/* generate new public key: y = g ^ x % p */
mpint* dh_new(DHstate *dh, mpint *p, mpint *g);
/* calculate shared key: k = pub ^ x % p */
mpint* dh_finish(DHstate *dh, mpint *pub);