Skip to content

Commit 334876d

Browse files
committed
rename x25519_set_key to x25519_import_raw
1 parent 44a1834 commit 334876d

File tree

4 files changed

+57
-74
lines changed

4 files changed

+57
-74
lines changed

src/headers/tomcrypt_pk.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,12 @@ int ed25519_verify(const unsigned char *msg, unsigned long msglen,
371371
/** X25519 Key-Exchange API */
372372
int x25519_make_key(prng_state *prng, int wprng, curve25519_key *key);
373373

374-
int x25519_set_key(const unsigned char *k, unsigned long klen,
375-
const unsigned char *u, unsigned long ulen,
376-
curve25519_key *key);
377-
378374
int x25519_export( unsigned char *out, unsigned long *outlen,
379375
int which,
380376
const curve25519_key *key);
381377

382378
int x25519_import(const unsigned char *in, unsigned long inlen, curve25519_key *key);
379+
int x25519_import_raw(const unsigned char *in, unsigned long inlen, int which, curve25519_key *key);
383380
int x25519_import_x509(const unsigned char *in, unsigned long inlen, curve25519_key *key);
384381
int x25519_import_pkcs8(const unsigned char *in, unsigned long inlen,
385382
const void *pwd, unsigned long pwdlen,

src/pk/x25519/x25519_import_raw.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
2+
*
3+
* LibTomCrypt is a library that provides various cryptographic
4+
* algorithms in a highly modular and flexible manner.
5+
*
6+
* The library is free for all purposes without any express
7+
* guarantee it works.
8+
*/
9+
#include "tomcrypt_private.h"
10+
11+
/**
12+
@file x25519_import_raw.c
13+
Set the parameters of a X25519 key, Steffen Jaeckel
14+
*/
15+
16+
#ifdef LTC_CURVE25519
17+
18+
/**
19+
Set the parameters of a X25519 key
20+
21+
@param in The key
22+
@param inlen The length of the key
23+
@param which Which type of key (PK_PRIVATE or PK_PUBLIC)
24+
@param key [out] Destination of the key
25+
@return CRYPT_OK if successful
26+
*/
27+
int x25519_import_raw(const unsigned char *in, unsigned long inlen, int which, curve25519_key *key)
28+
{
29+
LTC_ARGCHK(in != NULL);
30+
LTC_ARGCHK(inlen == 32uL);
31+
LTC_ARGCHK(key != NULL);
32+
33+
if (which == PK_PRIVATE) {
34+
XMEMCPY(key->priv, in, sizeof(key->priv));
35+
tweetnacl_crypto_scalarmult_base(key->pub, key->priv);
36+
} else if (which == PK_PUBLIC) {
37+
XMEMCPY(key->pub, in, sizeof(key->pub));
38+
} else {
39+
return CRYPT_INVALID_ARG;
40+
}
41+
key->algo = PKA_X25519;
42+
key->type = which;
43+
44+
return CRYPT_OK;
45+
}
46+
47+
#endif
48+
49+
/* ref: $Format:%D$ */
50+
/* git commit: $Format:%H$ */
51+
/* commit time: $Format:%ai$ */

src/pk/x25519/x25519_set_key.c

Lines changed: 0 additions & 65 deletions
This file was deleted.

tests/x25519_test.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ static int _rfc_7748_6_test(void)
101101
unsigned char buf[32];
102102
unsigned long buflen = sizeof(buf);
103103

104-
DO(x25519_set_key(alice_private, sizeof(alice_private), alice_public, sizeof(alice_public), &alice_priv));
105-
DO(x25519_set_key(bob_private, sizeof(bob_private), bob_public, sizeof(bob_public), &bob_priv));
106-
DO(x25519_set_key(NULL, 0, alice_public, sizeof(alice_public), &alice_pub));
107-
DO(x25519_set_key(NULL, 0, bob_public, sizeof(bob_public), &bob_pub));
104+
DO(x25519_import_raw(alice_private, sizeof(alice_private), PK_PRIVATE, &alice_priv));
105+
DO(x25519_import_raw(bob_private, sizeof(bob_private), PK_PRIVATE, &bob_priv));
106+
DO(x25519_import_raw(alice_public, sizeof(alice_public), PK_PUBLIC, &alice_pub));
107+
DO(x25519_import_raw(bob_public, sizeof(bob_public), PK_PUBLIC, &bob_pub));
108108

109109
DO(x25519_shared_secret(&alice_priv, &bob_pub, buf, &buflen));
110110
DO(compare_testvector(buf, buflen, shared_secret, sizeof(shared_secret), "x25519 - RFC 7748 Ch. 6", 0));
@@ -199,7 +199,7 @@ static int _x25519_compat_test(void)
199199

200200
buflen = sizeof(buf);
201201
DO(x25519_export(buf, &buflen, PK_PUBLIC, &priv));
202-
DO(x25519_set_key(NULL, 0, buf, buflen, &pub));
202+
DO(x25519_import_raw(buf, buflen, PK_PUBLIC, &pub));
203203

204204
buflen = sizeof(buf);
205205
DO(x25519_export(buf, &buflen, PK_PUBLIC | PK_STD, &priv));

0 commit comments

Comments
 (0)