Subversion Repositories planix.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 33
Line 19... Line 19...
19
 
19
 
20
typedef struct AESstate AESstate;
20
typedef struct AESstate AESstate;
21
struct AESstate
21
struct AESstate
22
{
22
{
23
	ulong	setup;
23
	ulong	setup;
-
 
24
	ulong	offset;
24
	int	rounds;
25
	int	rounds;
25
	int	keybytes;
26
	int	keybytes;
-
 
27
	void	*ekey;				/* expanded encryption round key */
26
	uint	ctrsz;
28
	void	*dkey;				/* expanded decryption round key */
27
	uchar	key[AESmaxkey];			/* unexpanded key */
29
	uchar	key[AESmaxkey];			/* unexpanded key */
28
	ulong	ekey[4*(AESmaxrounds + 1)];	/* encryption key */
-
 
29
	ulong	dkey[4*(AESmaxrounds + 1)];	/* decryption key */
-
 
30
	uchar	ivec[AESbsize];			/* initialization vector */
30
	uchar	ivec[AESbsize];			/* initialization vector */
31
	uchar	mackey[3 * AESbsize];		/* 3 XCBC mac 96 keys */
31
	uchar	storage[512];			/* storage for expanded keys */
32
};
32
};
33
 
33
 
34
/* block ciphers */
34
/* block ciphers */
35
void	aes_encrypt(ulong rk[], int Nr, uchar pt[16], uchar ct[16]);
35
extern void (*aes_encrypt)(ulong rk[], int Nr, uchar pt[16], uchar ct[16]);
36
void	aes_decrypt(ulong rk[], int Nr, uchar ct[16], uchar pt[16]);
36
extern void (*aes_decrypt)(ulong rk[], int Nr, uchar ct[16], uchar pt[16]);
-
 
37
 
-
 
38
void	setupAESstate(AESstate *s, uchar key[], int nkey, uchar *ivec);
37
 
39
 
38
void	setupAESstate(AESstate *s, uchar key[], int keybytes, uchar *ivec);
-
 
39
void	aesCBCencrypt(uchar *p, int len, AESstate *s);
40
void	aesCBCencrypt(uchar *p, int len, AESstate *s);
40
void	aesCBCdecrypt(uchar *p, int len, AESstate *s);
41
void	aesCBCdecrypt(uchar *p, int len, AESstate *s);
-
 
42
void	aesCFBencrypt(uchar *p, int len, AESstate *s);
41
void	aesCTRdecrypt(uchar *p, int len, AESstate *s);
43
void	aesCFBdecrypt(uchar *p, int len, AESstate *s);
42
void	aesCTRencrypt(uchar *p, int len, AESstate *s);
44
void	aesOFBencrypt(uchar *p, int len, AESstate *s);
43
 
45
 
44
void	setupAESXCBCstate(AESstate *s);
46
typedef struct AESGCMstate AESGCMstate;
-
 
47
struct AESGCMstate
-
 
48
{
-
 
49
	AESstate;
-
 
50
 
-
 
51
	ulong	H[4];
-
 
52
	ulong	M[16][256][4];
-
 
53
};
-
 
54
 
-
 
55
void	setupAESGCMstate(AESGCMstate *s, uchar *key, int keylen, uchar *iv, int ivlen);
45
uchar*	aesXCBCmac(uchar *p, int len, AESstate *s);
56
void	aesgcm_setiv(AESGCMstate *s, uchar *iv, int ivlen);
-
 
57
void	aesgcm_encrypt(uchar *dat, ulong ndat, uchar *aad, ulong naad, uchar tag[16], AESGCMstate *s);
-
 
58
int	aesgcm_decrypt(uchar *dat, ulong ndat, uchar *aad, ulong naad, uchar tag[16], AESGCMstate *s);
46
 
59
 
47
/*
60
/*
48
 * Blowfish Definitions
61
 * Blowfish Definitions
49
 */
