Merge pull request #161 from jvarho/crypto-box-seed-keypair

Add crypto_box_seed_keypair
This commit is contained in:
Frank Denis
2014-05-25 19:09:27 -07:00
10 changed files with 94 additions and 1 deletions
+1
View File
@@ -65,6 +65,7 @@ test/default/box7
test/default/box8
test/default/box_easy
test/default/box_easy2
test/default/box_seed
test/default/chacha20
test/default/core1
test/default/core2
+13
View File
@@ -1,6 +1,12 @@
#include "crypto_box.h"
size_t
crypto_box_seedbytes(void)
{
return crypto_box_SEEDBYTES;
}
size_t
crypto_box_publickeybytes(void)
{
@@ -49,6 +55,13 @@ crypto_box_primitive(void)
return crypto_box_PRIMITIVE;
}
int
crypto_box_seed_keypair(unsigned char *pk, unsigned char *sk,
const unsigned char *seed)
{
return crypto_box_curve25519xsalsa20poly1305_seed_keypair(pk, sk, seed);
}
int
crypto_box_keypair(unsigned char *pk, unsigned char *sk)
{
@@ -1,5 +1,10 @@
#include "crypto_box_curve25519xsalsa20poly1305.h"
size_t
crypto_box_curve25519xsalsa20poly1305_seedbytes(void) {
return crypto_box_curve25519xsalsa20poly1305_SEEDBYTES;
}
size_t
crypto_box_curve25519xsalsa20poly1305_publickeybytes(void) {
return crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES;
@@ -3,10 +3,12 @@
#define crypto_box crypto_box_curve25519xsalsa20poly1305
#define crypto_box_open crypto_box_curve25519xsalsa20poly1305_open
#define crypto_box_seed_keypair crypto_box_curve25519xsalsa20poly1305_seed_keypair
#define crypto_box_keypair crypto_box_curve25519xsalsa20poly1305_keypair
#define crypto_box_beforenm crypto_box_curve25519xsalsa20poly1305_beforenm
#define crypto_box_afternm crypto_box_curve25519xsalsa20poly1305_afternm
#define crypto_box_open_afternm crypto_box_curve25519xsalsa20poly1305_open_afternm
#define crypto_box_SEEDBYTES crypto_box_curve25519xsalsa20poly1305_SEEDBYTES
#define crypto_box_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES
#define crypto_box_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES
#define crypto_box_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES
@@ -1,7 +1,19 @@
#include <string.h>
#include "crypto_scalarmult_curve25519.h"
#include "api.h"
#include "randombytes.h"
int crypto_box_seed_keypair(
unsigned char *pk,
unsigned char *sk,
const unsigned char *seed
)
{
memmove(sk, seed, 32);
return crypto_scalarmult_curve25519_base(pk,sk);
}
int crypto_box_keypair(
unsigned char *pk,
unsigned char *sk
@@ -20,6 +20,10 @@
extern "C" {
#endif
#define crypto_box_SEEDBYTES crypto_box_curve25519xsalsa20poly1305_SEEDBYTES
SODIUM_EXPORT
size_t crypto_box_seedbytes(void);
#define crypto_box_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES
SODIUM_EXPORT
size_t crypto_box_publickeybytes(void);
@@ -52,6 +56,10 @@ size_t crypto_box_macbytes(void);
SODIUM_EXPORT
const char *crypto_box_primitive(void);
SODIUM_EXPORT
int crypto_box_seed_keypair(unsigned char *pk, unsigned char *sk,
const unsigned char *seed);
SODIUM_EXPORT
int crypto_box_keypair(unsigned char *pk, unsigned char *sk);
@@ -11,6 +11,10 @@
extern "C" {
#endif
#define crypto_box_curve25519xsalsa20poly1305_SEEDBYTES 32U
SODIUM_EXPORT
size_t crypto_box_curve25519xsalsa20poly1305_seedbytes(void);
#define crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES 32U
SODIUM_EXPORT
size_t crypto_box_curve25519xsalsa20poly1305_publickeybytes(void);
@@ -58,7 +62,13 @@ int crypto_box_curve25519xsalsa20poly1305_open(unsigned char *m,
const unsigned char *sk);
SODIUM_EXPORT
int crypto_box_curve25519xsalsa20poly1305_keypair(unsigned char *pk, unsigned char *sk);
int crypto_box_curve25519xsalsa20poly1305_seed_keypair(unsigned char *pk,
unsigned char *sk,
const unsigned char *seed);
SODIUM_EXPORT
int crypto_box_curve25519xsalsa20poly1305_keypair(unsigned char *pk,
unsigned char *sk);
SODIUM_EXPORT
int crypto_box_curve25519xsalsa20poly1305_beforenm(unsigned char *k,
+6
View File
@@ -14,6 +14,7 @@ EXTRA_DIST = \
box8.exp \
box_easy.exp \
box_easy2.exp \
box_seed.exp \
chacha20.exp \
core1.exp \
core2.exp \
@@ -69,6 +70,7 @@ DISTCLEANFILES = \
box8.res \
box_easy.res \
box_easy2.res \
box_seed.res \
chacha20.res \
core1.res \
core2.res \
@@ -132,6 +134,7 @@ TESTS_TARGETS = \
box8 \
box_easy \
box_easy2 \
box_seed \
chacha20 \
core1 \
core2 \
@@ -217,6 +220,9 @@ box_easy_LDADD = $(TESTS_LDADD)
box_easy2_SOURCE = cmptest.h box_easy2.c
box_easy2_LDADD = $(TESTS_LDADD)
box_seed_SOURCE = cmptest.h box_seed.c
box_seed_LDADD = $(TESTS_LDADD)
chacha20_SOURCE = cmptest.h chacha20.c
chacha20_LDADD = $(TESTS_LDADD)
+28
View File
@@ -0,0 +1,28 @@
#include <stdio.h>
#define TEST_NAME "box_seed"
#include "cmptest.h"
unsigned char seed[32] = {
0x77,0x07,0x6d,0x0a,0x73,0x18,0xa5,0x7d
,0x3c,0x16,0xc1,0x72,0x51,0xb2,0x66,0x45
,0xdf,0x4c,0x2f,0x87,0xeb,0xc0,0x99,0x2a
,0xb1,0x77,0xfb,0xa5,0x1d,0xb9,0x2c,0x2a
};
int main(void)
{
int i;
unsigned char sk[32];
unsigned char pk[32];
crypto_box_curve25519xsalsa20poly1305_seed_keypair(pk, sk, seed);
for (i = 0;i < 32;++i) {
printf(",0x%02x",(unsigned int) pk[i]);
if (i % 8 == 7) printf("\n");
}
for (i = 0;i < 32;++i) {
printf(",0x%02x",(unsigned int) sk[i]);
if (i % 8 == 7) printf("\n");
}
return 0;
}
+8
View File
@@ -0,0 +1,8 @@
,0x85,0x20,0xf0,0x09,0x89,0x30,0xa7,0x54
,0x74,0x8b,0x7d,0xdc,0xb4,0x3e,0xf7,0x5a
,0x0d,0xbf,0x3a,0x0d,0x26,0x38,0x1a,0xf4
,0xeb,0xa4,0xa9,0x8e,0xaa,0x9b,0x4e,0x6a
,0x77,0x07,0x6d,0x0a,0x73,0x18,0xa5,0x7d
,0x3c,0x16,0xc1,0x72,0x51,0xb2,0x66,0x45
,0xdf,0x4c,0x2f,0x87,0xeb,0xc0,0x99,0x2a
,0xb1,0x77,0xfb,0xa5,0x1d,0xb9,0x2c,0x2a