Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_unix/sys/src/libsec/port/curve25519_dh.c – Rev 26

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
26 7u83 1
#include "os.h"
2
#include <mp.h>
3
#include <libsec.h>
4
 
5
static uchar nine[32] = {9};
6
 
7
void
8
curve25519_dh_new(uchar x[32], uchar y[32])
9
{
10
	uchar b;
11
 
12
	/* new public/private key pair */
13
	genrandom(x, 32);
14
	b = x[31];
15
	x[0] &= ~7;			/* clear bit 0,1,2 */
16
	x[31] = 0x40 | (b & 0x7f);	/* set bit 254, clear bit 255 */
17
	curve25519(y, x, nine);
18
 
19
	/* bit 255 is always 0, so make it random */
20
	y[31] |= b & 0x80;
21
}
22
 
23
void
24
curve25519_dh_finish(uchar x[32], uchar y[32], uchar z[32])
25
{
26
	/* remove the random bit */
27
	y[31] &= 0x7f;
28
 
29
	/* calculate dhx key */
30
	curve25519(z, x, y);
31
 
32
	memset(x, 0, 32);
33
	memset(y, 0, 32);
34
}