62
 */
50
 
63
 
51
enum
64
enum
52
{
65
{
53
	BFbsize	= 8,
66
	BFbsize	= 8,
54
	BFrounds= 16
67
	BFrounds= 16
55
};
68
};
Line 57... Line 70...
57
/* 16-round Blowfish */
70
/* 16-round Blowfish */
58
typedef struct BFstate BFstate;
71
typedef struct BFstate BFstate;
59
struct BFstate
72
struct BFstate
60
{
73
{
61
	ulong	setup;
74
	ulong	setup;
62
 
75
 
63
	uchar	key[56];
76
	uchar	key[56];
64
	uchar	ivec[8];
77
	uchar	ivec[8];
65
 
78
 
66
	u32int 	pbox[BFrounds+2];
79
	u32int 	pbox[BFrounds+2];
67
	u32int	sbox[1024];
80
	u32int	sbox[1024];
Line 70... Line 83...
70
void	setupBFstate(BFstate *s, uchar key[], int keybytes, uchar *ivec);
83
void	setupBFstate(BFstate *s, uchar key[], int keybytes, uchar *ivec);
71
void	bfCBCencrypt(uchar*, int, BFstate*);
84
void	bfCBCencrypt(uchar*, int, BFstate*);
72
void	bfCBCdecrypt(uchar*, int, BFstate*);
85
void	bfCBCdecrypt(uchar*, int, BFstate*);
73
void	bfECBencrypt(uchar*, int, BFstate*);
86
void	bfECBencrypt(uchar*, int, BFstate*);
74
void	bfECBdecrypt(uchar*, int, BFstate*);
87
void	bfECBdecrypt(uchar*, int, BFstate*);
-
 
88
 
-
 
89
/*
-
 
90
 * Chacha definitions
-
 
91
 */
-
 
92
 
-
 
93
enum
-
 
94
{
-
 
95
	ChachaBsize=	64,
-
 
96
	ChachaKeylen=	256/8,
-
 
97
	ChachaIVlen=	96/8,
-
 
98
	XChachaIVlen=	192/8,
-
 
99
};
-
 
100
 
-
 
101
typedef struct Chachastate Chachastate;
-
 
102
struct Chachastate
-
 
103
{
-
 
104
	union{
-
 
105
		u32int	input[16];
-
 
106
		struct {
-
 
107
			u32int	constant[4];
-
 
108
			u32int	key[8];
-
 
109
			u32int	counter;
-
 
110
			u32int	iv[3];
-
 
111
		};
-
 
112
	};
-
 
113
	u32int	xkey[8];
-
 
114
	int	rounds;
-
 
115
	int	ivwords;
-
 
116
};
-
 
117
 
-
 
118
void	setupChachastate(Chachastate*, uchar*, ulong, uchar*, ulong, int);
-
 
119
void	chacha_setiv(Chachastate *, uchar*);
-
 
120
void	chacha_setblock(Chachastate*, u64int);
-
 
121
void	chacha_encrypt(uchar*, ulong, Chachastate*);
-
 
122
void	chacha_encrypt2(uchar*, uchar*, ulong, Chachastate*);
-
 
123
 
-
 
124
void	hchacha(uchar h[32], uchar *key, ulong keylen, uchar nonce[16], int rounds);
-
 
125
 
-
 
126
void	ccpoly_encrypt(uchar *dat, ulong ndat, uchar *aad, ulong naad, uchar tag[16], Chachastate *cs);
-
 
127
int	ccpoly_decrypt(uchar *dat, ulong ndat, uchar *aad, ulong naad, uchar tag[16], Chachastate *cs);
-
 
128
 
-
 
129
/*
-
 
130
 * Salsa definitions
-
 
131
 */
-
 
132
enum
-
 
133
{
-
 
134
	SalsaBsize=	64,
-
 
135
	SalsaKeylen=	256/8,
-
 
136
	SalsaIVlen=	64/8,
-
 
137
	XSalsaIVlen=	192/8,
-
 
138
};
-
 
139
 
-
 
140
typedef struct Salsastate Salsastate;
-
 
141
struct Salsastate
-
 
142
{
-
 
143
	u32int	input[16];
-
 
144
	u32int	xkey[8];
-
 
145
	int	rounds;
-
 
146
	int	ivwords;
-
 
147
};
-
 
148
 
-
 
149
void	setupSalsastate(Salsastate*, uchar*, ulong, uchar*, ulong, int);
-
 
150
void	salsa_setiv(Salsastate*, uchar*);
-
 
151
void	salsa_setblock(Salsastate*, u64int);
-
 
152
void	salsa_encrypt(uchar*, ulong, Salsastate*);
-
 
153
void	salsa_encrypt2(uchar*, uchar*, ulong, Salsastate*);
-
 
154
 
-
 
155
void	salsa_core(u32int in[16], u32int out[16], int rounds);
-
 
156
 
-
 
157
void	hsalsa(uchar h[32], uchar *key, ulong keylen, uchar nonce[16], int rounds);
75
 
158
 
76
/*
159
/*
77
 * DES definitions
160
 * DES definitions
78
 */
161
 */
79
 
162
 
Line 142... Line 225...
142
	SHA2_256dlen=	32,	/* SHA-256 digest length */
225
	SHA2_256dlen=	32,	/* SHA-256 digest length */
143
	SHA2_384dlen=	48,	/* SHA-384 digest length */
226
	SHA2_384dlen=	48,	/* SHA-384 digest length */
144
	SHA2_512dlen=	64,	/* SHA-512 digest length */
227
	SHA2_512dlen=	64,	/* SHA-512 digest length */
145
	MD4dlen=	16,	/* MD4 digest length */
228
	MD4dlen=	16,	/* MD4 digest length */
146
	MD5dlen=	16,	/* MD5 digest length */
229
	MD5dlen=	16,	/* MD5 digest length */
-
 
230
	Poly1305dlen=	16,	/* Poly1305 digest length */
147
	AESdlen=	16,	/* TODO: see rfc */
231
	AESdlen=	16,	/* TODO: see rfc */
148
 
232
 
149
	Hmacblksz	= 64,	/* in bytes; from rfc2104 */
233
	Hmacblksz	= 64,	/* in bytes; from rfc2104 */
150
};
234
};
151
 
235
 
152
typedef struct DigestState DigestState;
236
typedef struct DigestState DigestState;
153
struct DigestState
237
struct DigestState
154
{
238
{
155
	uvlong	len;
239
	uvlong	len;
156
	union {
240
	union {
157
		u32int	state[8];
241
		u32int	state[16];
158
		u64int	bstate[8];
242
		u64int	bstate[8];
159
	};
243
	};
160
	uchar	buf[256];
244
	uchar	buf[256];
161
	int	blen;
245
	int	blen;
162
	char	malloced;
246
	char	malloced;
Line 169... Line 253...
169
typedef struct DigestState SHA2_384state;
253
typedef struct DigestState SHA2_384state;
170
typedef struct DigestState SHA2_512state;
254
typedef struct DigestState SHA2_512state;
171
typedef struct DigestState MD5state;
255
typedef struct DigestState MD5state;
172
typedef struct DigestState MD4state;
256
typedef struct DigestState MD4state;
173
typedef struct DigestState AEShstate;
257
typedef struct DigestState AEShstate;
-
 
258
 
174
 
259
 
175
DigestState*	md4(uchar*, ulong, uchar*, DigestState*);
260
DigestState*	md4(uchar*, ulong, uchar*, DigestState*);
176
DigestState*	md5(uchar*, ulong, uchar*, DigestState*);
261
DigestState*	md5(uchar*, ulong, uchar*, DigestState*);
177
DigestState*	sha1(uchar*, ulong, uchar*, DigestState*);
262
DigestState*	sha1(uchar*, ulong, uchar*, DigestState*);
178
DigestState*	sha2_224(uchar*, ulong, uchar*, DigestState*);
263
DigestState*	sha2_224(uchar*, ulong, uchar*, DigestState*);
179
DigestState*	sha2_256(uchar*, ulong, uchar*, DigestState*);
264
DigestState*	sha2_256(uchar*, ulong, uchar*, DigestState*);
180
DigestState*	sha2_384(uchar*, ulong, uchar*, DigestState*);
265
DigestState*	sha2_384(uchar*, ulong, uchar*, DigestState*);
181
DigestState*	sha2_512(uchar*, ulong, uchar*, DigestState*);
266
DigestState*	sha2_512(uchar*, ulong, uchar*, DigestState*);
182
DigestState*	aes(uchar*, ulong, uchar*, DigestState*);
-
 
183
DigestState*	hmac_x(uchar *p, ulong len, uchar *key, ulong klen,
267
DigestState*	hmac_x(uchar *p, ulong len, uchar *key, ulong klen,
184
			uchar *digest, DigestState *s,
268
			uchar *digest, DigestState *s,
185
			DigestState*(*x)(uchar*, ulong, uchar*, DigestState*),
269
			DigestState*(*x)(uchar*, ulong, uchar*, DigestState*),
186
			int xlen);
270
			int xlen);
187
DigestState*	hmac_md5(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
271
DigestState*	hmac_md5(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
Line 189... Line 273...
189
DigestState*	hmac_sha2_224(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
273
DigestState*	hmac_sha2_224(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
190
DigestState*	hmac_sha2_256(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
274
DigestState*	hmac_sha2_256(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
191
DigestState*	hmac_sha2_384(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
275
DigestState*	hmac_sha2_384(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
192
DigestState*	hmac_sha2_512(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
276
DigestState*	hmac_sha2_512(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
193
DigestState*	hmac_aes(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
277
DigestState*	hmac_aes(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
-
 
278
 
194
char*		md5pickle(MD5state*);
279
char*		md5pickle(MD5state*);
195
MD5state*	md5unpickle(char*);
280
MD5state*	md5unpickle(char*);
196
char*		sha1pickle(SHA1state*);
281
char*		sha1pickle(SHA1state*);
197
SHA1state*	sha1unpickle(char*);
282
SHA1state*	sha1unpickle(char*);
-
 
283
 
-
 
284
DigestState*	poly1305(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
198
 
285
 
199
/*
286
/*
200
 * random number generation
287
 * random number generation
201
 */
288
 */
202
void	genrandom(uchar *buf, int nbytes);
289
void	genrandom(uchar *buf, int nbytes);
Line 273... Line 360...
273
void		rsapubfree(RSApub*);
360
void		rsapubfree(RSApub*);
274
RSApriv*	rsaprivalloc(void);
361
RSApriv*	rsaprivalloc(void);
275
void		rsaprivfree(RSApriv*);
362
void		rsaprivfree(RSApriv*);
276
RSApub*		rsaprivtopub(RSApriv*);
363
RSApub*		rsaprivtopub(RSApriv*);
277
RSApub*		X509toRSApub(uchar*, int, char*, int);
364
RSApub*		X509toRSApub(uchar*, int, char*, int);
278
uchar*		RSApubtoasn1(RSApub*, int*);
-
 
279
RSApub*		asn1toRSApub(uchar*, int);
365
RSApub*		asn1toRSApub(uchar*, int);
280
RSApriv*	asn1toRSApriv(uchar*, int);
366
RSApriv*	asn1toRSApriv(uchar*, int);
281
void		asn1dump(uchar *der, int len);
367
void		asn1dump(uchar *der, int len);
282
uchar*		decodePEM(char *s, char *type, int *len, char **new_s);
368
uchar*		decodePEM(char *s, char *type, int *len, char **new_s);
283
PEMChain*	decodepemchain(char *s, char *type);
369
PEMChain*	decodepemchain(char *s, char *type);
284
uchar*		X509gen(RSApriv *priv, char *subj, ulong valid[2], int *certlen);
370
uchar*		X509rsagen(RSApriv *priv, char *subj, ulong valid[2], int *certlen);
285
uchar*		X509req(RSApriv *priv, char *subj, int *certlen);
371
uchar*		X509rsareq(RSApriv *priv, char *subj, int *certlen);
286
char*		X509verify(uchar *cert, int ncert, RSApub *pk);
372
char*		X509rsaverify(uchar *cert, int ncert, RSApub *pk);
-
 
373
char*		X509rsaverifydigest(uchar *sig, int siglen, uchar *edigest, int edigestlen, RSApub *pk);
-
 
374
 
-
 
375
 
-
 
376
uchar*          X509gen(RSApriv *priv, char *subj, ulong valid[2], int *certlen);
-
 
377
uchar*          X509req(RSApriv *priv, char *subj, int *certlen);
-
 
378
char*           X509verify(uchar *cert, int ncert, RSApub *pk);
287
void		X509dump(uchar *cert, int ncert);
379
void		X509dump(uchar *cert, int ncert);
-
 
380
 
-
 
381
mpint*		pkcs1padbuf(uchar *buf, int len, mpint *modulus, int blocktype);
-
 
382
int		pkcs1unpadbuf(uchar *buf, int len, mpint *modulus, int blocktype);
-
 
383
int		asn1encodeRSApub(RSApub *pk, uchar *buf, int len);
-
 
384
int		asn1encodedigest(DigestState* (*fun)(uchar*, ulong, uchar*, DigestState*),
-
 
385
			uchar *digest, uchar *buf, int len);
-
 
386
 
-
 
387
int		X509digestSPKI(uchar *, int, DigestState* (*)(uchar*, ulong, uchar*, DigestState*), uchar *);
288
 
388
 
289
/*
389
/*
290
 * elgamal
390
 * elgamal
291
 */
391
 */
292
typedef struct EGpub EGpub;
392
typedef struct EGpub EGpub;
Line 364... Line 464...
364
DSApriv*	dsaprivalloc(void);
464
DSApriv*	dsaprivalloc(void);
365
void		dsaprivfree(DSApriv*);
465
void		dsaprivfree(DSApriv*);
366
DSAsig*		dsasigalloc(void);
466
DSAsig*		dsasigalloc(void);
367
void		dsasigfree(DSAsig*);
467
void		dsasigfree(DSAsig*);
368
DSApub*		dsaprivtopub(DSApriv*);
468
DSApub*		dsaprivtopub(DSApriv*);
369
DSApriv*	asn1toDSApriv(uchar*, int);
469
DSApriv*        asn1toDSApriv(uchar*, int);
370
 
470
 
371
/*
471
/*
372
 * TLS
472
 * TLS
373
 */
473
 */
374
typedef struct Thumbprint{
474
typedef struct Thumbprint{
375
	struct Thumbprint *next;
475
	struct Thumbprint *next;
376
	uchar	sha1[SHA1dlen];
476
	uchar	hash[SHA2_256dlen];
-
 
477
	uchar	len;
377
} Thumbprint;
478
} Thumbprint;
378
 
479
 
379
typedef struct TLSconn{
480
typedef struct TLSconn{
380
	char	dir[40];	/* connection directory */
481
	char	dir[40];	/* connection directory */
381
	uchar	*cert;	/* certificate (local on input, remote on output) */
482
	uchar	*cert;	/* certificate (local on input, remote on output) */
382
	uchar	*sessionID;
483
	uchar	*sessionID;
-
 
484
	uchar	*psk;
383
	int	certlen;
485
	int	certlen;
384
	int	sessionIDlen;
486
	int	sessionIDlen;
-
 
487
	int	psklen;
385
	int	(*trace)(char*fmt, ...);
488
	int	(*trace)(char*fmt, ...);
386
	PEMChain*chain;	/* optional extra certificate evidence for servers to present */
489
	PEMChain*chain;	/* optional extra certificate evidence for servers to present */
387
	char	*sessionType;
490
	char	*sessionType;
388
	uchar	*sessionKey;
491
	uchar	*sessionKey;
389
	int	sessionKeylen;
492
	int	sessionKeylen;
390
	char	*sessionConst;
493
	char	*sessionConst;
-
 
494
	char	*serverName;
-
 
495
	char	*pskID;
391
} TLSconn;
496
} TLSconn;
392
 
497
 
393
/* tlshand.c */
498
/* tlshand.c */
394
int tlsClient(int fd, TLSconn *c);
499
int tlsClient(int fd, TLSconn *c);
395
int tlsServer(int fd, TLSconn *c);
500
int tlsServer(int fd, TLSconn *c);
396
 
501
 
397
/* thumb.c */
502
/* thumb.c */
398
Thumbprint* initThumbprints(char *ok, char *crl);
503
Thumbprint* initThumbprints(char *ok, char *crl, char *tag);
399
void	freeThumbprints(Thumbprint *ok);
504
void	freeThumbprints(Thumbprint *ok);
400
int	okThumbprint(uchar *sha1, Thumbprint *ok);
505
int	okThumbprint(uchar *hash, int len, Thumbprint *ok);
-
 
506
int	okCertificate(uchar *cert, int len, Thumbprint *ok);
401
 
507
 
402
/* readcert.c */
508
/* readcert.c */
403
uchar	*readcert(char *filename, int *pcertlen);
509
uchar	*readcert(char *filename, int *pcertlen);
404
PEMChain*readcertchain(char *filename);
510
PEMChain*readcertchain(char *filename);
-
 
511
 
-
 
512
/* aes_xts.c */
-
 
513
void aes_xts_encrypt(AESstate *tweak, AESstate *ecb, uvlong sectorNumber, uchar *input, uchar *output, ulong len);
-
 
514
void aes_xts_decrypt(AESstate *tweak, AESstate *ecb, uvlong sectorNumber, uchar *input, uchar *output, ulong len);
-
 
515
 
-
 
516
typedef struct ECpoint{
-
 
517
	int inf;
-
 
518
	mpint *x;
-
 
519
	mpint *y;
-
 
520
	mpint *z;	/* nil when using affine coordinates */
-
 
521
} ECpoint;
-
 
522
 
-
 
523
typedef ECpoint ECpub;
-
 
524
typedef struct ECpriv{
-
 
525
	ECpoint;
-
 
526
	mpint *d;
-
 
527
} ECpriv;
-
 
528
 
-
 
529
typedef struct ECdomain{
-
 
530
	mpint *p;
-
 
531
	mpint *a;
-
 
532
	mpint *b;
-
 
533
	ECpoint G;
-
 
534
	mpint *n;
-
 
535
	mpint *h;
-
 
536
} ECdomain;
-
 
537
 
-
 
538
void	ecdominit(ECdomain *, void (*init)(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h));
-
 
539
void	ecdomfree(ECdomain *);
-
 
540
 
-
 
541
void	ecassign(ECdomain *, ECpoint *old, ECpoint *new);
-
 
542
void	ecadd(ECdomain *, ECpoint *a, ECpoint *b, ECpoint *s);
-
 
543
void	ecmul(ECdomain *, ECpoint *a, mpint *k, ECpoint *s);
-
 
544
ECpoint*	strtoec(ECdomain *, char *, char **, ECpoint *);
-
 
545
ECpriv*	ecgen(ECdomain *, ECpriv*);
-
 
546
int	ecverify(ECdomain *, ECpoint *);
-
 
547
int	ecpubverify(ECdomain *, ECpub *);
-
 
548
void	ecdsasign(ECdomain *, ECpriv *, uchar *, int, mpint *, mpint *);
-
 
549
int	ecdsaverify(ECdomain *, ECpub *, uchar *, int, mpint *, mpint *);
-
 
550
void	base58enc(uchar *, char *, int);
-
 
551
int	base58dec(char *, uchar *, int);
-
 
552
 
-
 
553
ECpub*	ecdecodepub(ECdomain *dom, uchar *, int);
-
 
554
int	ecencodepub(ECdomain *dom, ECpub *, uchar *, int);
-
 
555
void	ecpubfree(ECpub *);
-
 
556
 
-
 
557
ECpub*	X509toECpub(uchar *cert, int ncert, char *name, int nname, ECdomain *dom);
-
 
558
char*	X509ecdsaverify(uchar *cert, int ncert, ECdomain *dom, ECpub *pub);
-
 
559
char*	X509ecdsaverifydigest(uchar *sig, int siglen, uchar *edigest, int edigestlen, ECdomain *dom, ECpub *pub);
-
 
560
 
-
 
561
/* curves */
-
 
562
void	secp256r1(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h);
-
 
563
void	secp256k1(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h);
-
 
564
void	secp384r1(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h);
-
 
565
 
-
 
566
DigestState*	ripemd160(uchar *, ulong, uchar *, DigestState *);
-
 
567
 
-
 
568
/*
-
 
569
 * Diffie-Hellman key exchange
-
 
570
 */
-
 
571
 
-
 
572
typedef struct DHstate DHstate;
-
 
573
struct DHstate
-
 
574
{
-
 
575
	mpint	*g;	/* base g */
-
 
576
	mpint	*p;	/* large prime */
-
 
577
	mpint	*q;	/* subgroup prime */
-
 
578
	mpint	*x;	/* random secret */
-
 
579
	mpint	*y;	/* public key y = g**x % p */
-
 
580
};
-
 
581
 
-
 
582
/* generate new public key: y = g**x % p */
-
 
583
mpint* dh_new(DHstate *dh, mpint *p, mpint *q, mpint *g);
-
 
584
 
-
 
585
/* calculate shared key: k = y**x % p */
-
 
586
mpint* dh_finish(DHstate *dh, mpint *y);
-
 
587
 
-
 
588
/* Curve25519 elliptic curve, public key function */
-
 
589
void curve25519(uchar mypublic[32], uchar secret[32], uchar basepoint[32]);
-
 
590
 
-
 
591
/* Curve25519 diffie hellman */
-
 
592
void curve25519_dh_new(uchar x[32], uchar y[32]);
-
 
593
void curve25519_dh_finish(uchar x[32], uchar y[32], uchar z[32]);
-
 
594
 
-
 
595
/* password-based key derivation function 2 (rfc2898) */
-
 
596
void pbkdf2_x(uchar *p, ulong plen, uchar *s, ulong slen, ulong rounds, uchar *d, ulong dlen,
-
 
597
	DigestState* (*x)(uchar*, ulong, uchar*, ulong, uchar*, DigestState*), int xlen);
-
 
598
 
-
 
599
/* scrypt password-based key derivation function */
-
 
600
char* scrypt(uchar *p, ulong plen, uchar *s, ulong slen,
-
 
601
	ulong N, ulong R, ulong P,
-
 
602
	uchar *d, ulong dlen);
-
 
603
 
-
 
604
/* hmac-based key derivation function (rfc5869) */
-
 
605
void hkdf_x(uchar *salt, ulong nsalt, uchar *info, ulong ninfo, uchar *key, ulong nkey, uchar *d, ulong dlen,
-
 
606
	DigestState* (*x)(uchar*, ulong, uchar*, ulong, uchar*, DigestState*), int xlen);
-
 
607
 
-
 
608
/* timing safe memcmp() */
-
 
609
int tsmemcmp(void*, void*, ulong);