Merge pull request #1454 from dgarske/noprivkey

Support for not loading a private key when using `HAVE_PK_CALLBACKS`
This commit is contained in:
toddouska
2018-03-22 12:47:22 -07:00
committed by GitHub
23 changed files with 937 additions and 385 deletions

View File

@@ -51,7 +51,7 @@ WOLFSSL_API int wc_InitCert(Cert*);
\code
Cert myCert;
wc_InitCert(&myCert);
RNG rng;
WC_RNG rng;
//initialize rng;
RsaKey key;
//initialize key;
@@ -149,7 +149,7 @@ WOLFSSL_API int wc_MakeCert(Cert*, byte* derBuffer, word32 derSz, RsaKey*,
// initialize myCert, derCert
RsaKey key;
// initialize key;
RNG rng;
WC_RNG rng;
// initialize rng
word32 certSz;
@@ -195,7 +195,7 @@ WOLFSSL_API int wc_SignCert(int requestSz, int sigType, byte* derBuffer,
// initialize myCert, derCert
RsaKey key;
// initialize key;
RNG rng;
WC_RNG rng;
// initialize rng
word32 certSz;
@@ -899,7 +899,7 @@ WOLFSSL_API int wc_SetKeyUsage(Cert *cert, const char *value);
\code
Cert myCert;
// initialize myCert
RNG rng;
WC_RNG rng;
//initialize rng;
byte ntruPublicKey[NTRU_KEY_SIZE];
//initialize ntruPublicKey;
@@ -1222,7 +1222,7 @@ WOLFSSL_API int wc_SetKeyUsage(Cert *cert, const char *value);
\code
ecc_key key;
wc_ecc_init(&key);
WC_RNG rng;
WC_WC_RNG rng;
wc_InitRng(&rng);
wc_ecc_make_key(&rng, 24, &key);
int derSz = // Some appropriate size for der;

View File

@@ -23,7 +23,7 @@
\code
curve25519_key key;
wc_curve25519_init(&key); // initialize key
RNG rng;
WC_RNG rng;
wc_InitRng(&rng); // initialize random number generator
if( wc_curve25519_make_key(&rng, 32, &key) != 0) {

View File

@@ -80,7 +80,7 @@ WOLFSSL_API void wc_FreeDhKey(DhKey* key);
wc_InitDhKey(&key); // initialize key
// Set DH parameters using wc_DhSetKey or wc_DhKeyDecode
RNG rng;
WC_RNG rng;
wc_InitRng(&rng); // initialize rng
ret = wc_DhGenerateKeyPair(&key, &rng, priv, &privSz, pub, &pubSz);
\endcode

View File

@@ -81,7 +81,7 @@ WOLFSSL_API void wc_FreeDsaKey(DsaKey* key);
DsaKey key;
// initialize DSA key, load private Key
int ret;
RNG rng;
WC_RNG rng;
wc_InitRng(&rng);
byte hash[] = { // initialize with hash digest };
byte signature[40]; // signature will be 40 bytes (320 bits)
@@ -255,7 +255,7 @@ WOLFSSL_API int wc_DsaPrivateKeyDecode(const byte* input, word32* inOutIdx,
_Example_
\code
DsaKey key;
WC_RNG rng;
WC_WC_RNG rng;
int derSz;
int bufferSize = // Sufficient buffer size;
byte der[bufferSize];
@@ -286,7 +286,7 @@ WOLFSSL_API int wc_DsaKeyToDer(DsaKey* key, byte* output, word32 inLen);
_Example_
\code
WC_RNG rng;
WC_WC_RNG rng;
DsaKey dsa;
wc_InitRng(&rng);
wc_InitDsa(&dsa);
@@ -318,7 +318,7 @@ WOLFSSL_API int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa);
_Example_
\code
DsaKey key;
WC_RNG rng;
WC_WC_RNG rng;
wc_InitDsaKey(&key);
wc_InitRng(&rng);
if(wc_MakeDsaParameters(&rng, 1024, &genKey) != 0)

View File

@@ -41,7 +41,7 @@
\code
ecc_key key;
wc_ecc_init(&key);
RNG rng;
WC_WC_RNG rng;
wc_InitRng(&rng);
wc_ecc_make_key(&rng, 32, &key); // initialize 32 byte ecc key
\endcode
@@ -51,6 +51,7 @@
*/
WOLFSSL_API
int wc_ecc_make_key(WC_RNG* rng, int keysize, ecc_key* key);
/*!
\ingroup ECC
@@ -65,7 +66,7 @@ int wc_ecc_make_key(WC_RNG* rng, int keysize, ecc_key* key);
_Example_
\code
ecc_key key;
RNG rng;
WC_WC_RNG rng;
int check_result;
wc_ecc_init(&key);
wc_InitRng(&rng);
@@ -86,6 +87,7 @@ int wc_ecc_make_key(WC_RNG* rng, int keysize, ecc_key* key);
*/
WOLFSSL_API
int wc_ecc_make_pub(ecc_key* key, ecc_point* pubOut);
/*!
\ingroup ECC
@@ -139,7 +141,7 @@ int wc_ecc_make_pub(ecc_key* key, ecc_point* pubOut);
_Example_
\code
ecc_key priv, pub;
RNG rng;
WC_WC_RNG rng;
byte secret[1024]; // can hold 1024 byte shared secret key
word32 secretSz = sizeof(secret);
int ret;
@@ -161,6 +163,7 @@ int wc_ecc_make_pub(ecc_key* key, ecc_point* pubOut);
WOLFSSL_API
int wc_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out,
word32* outlen);
/*!
\ingroup ECC
@@ -206,6 +209,7 @@ int wc_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out,
WOLFSSL_API
int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point,
byte* out, word32 *outlen);
/*!
\ingroup ECC
@@ -254,7 +258,7 @@ int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point,
_Example_
\code
ecc_key key;
RNG rng;
WC_WC_RNG rng;
int ret, sigSz;
byte sig[512]; // will hold generated signature
@@ -274,6 +278,7 @@ int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point,
WOLFSSL_API
int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen,
WC_RNG* rng, ecc_key* key);
/*!
\ingroup ECC
@@ -319,7 +324,7 @@ int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen,
_Example_
\code
ecc_key key;
WC_RNG rng;
WC_WC_WC_RNG rng;
int ret, sigSz;
mp_int r; // destination for r component of signature.
mp_int s; // destination for s component of signature.
@@ -342,6 +347,7 @@ int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen,
WOLFSSL_API
int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng,
ecc_key* key, mp_int *r, mp_int *s);
/*!
\ingroup ECC
@@ -409,6 +415,7 @@ int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng,
WOLFSSL_API
int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash,
word32 hashlen, int* stat, ecc_key* key);
/*!
\ingroup ECC
@@ -447,6 +454,7 @@ Note: Do not use the return value to test for valid. Only use stat.
WOLFSSL_API
int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
word32 hashlen, int* stat, ecc_key* key);
/*!
\ingroup ECC
@@ -469,6 +477,7 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
*/
WOLFSSL_API
int wc_ecc_init(ecc_key* key);
/*!
\ingroup ECC
@@ -489,6 +498,7 @@ int wc_ecc_init(ecc_key* key);
*/
WOLFSSL_API
int wc_ecc_free(ecc_key* key);
/*!
\ingroup ECC
@@ -513,6 +523,7 @@ int wc_ecc_free(ecc_key* key);
*/
WOLFSSL_API
void wc_ecc_fp_free(void);
/*!
\ingroup ECC
@@ -526,7 +537,7 @@ void wc_ecc_fp_free(void);
_Example_
\code
ecc_key key;
RNG rng;
WC_WC_RNG rng;
int is_valid;
wc_ecc_init(&key);
wc_InitRng(&rng);
@@ -546,6 +557,7 @@ void wc_ecc_fp_free(void);
*/
WOLFSSL_API
int wc_ecc_is_valid_idx(int n);
/*!
\ingroup ECC
@@ -573,6 +585,7 @@ int wc_ecc_is_valid_idx(int n);
*/
WOLFSSL_API
ecc_point* wc_ecc_new_point(void);
/*!
\ingroup ECC
@@ -600,6 +613,7 @@ ecc_point* wc_ecc_new_point(void);
*/
WOLFSSL_API
void wc_ecc_del_point(ecc_point* p);
/*!
\ingroup ECC
@@ -632,6 +646,7 @@ void wc_ecc_del_point(ecc_point* p);
*/
WOLFSSL_API
int wc_ecc_copy_point(ecc_point* p, ecc_point *r);
/*!
\ingroup ECC
@@ -674,6 +689,7 @@ int wc_ecc_copy_point(ecc_point* p, ecc_point *r);
*/
WOLFSSL_API
int wc_ecc_cmp_point(ecc_point* a, ecc_point *b);
/*!
\ingroup ECC
@@ -714,6 +730,7 @@ int wc_ecc_cmp_point(ecc_point* a, ecc_point *b);
*/
WOLFSSL_API
int wc_ecc_point_is_at_infinity(ecc_point *p);
/*!
\ingroup ECC
@@ -748,6 +765,7 @@ int wc_ecc_point_is_at_infinity(ecc_point *p);
WOLFSSL_API
int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R,
mp_int* a, mp_int* modulus, int map);
/*!
\ingroup ECC
@@ -812,6 +830,7 @@ int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R,
*/
WOLFSSL_API
int wc_ecc_export_x963(ecc_key*, byte* out, word32* outLen);
/*!
\ingroup ECC
@@ -882,6 +901,7 @@ int wc_ecc_export_x963(ecc_key*, byte* out, word32* outLen);
*/
WOLFSSL_API
int wc_ecc_export_x963_ex(ecc_key*, byte* out, word32* outLen, int compressed);
/*!
\ingroup ECC
@@ -944,6 +964,7 @@ int wc_ecc_export_x963_ex(ecc_key*, byte* out, word32* outLen, int compressed);
*/
WOLFSSL_API
int wc_ecc_import_x963(const byte* in, word32 inLen, ecc_key* key);
/*!
\ingroup ECC
@@ -1013,6 +1034,7 @@ NOT_COMPILED_IN Returned if the HAVE_COMP_KEY was not enabled at compile
WOLFSSL_API
int wc_ecc_import_private_key(const byte* priv, word32 privSz, const byte* pub,
word32 pubSz, ecc_key* key);
/*!
\ingroup ECC
@@ -1077,6 +1099,7 @@ int wc_ecc_import_private_key(const byte* priv, word32 privSz, const byte* pub,
*/
WOLFSSL_API
int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen);
/*!
\ingroup ECC
@@ -1142,6 +1165,7 @@ int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen);
WOLFSSL_API
int wc_ecc_import_raw(ecc_key* key, const char* qx, const char* qy,
const char* d, const char* curveName);
/*!
\ingroup ECC
@@ -1203,6 +1227,7 @@ int wc_ecc_import_raw(ecc_key* key, const char* qx, const char* qy,
*/
WOLFSSL_API
int wc_ecc_export_private_only(ecc_key* key, byte* out, word32* outLen);
/*!
\ingroup ECC
@@ -1235,6 +1260,7 @@ int wc_ecc_export_private_only(ecc_key* key, byte* out, word32* outLen);
WOLFSSL_API
int wc_ecc_export_point_der(const int curve_idx, ecc_point* point,
byte* out, word32* outLen);
/*!
\ingroup ECC
@@ -1266,6 +1292,7 @@ int wc_ecc_export_point_der(const int curve_idx, ecc_point* point,
WOLFSSL_API
int wc_ecc_import_point_der(byte* in, word32 inLen, const int curve_idx,
ecc_point* point);
/*!
\ingroup ECC
@@ -1292,12 +1319,40 @@ int wc_ecc_import_point_der(byte* in, word32 inLen, const int curve_idx,
*/
WOLFSSL_API
int wc_ecc_size(ecc_key* key);
/*!
\ingroup ECC
\brief This function returns the worst case size for an ECC signature,
given by: keySz * 2 + SIG_HEADER_SZ + 4 The actual signature size can
be computed with wc_ecc_sign_hash.
given by: (keySz * 2) + SIG_HEADER_SZ + ECC_MAX_PAD_SZ.
The actual signature size can be computed with wc_ecc_sign_hash.
\return returns the maximum signature
size, in octets
\param key size
_Example_
\code
int sigSz = wc_ecc_sig_size(32);
if ( sigSz == 0) {
// error determining sig size
}
\endcode
\sa wc_ecc_sign_hash
\sa wc_ecc_sig_size
*/
WOLFSSL_API
int wc_ecc_sig_size_calc(int sz);
/*!
\ingroup ECC
\brief This function returns the worst case size for an ECC signature,
given by: (keySz * 2) + SIG_HEADER_SZ + ECC_MAX_PAD_SZ.
The actual signature size can be computed with wc_ecc_sign_hash.
\return Success Given a valid key, returns the maximum signature
size, in octets
@@ -1314,17 +1369,20 @@ int wc_ecc_size(ecc_key* key);
sigSz = wc_ecc_sig_size(&key);
if ( sigSz == 0) {
// error determining sig size
// error determining sig size
}
\endcode
\sa wc_ecc_sign_hash
\sa wc_ecc_sig_size_calc
*/
WOLFSSL_API
int wc_ecc_sig_size(ecc_key* key);
/*!
\ingroup ECC
\brief This function allocates and initializes space for a new ECC
context object to allow secure message exchange with ECC.
@@ -1340,11 +1398,11 @@ int wc_ecc_sig_size(ecc_key* key);
_Example_
\code
ecEncCtx* ctx;
RNG rng;
WC_WC_RNG rng;
wc_InitRng(&rng);
ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng);
if(ctx == NULL) {
// error generating new ecEncCtx object
// error generating new ecEncCtx object
}
\endcode
@@ -1353,6 +1411,7 @@ int wc_ecc_sig_size(ecc_key* key);
*/
WOLFSSL_API
ecEncCtx* wc_ecc_ctx_new(int flags, WC_RNG* rng);
/*!
\ingroup ECC
@@ -1366,7 +1425,7 @@ ecEncCtx* wc_ecc_ctx_new(int flags, WC_RNG* rng);
_Example_
\code
ecEncCtx* ctx;
RNG rng;
WC_WC_RNG rng;
wc_InitRng(&rng);
ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng);
// do secure communication
@@ -1378,6 +1437,7 @@ ecEncCtx* wc_ecc_ctx_new(int flags, WC_RNG* rng);
*/
WOLFSSL_API
void wc_ecc_ctx_free(ecEncCtx*);
/*!
\ingroup ECC
@@ -1395,7 +1455,7 @@ void wc_ecc_ctx_free(ecEncCtx*);
_Example_
\code
ecEncCtx* ctx;
RNG rng;
WC_WC_RNG rng;
wc_InitRng(&rng);
ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng);
// do secure communication
@@ -1408,6 +1468,7 @@ void wc_ecc_ctx_free(ecEncCtx*);
*/
WOLFSSL_API
int wc_ecc_ctx_reset(ecEncCtx*, WC_RNG*); /* reset for use again w/o alloc/free */
/*!
\ingroup ECC
@@ -1426,7 +1487,7 @@ int wc_ecc_ctx_reset(ecEncCtx*, WC_RNG*); /* reset for use again w/o alloc/free
_Example_
\code
ecEncCtx* ctx;
RNG rng;
WC_WC_RNG rng;
const byte* salt;
wc_InitRng(&rng);
ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng);
@@ -1441,6 +1502,7 @@ int wc_ecc_ctx_reset(ecEncCtx*, WC_RNG*); /* reset for use again w/o alloc/free
*/
WOLFSSL_API
const byte* wc_ecc_ctx_get_own_salt(ecEncCtx*);
/*!
\ingroup ECC
@@ -1461,7 +1523,7 @@ const byte* wc_ecc_ctx_get_own_salt(ecEncCtx*);
_Example_
\code
ecEncCtx* cliCtx, srvCtx;
RNG rng;
WC_WC_RNG rng;
const byte* cliSalt, srvSalt;
int ret;
@@ -1478,6 +1540,7 @@ const byte* wc_ecc_ctx_get_own_salt(ecEncCtx*);
*/
WOLFSSL_API
int wc_ecc_ctx_set_peer_salt(ecEncCtx*, const byte* salt);
/*!
\ingroup ECC
@@ -1508,6 +1571,7 @@ int wc_ecc_ctx_set_peer_salt(ecEncCtx*, const byte* salt);
*/
WOLFSSL_API
int wc_ecc_ctx_set_info(ecEncCtx*, const byte* info, int sz);
/*!
\ingroup ECC
@@ -1568,6 +1632,7 @@ int wc_ecc_ctx_set_info(ecEncCtx*, const byte* info, int sz);
WOLFSSL_API
int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx);
/*!
\ingroup ECC

View File

@@ -18,7 +18,7 @@
\code
ed25519_key key;
wc_ed25519_init(&key);
RNG rng;
WC_RNG rng;
wc_InitRng(&rng);
wc_ed25519_make_key(&rng, 32, &key); // initialize 32 byte ed25519 key
\endcode
@@ -51,7 +51,7 @@ int wc_ed25519_make_key(WC_RNG* rng, int keysize, ed25519_key* key);
_Example_
\code
ed25519_key key;
RNG rng;
WC_RNG rng;
int ret, sigSz;
byte sig[64]; // will hold generated signature
@@ -332,7 +332,7 @@ int wc_ed25519_export_private_only(ed25519_key* key, byte* out, word32* outLen);
ed25519_key key;
wc_ed25519_init(&key);
RNG rng;
WC_RNG rng;
wc_InitRng(&rng);
wc_ed25519_make_key(&rng, 32, &key); // initialize 32 byte ed25519 key
@@ -432,7 +432,7 @@ int wc_ed25519_size(ed25519_key* key);
ed25519_key key;
wc_ed25519_init(&key);
RNG rng;
WC_RNG rng;
wc_InitRng(&rng);
wc_ed25519_make_key(&rng, 32, &key); // initialize 32 byte ed25519 key
@@ -457,7 +457,7 @@ int wc_ed25519_priv_size(ed25519_key* key);
\code
ed25519_key key;
wc_ed25519_init(&key);
RNG rng;
WC_RNG rng;
wc_InitRng(&rng);
wc_ed25519_make_key(&rng, 32, &key); // initialize 32 byte ed25519 key

View File

@@ -28,6 +28,7 @@
\sa wc_FreeRsaKey
*/
WOLFSSL_API int wc_InitRsaKey(RsaKey* key, void* heap);
/*!
\ingroup RSA
@@ -49,6 +50,7 @@ WOLFSSL_API int wc_InitRsaKey(RsaKey* key, void* heap);
\sa wc_InitRsaKey
*/
WOLFSSL_API int wc_FreeRsaKey(RsaKey* key);
/*!
\ingroup RSA
@@ -122,6 +124,7 @@ WOLFSSL_API int wc_FreeRsaKey(RsaKey* key);
*/
WOLFSSL_API int wc_RsaPublicEncrypt(const byte* in, word32 inLen, byte* out,
word32 outLen, RsaKey* key, WC_RNG* rng);
/*!
\ingroup RSA
@@ -145,6 +148,7 @@ WOLFSSL_API int wc_RsaPublicEncrypt(const byte* in, word32 inLen, byte* out,
*/
WOLFSSL_API int wc_RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out,
RsaKey* key);
/*!
\ingroup RSA
@@ -178,6 +182,7 @@ WOLFSSL_API int wc_RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out,
*/
WOLFSSL_API int wc_RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out,
word32 outLen, RsaKey* key);
/*!
\ingroup RSA
@@ -210,6 +215,7 @@ WOLFSSL_API int wc_RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out,
*/
WOLFSSL_API int wc_RsaSSL_Sign(const byte* in, word32 inLen, byte* out,
word32 outLen, RsaKey* key, WC_RNG* rng);
/*!
\ingroup RSA
@@ -227,7 +233,7 @@ WOLFSSL_API int wc_RsaSSL_Sign(const byte* in, word32 inLen, byte* out,
_Example_
\code
RsaKey key;
RNG rng;
WC_WC_RNG rng;
int ret = 0;
long e = 65537; // standard value to use for exponent
wc_InitRsaKey(&key, NULL); // not using heap hint. No custom memory
@@ -247,6 +253,7 @@ WOLFSSL_API int wc_RsaSSL_Sign(const byte* in, word32 inLen, byte* out,
*/
WOLFSSL_API int wc_RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out,
RsaKey* key);
/*!
\ingroup RSA
@@ -278,6 +285,7 @@ WOLFSSL_API int wc_RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out,
*/
WOLFSSL_API int wc_RsaSSL_Verify(const byte* in, word32 inLen, byte* out,
word32 outLen, RsaKey* key);
/*!
\ingroup RSA
@@ -298,6 +306,7 @@ WOLFSSL_API int wc_RsaSSL_Verify(const byte* in, word32 inLen, byte* out,
\sa XMEMSET
*/
WOLFSSL_API int wc_RsaEncryptSize(RsaKey* key);
/*!
\ingroup RSA
@@ -341,6 +350,7 @@ WOLFSSL_API int wc_RsaEncryptSize(RsaKey* key);
*/
WOLFSSL_API int wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx,
RsaKey*, word32);
/*!
\ingroup RSA
@@ -389,6 +399,7 @@ WOLFSSL_API int wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx,
*/
WOLFSSL_API int wc_RsaPublicKeyDecode(const byte* input, word32* inOutIdx,
RsaKey*, word32);
/*!
\ingroup RSA
@@ -433,6 +444,7 @@ WOLFSSL_API int wc_RsaPublicKeyDecode(const byte* input, word32* inOutIdx,
*/
WOLFSSL_API int wc_RsaPublicKeyDecodeRaw(const byte* n, word32 nSz,
const byte* e, word32 eSz, RsaKey* key);
/*!
\ingroup RSA
@@ -454,7 +466,7 @@ WOLFSSL_API int wc_RsaPublicKeyDecodeRaw(const byte* n, word32 nSz,
// Allocate memory for der
int derSz = // Amount of memory allocated for der;
RsaKey key;
RNG rng;
WC_WC_RNG rng;
long e = 65537; // standard value to use for exponent
ret = wc_MakeRsaKey(&key, 2048, e, &rng); // generate 2048 bit long
private key
@@ -472,6 +484,7 @@ WOLFSSL_API int wc_RsaPublicKeyDecodeRaw(const byte* n, word32 nSz,
\sa wc_InitRng
*/
WOLFSSL_API int wc_RsaKeyToDer(RsaKey*, byte* output, word32 inLen);
/*!
\ingroup RSA
@@ -496,7 +509,7 @@ WOLFSSL_API int wc_RsaPublicKeyDecodeRaw(const byte* n, word32 nSz,
_Example_
\code
WC_RNG rng;
WC_WC_WC_RNG rng;
RsaKey key;
byte in[] = “I use Turing Machines to ask questions”
byte out[256];
@@ -516,6 +529,7 @@ WOLFSSL_API int wc_RsaPublicKeyDecodeRaw(const byte* n, word32 nSz,
WOLFSSL_API int wc_RsaPublicEncrypt_ex(const byte* in, word32 inLen, byte* out,
word32 outLen, RsaKey* key, WC_RNG* rng, int type,
enum wc_HashType hash, int mgf, byte* label, word32 lableSz);
/*!
\ingroup RSA
@@ -542,7 +556,7 @@ WOLFSSL_API int wc_RsaPublicEncrypt_ex(const byte* in, word32 inLen, byte* out,
_Example_
\code
WC_RNG rng;
WC_WC_WC_RNG rng;
RsaKey key;
byte in[] = “I use Turing Machines to ask questions”
byte out[256];
@@ -568,6 +582,7 @@ WOLFSSL_API int wc_RsaPublicEncrypt_ex(const byte* in, word32 inLen, byte* out,
WOLFSSL_API int wc_RsaPrivateDecrypt_ex(const byte* in, word32 inLen,
byte* out, word32 outLen, RsaKey* key, int type,
enum wc_HashType hash, int mgf, byte* label, word32 lableSz);
/*!
\ingroup RSA
@@ -598,7 +613,7 @@ WOLFSSL_API int wc_RsaPrivateDecrypt_ex(const byte* in, word32 inLen,
_Example_
\code
WC_RNG rng;
WC_WC_WC_RNG rng;
RsaKey key;
byte in[] = “I use Turing Machines to ask questions”
byte out[256];
@@ -625,6 +640,7 @@ WOLFSSL_API int wc_RsaPrivateDecrypt_ex(const byte* in, word32 inLen,
WOLFSSL_API int wc_RsaPrivateDecryptInline_ex(byte* in, word32 inLen,
byte** out, RsaKey* key, int type, enum wc_HashType hash,
int mgf, byte* label, word32 lableSz);
/*!
\ingroup RSA
@@ -669,6 +685,7 @@ WOLFSSL_API int wc_RsaPrivateDecryptInline_ex(byte* in, word32 inLen,
*/
WOLFSSL_API int wc_RsaFlattenPublicKey(RsaKey*, byte*, word32*, byte*,
word32*);
/*!
\ingroup RSA
@@ -703,6 +720,7 @@ WOLFSSL_API int wc_RsaFlattenPublicKey(RsaKey*, byte*, word32*, byte*,
\sa wc_RsaInitKey
*/
WOLFSSL_API int wc_RsaKeyToPublicDer(RsaKey*, byte* output, word32 inLen);
/*!
\ingroup RSA
@@ -757,7 +775,7 @@ WOLFSSL_API int wc_RsaFlattenPublicKey(RsaKey*, byte*, word32*, byte*,
_Example_
\code
RsaKey priv;
RNG rng;
WC_WC_RNG rng;
int ret = 0;
long e = 65537; // standard value to use for exponent

View File

@@ -106,7 +106,7 @@ WOLFSSL_API int wc_SignatureVerify(
_Example_
\code
int ret;
RNG rng;
WC_RNG rng;
ecc_key eccKey;
wc_InitRng(&rng);

View File

@@ -3589,7 +3589,7 @@ WOLFSSL_API WOLFSSL_SESSION* wolfSSL_get1_session(WOLFSSL* ssl);
downgrade to SSLv3 if needed. In this case, the client will be able to
connect to a server running SSLv3 - TLSv1.2.
\return pointer upon succes a pointer to a WOLFSSL_METHOD.
\return pointer upon success a pointer to a WOLFSSL_METHOD.
\return Failure If memory allocation fails when calling XMALLOC,
the failure value of the underlying malloc() implementation will be
returned (typically NULL with errno will be set to ENOMEM).

View File

@@ -833,7 +833,10 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
int useClientCert = 1;
int fewerPackets = 0;
int atomicUser = 0;
#ifdef HAVE_PK_CALLBACKS
int pkCallbacks = 0;
PkCbInfo pkCbInfo;
#endif
int overrideDateErrors = 0;
int minDhKeyBits = DEFAULT_MIN_DHKEY_BITS;
char* alpnList = NULL;
@@ -926,7 +929,6 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
(void)session;
(void)sslResume;
(void)atomicUser;
(void)pkCallbacks;
(void)scr;
(void)forceScr;
(void)ourKey;
@@ -1619,26 +1621,35 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
wolfSSL_CTX_SetCACb(ctx, CaCb);
#endif
#if !defined(NO_CERTS)
#ifndef NO_CERTS
if (useClientCert){
#if !defined(NO_FILESYSTEM)
#ifndef NO_FILESYSTEM
if (wolfSSL_CTX_use_certificate_chain_file(ctx, ourCert)
!= WOLFSSL_SUCCESS) {
wolfSSL_CTX_free(ctx);
err_sys("can't load client cert file, check file and run from"
" wolfSSL home dir");
}
#else
load_buffer(ctx, ourCert, WOLFSSL_CERT_CHAIN);
#endif
#ifdef HAVE_PK_CALLBACKS
pkCbInfo.ourKey = ourKey;
#ifdef TEST_PK_PRIVKEY
if (!pkCallbacks)
#endif
#endif
#ifndef NO_FILESYSTEM
if (wolfSSL_CTX_use_PrivateKey_file(ctx, ourKey, WOLFSSL_FILETYPE_PEM)
!= WOLFSSL_SUCCESS) {
wolfSSL_CTX_free(ctx);
err_sys("can't load client private key file, check file and run "
"from wolfSSL home dir");
}
#else
load_buffer(ctx, ourCert, WOLFSSL_CERT_CHAIN);
#else
load_buffer(ctx, ourKey, WOLFSSL_KEY);
#endif /* !defined(NO_FILESYSTEM) */
#endif
}
/* for testing only - use client cert as CA to force no signer error */
@@ -1651,28 +1662,28 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
}
if (!usePsk && !useAnon && !useVerifyCb) {
#if !defined(NO_FILESYSTEM)
#if !defined(NO_FILESYSTEM)
if (wolfSSL_CTX_load_verify_locations(ctx, verifyCert,0)
!= WOLFSSL_SUCCESS) {
wolfSSL_CTX_free(ctx);
err_sys("can't load ca file, Please run from wolfSSL home dir");
}
#else
#else
load_buffer(ctx, verifyCert, WOLFSSL_CA);
#endif /* !defined(NO_FILESYSTEM) */
#ifdef HAVE_ECC
#endif /* !NO_FILESYSTEM */
#ifdef HAVE_ECC
/* load ecc verify too, echoserver uses it by default w/ ecc */
#if !defined(NO_FILESYSTEM)
#ifndef NO_FILESYSTEM
if (wolfSSL_CTX_load_verify_locations(ctx, eccCertFile, 0)
!= WOLFSSL_SUCCESS) {
wolfSSL_CTX_free(ctx);
err_sys("can't load ecc ca file, Please run from wolfSSL home dir");
}
#else
#else
load_buffer(ctx, eccCertFile, WOLFSSL_CA);
#endif /* !defined(NO_FILESYSTEM) */
#endif /* HAVE_ECC */
#if defined(WOLFSSL_TRUST_PEER_CERT) && !defined(NO_FILESYSTEM)
#endif /* !NO_FILESYSTEM */
#endif /* HAVE_ECC */
#if defined(WOLFSSL_TRUST_PEER_CERT) && !defined(NO_FILESYSTEM)
if (trustCert) {
if ((ret = wolfSSL_CTX_trust_peer_cert(ctx, trustCert,
WOLFSSL_FILETYPE_PEM)) != WOLFSSL_SUCCESS) {
@@ -1680,7 +1691,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
err_sys("can't load trusted peer cert file");
}
}
#endif /* WOLFSSL_TRUST_PEER_CERT && !NO_FILESYSTEM */
#endif /* WOLFSSL_TRUST_PEER_CERT && !NO_FILESYSTEM */
}
if (useVerifyCb)
wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myVerify);
@@ -1688,7 +1699,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_NONE, 0);
else if (!usePsk && !useAnon && overrideDateErrors == 1)
wolfSSL_CTX_set_verify(ctx, WOLFSSL_VERIFY_PEER, myDateCb);
#endif /* !defined(NO_CERTS) */
#endif /* !NO_CERTS */
#ifdef WOLFSSL_ASYNC_CRYPT
ret = wolfAsync_DevOpen(&devId);
@@ -1806,6 +1817,11 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
#endif
}
#ifdef HAVE_PK_CALLBACKS
if (pkCallbacks)
SetupPkCallbacks(ctx);
#endif
ssl = wolfSSL_new(ctx);
if (ssl == NULL) {
wolfSSL_CTX_free(ctx);
@@ -1999,7 +2015,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
#endif
#ifdef HAVE_PK_CALLBACKS
if (pkCallbacks)
SetupPkCallbacks(ctx, ssl);
SetupPkCallbackContexts(ssl, &pkCbInfo);
#endif
if (matchName && doPeerCheck)
wolfSSL_check_domain_name(ssl, domain);

View File

@@ -463,7 +463,10 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
int useNtruKey = 0;
int nonBlocking = 0;
int fewerPackets = 0;
#ifdef HAVE_PK_CALLBACKS
int pkCallbacks = 0;
PkCbInfo pkCbInfo;
#endif
int wc_shutdown = 0;
int resume = 0;
int resumeCount = 0;
@@ -549,7 +552,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
ourCert = (char*)eccCertFile;
ourKey = (char*)eccKeyFile;
#endif
(void)pkCallbacks;
(void)needDH;
(void)ourKey;
(void)ourCert;
@@ -1041,6 +1044,12 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
}
#endif
#if !defined(NO_CERTS)
#ifdef HAVE_PK_CALLBACKS
pkCbInfo.ourKey = ourKey;
#ifdef TEST_PK_PRIVKEY
if (!pkCallbacks)
#endif
#endif
if (!useNtruKey && (!usePsk || usePskPlus) && !useAnon) {
#if !defined(NO_FILESYSTEM)
if (SSL_CTX_use_PrivateKey_file(ctx, ourKey, WOLFSSL_FILETYPE_PEM)
@@ -1180,6 +1189,11 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
#endif
}
#ifdef HAVE_PK_CALLBACKS
if (pkCallbacks)
SetupPkCallbacks(ctx);
#endif
ssl = SSL_new(ctx);
if (ssl == NULL)
err_sys_ex(runWithErrors, "unable to get SSL");
@@ -1255,9 +1269,10 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
if (SSL_CTX_load_verify_locations(ctx, "certs/ocsp/intermediate3-ca-cert.pem", 0) != WOLFSSL_SUCCESS)
err_sys_ex(runWithErrors, "can't load ca file, Please run from wolfSSL home dir");
#endif
#ifdef HAVE_PK_CALLBACKS
if (pkCallbacks)
SetupPkCallbacks(ctx, ssl);
SetupPkCallbackContexts(ssl, &pkCbInfo);
#endif
/* do accept */

File diff suppressed because it is too large Load Diff

139
src/ssl.c
View File

@@ -5338,30 +5338,27 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
WOLFSSL_MSG("RSA decode failed and ECC not enabled to try");
ret = WOLFSSL_BAD_FILE;
#endif
} else {
}
else {
/* check that the size of the RSA key is enough */
int rsaSz = wc_RsaEncryptSize((RsaKey*)key);
int minRsaSz;
minRsaSz = ssl ? ssl->options.minRsaKeySz : ctx->minRsaKeySz;
if (rsaSz < minRsaSz) {
ret = RSA_KEY_SIZE_E;
WOLFSSL_MSG("Private Key size too small");
}
if (ssl) {
if (rsaSz < ssl->options.minRsaKeySz) {
ret = RSA_KEY_SIZE_E;
WOLFSSL_MSG("Private Key size too small");
}
ssl->buffers.keyType = rsa_sa_algo;
#ifdef WC_RSA_PSS
ssl->buffers.keySz = rsaSz;
#endif
}
else if(ctx) {
if (rsaSz < ctx->minRsaKeySz) {
ret = RSA_KEY_SIZE_E;
WOLFSSL_MSG("Private Key size too small");
}
ctx->privateKeyType = rsa_sa_algo;
#ifdef WC_RSA_PSS
ctx->privateKeySz = rsaSz;
#endif
}
rsaKey = 1;
(void)rsaKey; /* for no ecc builds */
@@ -5391,31 +5388,27 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
if (wc_ecc_init_ex(&key, heap, devId) == 0) {
if (wc_EccPrivateKeyDecode(der->buffer, &idx, &key,
der->length) == 0) {
int keySz = wc_ecc_size(&key);
int minKeySz;
/* check for minimum ECC key size and then free */
if (ssl) {
if (wc_ecc_size(&key) < ssl->options.minEccKeySz) {
wc_ecc_free(&key);
WOLFSSL_MSG("ECC private key too small");
return ECC_KEY_SIZE_E;
}
}
else if (ctx) {
if (wc_ecc_size(&key) < ctx->minEccKeySz) {
wc_ecc_free(&key);
WOLFSSL_MSG("ECC private key too small");
return ECC_KEY_SIZE_E;
}
minKeySz = ssl ? ssl->options.minEccKeySz : ctx->minEccKeySz;
if (keySz < minKeySz) {
wc_ecc_free(&key);
WOLFSSL_MSG("ECC private key too small");
return ECC_KEY_SIZE_E;
}
eccKey = 1;
if (ssl) {
ssl->options.haveStaticECC = 1;
ssl->buffers.keyType = ecc_dsa_sa_algo;
ssl->buffers.keySz = keySz;
}
else if (ctx) {
ctx->haveStaticECC = 1;
ctx->privateKeyType = ecc_dsa_sa_algo;
ctx->privateKeySz = keySz;
}
if (ssl && ssl->options.side == WOLFSSL_SERVER_END) {
@@ -5434,6 +5427,8 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
/* make sure Ed25519 key can be used */
word32 idx = 0;
ed25519_key key;
const int keySz = ED25519_KEY_SIZE;
int minKeySz;
ret = wc_ed25519_init(&key);
if (ret != 0) {
@@ -5447,21 +5442,20 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
}
/* check for minimum key size and then free */
minKeySz = ssl ? ssl->options.minEccKeySz : ctx->minEccKeySz;
if (keySz < minKeySz) {
wc_ed25519_free(&key);
WOLFSSL_MSG("ED25519 private key too small");
return ECC_KEY_SIZE_E;
}
if (ssl) {
if (ED25519_KEY_SIZE < ssl->options.minEccKeySz) {
wc_ed25519_free(&key);
WOLFSSL_MSG("ED25519 private key too small");
return ECC_KEY_SIZE_E;
}
ssl->buffers.keyType = ed25519_sa_algo;
ssl->buffers.keySz = keySz;
}
else if (ctx) {
if (ED25519_KEY_SIZE < ctx->minEccKeySz) {
wc_ed25519_free(&key);
WOLFSSL_MSG("ED25519 private key too small");
return ECC_KEY_SIZE_E;
}
ctx->privateKeyType = ed25519_sa_algo;
ctx->privateKeySz = keySz;
}
wc_ed25519_free(&key);
@@ -5485,6 +5479,9 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
#else
DecodedCert cert[1];
#endif
#ifdef HAVE_PK_CALLBACKS
int keyType = 0, keySz = 0;
#endif
#ifdef WOLFSSL_SMALL_STACK
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), heap,
@@ -5587,6 +5584,12 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
WOLFSSL_MSG("Certificate RSA key size too small");
}
}
#ifdef HAVE_PK_CALLBACKS
keyType = rsa_sa_algo;
/* pubKeySize is the encoded public key */
/* mask lsb 5-bits to round by 16 to get actual key size */
keySz = cert->pubKeySize & ~0x1FL;
#endif
break;
#endif /* !NO_RSA */
#ifdef HAVE_ECC
@@ -5605,6 +5608,11 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
WOLFSSL_MSG("Certificate ECC key size error");
}
}
#ifdef HAVE_PK_CALLBACKS
keyType = ecc_dsa_sa_algo;
/* pubKeySize is encByte + x + y */
keySz = (cert->pubKeySize - 1) / 2;
#endif
break;
#endif /* HAVE_ECC */
#ifdef HAVE_ED25519
@@ -5623,6 +5631,10 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
WOLFSSL_MSG("Certificate ECC key size error");
}
}
#ifdef HAVE_PK_CALLBACKS
keyType = ed25519_sa_algo;
keySz = ED25519_KEY_SIZE;
#endif
break;
#endif /* HAVE_ED25519 */
@@ -5631,6 +5643,17 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff,
break; /* do no check if not a case for the key */
}
#ifdef HAVE_PK_CALLBACKS
if (ssl && ssl->buffers.keyType == 0) {
ssl->buffers.keyType = keyType;
ssl->buffers.keySz = keySz;
}
else if (ctx && ctx->privateKeyType == 0) {
ctx->privateKeyType = keyType;
ctx->privateKeySz = keySz;
}
#endif
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, heap, DYNAMIC_TYPE_DCERT);
@@ -9762,27 +9785,39 @@ int wolfSSL_DTLS_SetCookieSecret(WOLFSSL* ssl,
return WOLFSSL_FATAL_ERROR;
}
#ifndef NO_CERTS
/* in case used set_accept_state after init */
if (!havePSK && !haveAnon && !haveMcast &&
(!ssl->buffers.certificate ||
!ssl->buffers.certificate->buffer ||
!ssl->buffers.key ||
!ssl->buffers.key->buffer)) {
WOLFSSL_MSG("accept error: don't have server cert and key");
ssl->error = NO_PRIVATE_KEY;
WOLFSSL_ERROR(ssl->error);
#ifndef NO_CERTS
/* in case used set_accept_state after init */
/* allow no private key if using PK callbacks and CB is set */
if (!havePSK && !haveAnon && !haveMcast) {
if (!ssl->buffers.certificate ||
!ssl->buffers.certificate->buffer) {
WOLFSSL_MSG("accept error: server cert required");
WOLFSSL_ERROR(ssl->error = NO_PRIVATE_KEY);
return WOLFSSL_FATAL_ERROR;
}
#endif
#ifdef WOLFSSL_DTLS
if (ssl->version.major == DTLS_MAJOR) {
ssl->options.dtls = 1;
ssl->options.tls = 1;
ssl->options.tls1_1 = 1;
#ifdef HAVE_PK_CALLBACKS
if (wolfSSL_CTX_IsPrivatePkSet(ssl->ctx)) {
WOLFSSL_MSG("Using PK for server private key");
}
else
#endif
if (!ssl->buffers.key || !ssl->buffers.key->buffer) {
WOLFSSL_MSG("accept error: server key required");
WOLFSSL_ERROR(ssl->error = NO_PRIVATE_KEY);
return WOLFSSL_FATAL_ERROR;
}
}
#endif
#ifdef WOLFSSL_DTLS
if (ssl->version.major == DTLS_MAJOR) {
ssl->options.dtls = 1;
ssl->options.tls = 1;
ssl->options.tls1_1 = 1;
}
#endif
if (ssl->buffers.outputBuffer.length > 0) {
if ( (ssl->error = SendBuffered(ssl)) == 0) {

View File

@@ -1616,7 +1616,7 @@ static int EncryptTls13(WOLFSSL* ssl, byte* output, const byte* input,
#ifdef BUILD_AESGCM
case wolfssl_aes_gcm:
#ifdef WOLFSSL_ASYNC_CRYPT
/* intialize event */
/* initialize event */
asyncDev = &ssl->encrypt.aes->asyncDev;
ret = wolfSSL_AsyncInit(ssl, asyncDev, event_flags);
if (ret != 0)
@@ -1633,7 +1633,7 @@ static int EncryptTls13(WOLFSSL* ssl, byte* output, const byte* input,
#ifdef HAVE_AESCCM
case wolfssl_aes_ccm:
#ifdef WOLFSSL_ASYNC_CRYPT
/* intialize event */
/* initialize event */
asyncDev = &ssl->encrypt.aes->asyncDev;
ret = wolfSSL_AsyncInit(ssl, asyncDev, event_flags);
if (ret != 0)
@@ -1841,7 +1841,7 @@ int DecryptTls13(WOLFSSL* ssl, byte* output, const byte* input, word16 sz,
#ifdef BUILD_AESGCM
case wolfssl_aes_gcm:
#ifdef WOLFSSL_ASYNC_CRYPT
/* intialize event */
/* initialize event */
ret = wolfSSL_AsyncInit(ssl, &ssl->decrypt.aes->asyncDev,
WC_ASYNC_FLAG_CALL_AGAIN);
if (ret != 0)
@@ -1864,7 +1864,7 @@ int DecryptTls13(WOLFSSL* ssl, byte* output, const byte* input, word16 sz,
#ifdef HAVE_AESCCM
case wolfssl_aes_ccm:
#ifdef WOLFSSL_ASYNC_CRYPT
/* intialize event */
/* initialize event */
ret = wolfSSL_AsyncInit(ssl, &ssl->decrypt.aes->asyncDev,
WC_ASYNC_FLAG_CALL_AGAIN);
if (ret != 0)
@@ -2261,6 +2261,7 @@ static int WritePSKBinders(WOLFSSL* ssl, byte* output, word32 idx)
}
#endif
/* handle generation of TLS 1.3 client_hello (1) */
/* Send a ClientHello message to the server.
* Include the information required to start a handshake with servers using
* protocol versions less than TLS v1.3.
@@ -2536,6 +2537,7 @@ static int RestartHandshakeHash(WOLFSSL* ssl)
#endif
#ifdef WOLFSSL_TLS13_DRAFT_18
/* handle rocessing of TLS 1.3 hello_retry_request (6) */
/* Parse and handle a HelloRetryRequest message.
* Only a client will receive this message.
*
@@ -2615,6 +2617,7 @@ static byte helloRetryRequestRandom[] = {
};
#endif
/* handle processing of TLS 1.3 server_hello (2) and hello_retry_request (6) */
/* Handle the ServerHello message from the server.
* Only a client will receive this message.
*
@@ -2859,6 +2862,7 @@ int DoTls13ServerHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
return ret;
}
/* handle processing TLS 1.3 encrypted_extensions (8) */
/* Parse and handle an EncryptedExtensions message.
* Only a client will receive this message.
*
@@ -2918,6 +2922,7 @@ static int DoTls13EncryptedExtensions(WOLFSSL* ssl, const byte* input,
return ret;
}
/* handle processing TLS v1.3 certificate_request (13) */
/* Handle a TLS v1.3 CertificateRequest message.
* This message is always encrypted.
* Only a client will receive this message.
@@ -3522,6 +3527,7 @@ static int RestartHandshakeHashWithCookie(WOLFSSL* ssl, Cookie* cookie)
}
#endif
/* handle processing of TLS 1.3 client_hello (1) */
/* Handle a ClientHello handshake message.
* If the protocol version in the message is not TLS v1.3 or higher, use
* DoClientHello()
@@ -3729,6 +3735,7 @@ int DoTls13ClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
}
#ifdef WOLFSSL_TLS13_DRAFT_18
/* handle generation of TLS 1.3 hello_retry_request (6) */
/* Send the HelloRetryRequest message to indicate the negotiated protocol
* version and security parameters the server is willing to use.
* Only a server will send this message.
@@ -3813,6 +3820,7 @@ int SendTls13HelloRetryRequest(WOLFSSL* ssl)
#ifdef WOLFSSL_TLS13_DRAFT_18
static
#endif
/* handle generation of TLS 1.3 server_hello (2) */
int SendTls13ServerHello(WOLFSSL* ssl, byte extMsgType)
{
byte* output;
@@ -3940,6 +3948,7 @@ int SendTls13ServerHello(WOLFSSL* ssl, byte extMsgType)
return ret;
}
/* handle generation of TLS 1.3 encrypted_extensions (8) */
/* Send the rest of the extensions encrypted under the handshake key.
* This message is always encrypted in TLS v1.3.
* Only a server will send this message.
@@ -4029,6 +4038,7 @@ static int SendTls13EncryptedExtensions(WOLFSSL* ssl)
}
#ifndef NO_CERTS
/* handle generation TLS v1.3 certificate_request (13) */
/* Send the TLS v1.3 CertificateRequest message.
* This message is always encrypted in TLS v1.3.
* Only a server will send this message.
@@ -4550,6 +4560,7 @@ static word32 AddCertExt(byte* cert, word32 len, word32 idx, word32 fragSz,
return i;
}
/* handle generation TLS v1.3 certificate (11) */
/* Send the certificate for this end and any CAs that help with validation.
* This message is always encrypted in TLS v1.3.
*
@@ -4799,6 +4810,7 @@ static void FreeScv13Args(WOLFSSL* ssl, void* pArgs)
}
}
/* handle generation TLS v1.3 certificate_verify (15) */
/* Send the TLS v1.3 CertificateVerify message.
* A hash of all the message so far is used.
* The signed data is:
@@ -4874,9 +4886,23 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
args->verify =
&args->output[RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ];
ret = DecodePrivateKey(ssl, &args->length);
if (ret != 0)
goto exit_scv;
if (ssl->buffers.key == NULL) {
#ifdef HAVE_PK_CALLBACKS
if (wolfSSL_CTX_IsPrivatePkSet(ssl->ctx))
args->length = GetPrivateKeySigSize(ssl);
else
#endif
ERROR_OUT(NO_PRIVATE_KEY, exit_scv);
}
else {
ret = DecodePrivateKey(ssl, &args->length);
if (ret != 0)
goto exit_scv;
}
if (args->length <= 0) {
ERROR_OUT(NO_PRIVATE_KEY, exit_scv);
}
/* Add signature algorithm. */
if (ssl->hsType == DYNAMIC_TYPE_RSA)
@@ -4952,11 +4978,11 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
ret = EccSign(ssl, args->sigData, args->sigDataSz,
args->verify + HASH_SIG_SIZE + VERIFY_HEADER,
&sig->length, (ecc_key*)ssl->hsKey,
#if defined(HAVE_PK_CALLBACKS)
ssl->buffers.key->buffer, ssl->buffers.key->length,
#ifdef HAVE_PK_CALLBACKS
ssl->buffers.key,
ssl->EccSignCtx
#else
NULL, 0, NULL
NULL, NULL
#endif
);
args->length = sig->length;
@@ -4967,11 +4993,11 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
ret = Ed25519Sign(ssl, args->sigData, args->sigDataSz,
args->verify + HASH_SIG_SIZE + VERIFY_HEADER,
&sig->length, (ed25519_key*)ssl->hsKey,
#if defined(HAVE_PK_CALLBACKS)
ssl->buffers.key->buffer, ssl->buffers.key->length,
#ifdef HAVE_PK_CALLBACKS
ssl->buffers.key,
ssl->Ed25519SignCtx
#else
NULL, 0, NULL
NULL, NULL
#endif
);
args->length = sig->length;
@@ -4984,7 +5010,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
args->verify + HASH_SIG_SIZE + VERIFY_HEADER, &args->sigLen,
args->sigAlgo, ssl->suites->hashAlgo,
(RsaKey*)ssl->hsKey,
ssl->buffers.key->buffer, ssl->buffers.key->length,
ssl->buffers.key,
#ifdef HAVE_PK_CALLBACKS
ssl->RsaSignCtx
#else
@@ -5027,7 +5053,7 @@ static int SendTls13CertificateVerify(WOLFSSL* ssl)
ret = VerifyRsaSign(ssl, args->verifySig, args->sigLen,
sig->buffer, sig->length, args->sigAlgo,
ssl->suites->hashAlgo, (RsaKey*)ssl->hsKey,
ssl->buffers.key->buffer, ssl->buffers.key->length,
ssl->buffers.key,
#ifdef HAVE_PK_CALLBACKS
ssl->RsaSignCtx
#else
@@ -5115,7 +5141,7 @@ exit_scv:
return ret;
}
/* handle processing TLS v1.3 certificate (11) */
/* Parse and handle a TLS v1.3 Certificate message.
*
* ssl The SSL/TLS object.
@@ -5177,6 +5203,7 @@ static void FreeDcv13Args(WOLFSSL* ssl, void* pArgs)
(void)ssl;
}
/* handle processing TLS v1.3 certificate_verify (15) */
/* Parse and handle a TLS v1.3 CertificateVerify message.
*
* ssl The SSL/TLS object.
@@ -5342,11 +5369,10 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,
ret = RsaVerify(ssl, sig->buffer, sig->length, &args->output,
args->sigAlgo, args->hashAlgo, ssl->peerRsaKey,
#ifdef HAVE_PK_CALLBACKS
ssl->buffers.peerRsaKey.buffer,
ssl->buffers.peerRsaKey.length,
&ssl->buffers.peerRsaKey,
ssl->RsaVerifyCtx
#else
NULL, 0, NULL
NULL, NULL
#endif
);
if (ret >= 0) {
@@ -5363,11 +5389,10 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,
args->sigData, args->sigDataSz,
ssl->peerEccDsaKey,
#ifdef HAVE_PK_CALLBACKS
ssl->buffers.peerEccDsaKey.buffer,
ssl->buffers.peerEccDsaKey.length,
&ssl->buffers.peerEccDsaKey,
ssl->EccVerifyCtx
#else
NULL, 0, NULL
NULL, NULL
#endif
);
}
@@ -5380,11 +5405,10 @@ static int DoTls13CertificateVerify(WOLFSSL* ssl, byte* input,
args->sigData, args->sigDataSz,
ssl->peerEd25519Key,
#ifdef HAVE_PK_CALLBACKS
ssl->buffers.peerEd25519Key.buffer,
ssl->buffers.peerEd25519Key.length,
&ssl->buffers.peerEd25519Key,
ssl->Ed25519VerifyCtx
#else
NULL, 0, NULL
NULL, NULL
#endif
);
}
@@ -5698,6 +5722,7 @@ static int SendTls13Finished(WOLFSSL* ssl)
return ret;
}
/* handle generation TLS v1.3 key_update (24) */
/* Send the TLS v1.3 KeyUpdate message.
*
* ssl The SSL/TLS object.
@@ -5769,6 +5794,7 @@ static int SendTls13KeyUpdate(WOLFSSL* ssl)
return ret;
}
/* handle processing TLS v1.3 key_update (24) */
/* Parse and handle a TLS v1.3 KeyUpdate message.
*
* ssl The SSL/TLS object.
@@ -5880,6 +5906,7 @@ static int SendTls13EndOfEarlyData(WOLFSSL* ssl)
#endif /* !NO_WOLFSSL_CLIENT */
#ifndef NO_WOLFSSL_SERVER
/* handle processing of TLS 1.3 end_of_early_data (5) */
/* Parse the TLS v1.3 EndOfEarlyData message that indicates that there will be
* no more early application data.
* The decryption key now changes to the pre-calculated handshake key.
@@ -7324,16 +7351,27 @@ int wolfSSL_accept_TLSv13(WOLFSSL* ssl)
}
#ifndef NO_CERTS
/* in case used set_accept_state after init */
if (!havePSK && !haveAnon &&
(!ssl->buffers.certificate ||
!ssl->buffers.certificate->buffer ||
!ssl->buffers.key ||
!ssl->buffers.key->buffer)) {
WOLFSSL_MSG("accept error: don't have server cert and key");
ssl->error = NO_PRIVATE_KEY;
WOLFSSL_ERROR(ssl->error);
return WOLFSSL_FATAL_ERROR;
/* allow no private key if using PK callbacks and CB is set */
if (!havePSK && !haveAnon) {
if (!ssl->buffers.certificate ||
!ssl->buffers.certificate->buffer) {
WOLFSSL_MSG("accept error: server cert required");
WOLFSSL_ERROR(ssl->error = NO_PRIVATE_KEY);
return WOLFSSL_FATAL_ERROR;
}
#ifdef HAVE_PK_CALLBACKS
if (wolfSSL_CTX_IsPrivatePkSet(ssl->ctx)) {
WOLFSSL_MSG("Using PK for server private key");
}
else
#endif
if (!ssl->buffers.key || !ssl->buffers.key->buffer) {
WOLFSSL_MSG("accept error: server key required");
WOLFSSL_ERROR(ssl->error = NO_PRIVATE_KEY);
return WOLFSSL_FATAL_ERROR;
}
}
#endif

View File

@@ -231,7 +231,7 @@ static int execute_test_case(int svr_argc, char** svr_argv,
}
#endif
/* Build Client Command */
/* Build Server Command */
if (addNoVerify) {
printf("repeating test with client cert request off\n");
if (svrArgs.argc >= MAX_ARGS)
@@ -261,6 +261,9 @@ static int execute_test_case(int svr_argc, char** svr_argv,
else
svr_argv[svrArgs.argc++] = forceDefCipherListFlag;
}
#ifdef TEST_PK_PRIVKEY
svr_argv[svrArgs.argc++] = (char*)"-P";
#endif
/* update server flags list */
commandLine[0] = '\0';
@@ -321,6 +324,9 @@ static int execute_test_case(int svr_argc, char** svr_argv,
else
cli_argv[cliArgs.argc++] = forceDefCipherListFlag;
}
#ifdef TEST_PK_PRIVKEY
cli_argv[cliArgs.argc++] = (char*)"-P";
#endif
commandLine[0] = '\0';
added = 0;

View File

@@ -5877,6 +5877,10 @@ int wc_ecc_size(ecc_key* key)
return key->dp->size;
}
int wc_ecc_sig_size_calc(int sz)
{
return (sz * 2) + SIG_HEADER_SZ + ECC_MAX_PAD_SZ;
}
/* worst case estimate, check actual return from wc_ecc_sign_hash for actual
value of signature size in octets */
@@ -5886,7 +5890,7 @@ int wc_ecc_sig_size(ecc_key* key)
if (sz <= 0)
return sz;
return (sz * 2) + SIG_HEADER_SZ + ECC_MAX_PAD_SZ;
return wc_ecc_sig_size_calc(sz);
}

View File

@@ -722,6 +722,7 @@ static int RsaPad_OAEP(const byte* input, word32 inputLen, byte* pkcsBlock,
#endif /* !WC_NO_RSA_OAEP */
#ifdef WC_RSA_PSS
/* 0x00 .. 0x00 0x01 | Salt | Gen Hash | 0xbc
* XOR MGF over all bytes down to end of Salt
* Gen Hash = HASH(8 * 0x00 | Message Hash | Salt)
@@ -774,7 +775,7 @@ static int RsaPad_PSS(const byte* input, word32 inputLen, byte* pkcsBlock,
h = pkcsBlock + pkcsBlockLen - 1 - hLen;
if ((ret = wc_Hash(hType, s, (word32)(m - s), h, hLen)) != 0)
return ret;
pkcsBlock[pkcsBlockLen - 1] = 0xbc;
pkcsBlock[pkcsBlockLen - 1] = RSA_PSS_PAD_TERM;
ret = RsaMGF(mgf, h, hLen, pkcsBlock, pkcsBlockLen - hLen - 1, heap);
if (ret != 0)
@@ -1028,8 +1029,8 @@ static int RsaUnPad_PSS(byte *pkcsBlock, unsigned int pkcsBlockLen,
if ((int)pkcsBlockLen - hLen - 1 < saltLen + 2)
return PSS_SALTLEN_E;
if (pkcsBlock[pkcsBlockLen - 1] != 0xbc) {
WOLFSSL_MSG("RsaUnPad_PSS: Padding Error 0xBC");
if (pkcsBlock[pkcsBlockLen - 1] != RSA_PSS_PAD_TERM) {
WOLFSSL_MSG("RsaUnPad_PSS: Padding Term Error");
return BAD_PADDING_E;
}
@@ -2139,7 +2140,7 @@ int wc_RsaPSS_Verify_ex(byte* in, word32 inLen, byte* out, word32 outLen,
* Salt length is equal to hash length.
*
* in Hash of the data that is being verified.
* inSz Length of hash.
* inSz Length of hash.
* sig Buffer holding PSS data.
* sigSz Size of PSS data.
* hashType Hash algorithm.
@@ -2156,7 +2157,7 @@ int wc_RsaPSS_CheckPadding(const byte* in, word32 inSz, byte* sig,
/* Checks the PSS data to ensure that the signature matches.
*
* in Hash of the data that is being verified.
* inSz Length of hash.
* inSz Length of hash.
* sig Buffer holding PSS data.
* sigSz Size of PSS data.
* hashType Hash algorithm.

View File

@@ -162,7 +162,7 @@ int wc_Rsa_unsigned_bin_size(void* bn)
#define MP_OKAY 0
#endif
/* extract the bn value to a unsigned byte array and return MP_OKAY on succes */
/* extract the bn value to a unsigned byte array and return MP_OKAY on success */
int wc_Rsa_to_unsigned_bin(void* bn, byte* in, int inLen)
{
if (ippsGetOctString_BN((Ipp8u*)in, inLen, bn) != ippStsNoErr) {

View File

@@ -1492,6 +1492,9 @@ WOLFSSL_LOCAL int CheckVersion(WOLFSSL *ssl, ProtocolVersion pv);
WOLFSSL_LOCAL void PickHashSigAlgo(WOLFSSL* ssl, const byte* hashSigAlgo,
word32 hashSigAlgoSz);
WOLFSSL_LOCAL int DecodePrivateKey(WOLFSSL *ssl, word16* length);
#ifdef HAVE_PK_CALLBACKS
WOLFSSL_LOCAL int GetPrivateKeySigSize(WOLFSSL* ssl);
#endif
WOLFSSL_LOCAL void FreeKeyExchange(WOLFSSL* ssl);
WOLFSSL_LOCAL int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx, word32 size);
WOLFSSL_LOCAL int MatchDomainName(const char* pattern, int len, const char* str);
@@ -3840,25 +3843,25 @@ WOLFSSL_LOCAL int SetTicket(WOLFSSL*, const byte*, word32);
#endif
WOLFSSL_LOCAL int VerifyRsaSign(WOLFSSL* ssl, byte* verifySig,
word32 sigSz, const byte* plain, word32 plainSz, int sigAlgo,
int hashAlgo, RsaKey* key, const byte* keyBuf, word32 keySz, void* ctx);
int hashAlgo, RsaKey* key, DerBuffer* keyBufInfo, void* ctx);
WOLFSSL_LOCAL int RsaSign(WOLFSSL* ssl, const byte* in, word32 inSz,
byte* out, word32* outSz, int sigAlgo, int hashAlgo, RsaKey* key,
const byte* keyBuf, word32 keySz, void* ctx);
DerBuffer* keyBufInfo, void* ctx);
WOLFSSL_LOCAL int RsaVerify(WOLFSSL* ssl, byte* in, word32 inSz,
byte** out, int sigAlgo, int hashAlgo, RsaKey* key,
const byte* keyBuf, word32 keySz, void* ctx);
buffer* keyBufInfo, void* ctx);
WOLFSSL_LOCAL int RsaDec(WOLFSSL* ssl, byte* in, word32 inSz, byte** out,
word32* outSz, RsaKey* key, const byte* keyBuf, word32 keySz, void* ctx);
word32* outSz, RsaKey* key, DerBuffer* keyBufInfo, void* ctx);
WOLFSSL_LOCAL int RsaEnc(WOLFSSL* ssl, const byte* in, word32 inSz, byte* out,
word32* outSz, RsaKey* key, const byte* keyBuf, word32 keySz, void* ctx);
word32* outSz, RsaKey* key, buffer* keyBufInfo, void* ctx);
#endif /* !NO_RSA */
#ifdef HAVE_ECC
WOLFSSL_LOCAL int EccSign(WOLFSSL* ssl, const byte* in, word32 inSz,
byte* out, word32* outSz, ecc_key* key, byte* keyBuf, word32 keySz,
byte* out, word32* outSz, ecc_key* key, DerBuffer* keyBufInfo,
void* ctx);
WOLFSSL_LOCAL int EccVerify(WOLFSSL* ssl, const byte* in, word32 inSz,
const byte* out, word32 outSz, ecc_key* key, byte* keyBuf, word32 keySz,
const byte* out, word32 outSz, ecc_key* key, buffer* keyBufInfo,
void* ctx);
WOLFSSL_LOCAL int EccSharedSecret(WOLFSSL* ssl, ecc_key* priv_key,
ecc_key* pub_key, byte* pubKeyDer, word32* pubKeySz, byte* out,
@@ -3866,11 +3869,11 @@ WOLFSSL_LOCAL int SetTicket(WOLFSSL*, const byte*, word32);
#endif /* HAVE_ECC */
#ifdef HAVE_ED25519
WOLFSSL_LOCAL int Ed25519Sign(WOLFSSL* ssl, const byte* in, word32 inSz,
byte* out, word32* outSz, ed25519_key* key, byte* keyBuf,
word32 keySz, void* ctx);
byte* out, word32* outSz, ed25519_key* key, DerBuffer* keyBufInfo,
void* ctx);
WOLFSSL_LOCAL int Ed25519Verify(WOLFSSL* ssl, const byte* in,
word32 inSz, const byte* msg, word32 msgSz, ed25519_key* key,
byte* keyBuf, word32 keySz, void* ctx);
buffer* keyBufInfo, void* ctx);
#endif /* HAVE_ED25519 */

View File

@@ -2864,6 +2864,10 @@ WOLFSSL_API void wolfSSL_EC_POINT_dump(const char *msg, const WOLFSSL_EC_POINT *
#endif /* OPENSSL_EXTRA */
#ifdef HAVE_PK_CALLBACKS
WOLFSSL_API int wolfSSL_CTX_IsPrivatePkSet(WOLFSSL_CTX* ctx);
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif

View File

@@ -1305,6 +1305,37 @@ static INLINE void OCSPRespFreeCb(void* ioCtx, unsigned char* response)
if (buff)
free(buff);
}
#ifdef TEST_PK_PRIVKEY
static INLINE int load_key_file(const char* fname, byte** derBuf, word32* derLen)
{
int ret;
byte* buf = NULL;
size_t bufLen;
ret = load_file(fname, &buf, &bufLen);
if (ret != 0)
return ret;
*derBuf = (byte*)malloc(bufLen);
if (*derBuf == NULL) {
free(buf);
return MEMORY_E;
}
ret = wolfSSL_KeyPemToDer(buf, (word32)bufLen, *derBuf, (word32)bufLen, NULL);
if (ret < 0) {
free(buf);
free(*derBuf);
return ret;
}
*derLen = ret;
free(buf);
return 0;
}
#endif /* TEST_PK_PRIVKEY */
#endif /* !NO_FILESYSTEM || (NO_FILESYSTEM && FORCE_BUFFER_TEST) */
#endif /* !NO_CERTS */
@@ -1824,18 +1855,30 @@ static INLINE int wolfSSL_PrintStats(WOLFSSL_MEM_STATS* stats)
#ifdef HAVE_PK_CALLBACKS
typedef struct PkCbInfo {
const char* ourKey;
} PkCbInfo;
#ifdef HAVE_ECC
static INLINE int myEccSign(WOLFSSL* ssl, const byte* in, word32 inSz,
byte* out, word32* outSz, const byte* key, word32 keySz, void* ctx)
{
WC_RNG rng;
int ret;
word32 idx = 0;
ecc_key myKey;
int ret;
WC_RNG rng;
word32 idx = 0;
ecc_key myKey;
byte* keyBuf = (byte*)key;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
(void)ssl;
(void)ctx;
(void)cbInfo;
#ifdef TEST_PK_PRIVKEY
ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
if (ret != 0)
return ret;
#endif
ret = wc_InitRng(&rng);
if (ret != 0)
@@ -1843,13 +1886,17 @@ static INLINE int myEccSign(WOLFSSL* ssl, const byte* in, word32 inSz,
ret = wc_ecc_init(&myKey);
if (ret == 0) {
ret = wc_EccPrivateKeyDecode(key, &idx, &myKey, keySz);
ret = wc_EccPrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
if (ret == 0)
ret = wc_ecc_sign_hash(in, inSz, out, outSz, &rng, &myKey);
wc_ecc_free(&myKey);
}
wc_FreeRng(&rng);
#ifdef TEST_PK_PRIVKEY
free(keyBuf);
#endif
return ret;
}
@@ -1858,15 +1905,17 @@ static INLINE int myEccVerify(WOLFSSL* ssl, const byte* sig, word32 sigSz,
const byte* hash, word32 hashSz, const byte* key, word32 keySz,
int* result, void* ctx)
{
int ret;
ecc_key myKey;
int ret;
word32 idx = 0;
ecc_key myKey;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
(void)ssl;
(void)ctx;
(void)cbInfo;
ret = wc_ecc_init(&myKey);
if (ret == 0) {
ret = wc_ecc_import_x963(key, keySz, &myKey);
ret = wc_EccPublicKeyDecode(key, &idx, &myKey, keySz);
if (ret == 0)
ret = wc_ecc_verify_hash(sig, sigSz, hash, hashSz, result, &myKey);
wc_ecc_free(&myKey);
@@ -1880,13 +1929,14 @@ static INLINE int myEccSharedSecret(WOLFSSL* ssl, ecc_key* otherKey,
unsigned char* out, unsigned int* outlen,
int side, void* ctx)
{
int ret;
ecc_key* privKey = NULL;
ecc_key* pubKey = NULL;
ecc_key tmpKey;
int ret;
ecc_key* privKey = NULL;
ecc_key* pubKey = NULL;
ecc_key tmpKey;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
(void)ssl;
(void)ctx;
(void)cbInfo;
ret = wc_ecc_init(&tmpKey);
if (ret != 0) {
@@ -1949,18 +1999,30 @@ static INLINE int myEd25519Sign(WOLFSSL* ssl, const byte* in, word32 inSz,
int ret;
word32 idx = 0;
ed25519_key myKey;
byte* keyBuf = (byte*)key;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
(void)ssl;
(void)ctx;
(void)cbInfo;
#ifdef TEST_PK_PRIVKEY
ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
if (ret != 0)
return ret;
#endif
ret = wc_ed25519_init(&myKey);
if (ret == 0) {
ret = wc_Ed25519PrivateKeyDecode(key, &idx, &myKey, keySz);
ret = wc_Ed25519PrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
if (ret == 0)
ret = wc_ed25519_sign_msg(in, inSz, out, outSz, &myKey);
wc_ed25519_free(&myKey);
}
#ifdef TEST_PK_PRIVKEY
free(keyBuf);
#endif
return ret;
}
@@ -1971,9 +2033,10 @@ static INLINE int myEd25519Verify(WOLFSSL* ssl, const byte* sig, word32 sigSz,
{
int ret;
ed25519_key myKey;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
(void)ssl;
(void)ctx;
(void)cbInfo;
ret = wc_ed25519_init(&myKey);
if (ret == 0) {
@@ -1998,9 +2061,10 @@ static INLINE int myX25519SharedSecret(WOLFSSL* ssl, curve25519_key* otherKey,
curve25519_key* privKey = NULL;
curve25519_key* pubKey = NULL;
curve25519_key tmpKey;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
(void)ssl;
(void)ctx;
(void)cbInfo;
ret = wc_curve25519_init(&tmpKey);
if (ret != 0) {
@@ -2058,8 +2122,11 @@ static INLINE int myDhCallback(WOLFSSL* ssl, struct DhKey* key,
unsigned char* out, unsigned int* outlen,
void* ctx)
{
(void)ctx;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
(void)ssl;
(void)cbInfo;
/* return 0 on success */
return wc_DhAgree(key, out, outlen, priv, privSz, pubKeyDer, pubKeySz);
};
@@ -2075,9 +2142,17 @@ static INLINE int myRsaSign(WOLFSSL* ssl, const byte* in, word32 inSz,
int ret;
word32 idx = 0;
RsaKey myKey;
byte* keyBuf = (byte*)key;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
(void)ssl;
(void)ctx;
(void)cbInfo;
#ifdef TEST_PK_PRIVKEY
ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
if (ret != 0)
return ret;
#endif
ret = wc_InitRng(&rng);
if (ret != 0)
@@ -2085,7 +2160,7 @@ static INLINE int myRsaSign(WOLFSSL* ssl, const byte* in, word32 inSz,
ret = wc_InitRsaKey(&myKey, NULL);
if (ret == 0) {
ret = wc_RsaPrivateKeyDecode(key, &idx, &myKey, keySz);
ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
if (ret == 0)
ret = wc_RsaSSL_Sign(in, inSz, out, *outSz, &myKey, &rng);
if (ret > 0) { /* save and convert to 0 success */
@@ -2096,6 +2171,10 @@ static INLINE int myRsaSign(WOLFSSL* ssl, const byte* in, word32 inSz,
}
wc_FreeRng(&rng);
#ifdef TEST_PK_PRIVKEY
free(keyBuf);
#endif
return ret;
}
@@ -2106,9 +2185,10 @@ static INLINE int myRsaVerify(WOLFSSL* ssl, byte* sig, word32 sigSz,
int ret;
word32 idx = 0;
RsaKey myKey;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
(void)ssl;
(void)ctx;
(void)cbInfo;
ret = wc_InitRsaKey(&myKey, NULL);
if (ret == 0) {
@@ -2127,17 +2207,28 @@ static INLINE int myRsaSignCheck(WOLFSSL* ssl, byte* sig, word32 sigSz,
int ret;
word32 idx = 0;
RsaKey myKey;
byte* keyBuf = (byte*)key;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
(void)ssl;
(void)ctx;
(void)cbInfo;
#ifdef TEST_PK_PRIVKEY
ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
if (ret != 0)
return ret;
#endif
ret = wc_InitRsaKey(&myKey, NULL);
if (ret == 0) {
ret = wc_RsaPrivateKeyDecode(key, &idx, &myKey, keySz);
ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
if (ret == 0)
ret = wc_RsaSSL_VerifyInline(sig, sigSz, out, &myKey);
wc_FreeRsaKey(&myKey);
}
#ifdef TEST_PK_PRIVKEY
free(keyBuf);
#endif
return ret;
}
@@ -2152,9 +2243,17 @@ static INLINE int myRsaPssSign(WOLFSSL* ssl, const byte* in, word32 inSz,
int ret;
word32 idx = 0;
RsaKey myKey;
byte* keyBuf = (byte*)key;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
(void)ssl;
(void)ctx;
(void)cbInfo;
#ifdef TEST_PK_PRIVKEY
ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
if (ret != 0)
return ret;
#endif
switch (hash) {
#ifndef NO_SHA256
@@ -2180,7 +2279,7 @@ static INLINE int myRsaPssSign(WOLFSSL* ssl, const byte* in, word32 inSz,
ret = wc_InitRsaKey(&myKey, NULL);
if (ret == 0) {
ret = wc_RsaPrivateKeyDecode(key, &idx, &myKey, keySz);
ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
if (ret == 0) {
ret = wc_RsaPSS_Sign(in, inSz, out, *outSz, hashType, mgf, &myKey,
&rng);
@@ -2193,6 +2292,10 @@ static INLINE int myRsaPssSign(WOLFSSL* ssl, const byte* in, word32 inSz,
}
wc_FreeRng(&rng);
#ifdef TEST_PK_PRIVKEY
free(keyBuf);
#endif
return ret;
}
@@ -2200,13 +2303,14 @@ static INLINE int myRsaPssSign(WOLFSSL* ssl, const byte* in, word32 inSz,
static INLINE int myRsaPssVerify(WOLFSSL* ssl, byte* sig, word32 sigSz,
byte** out, int hash, int mgf, const byte* key, word32 keySz, void* ctx)
{
int ret;
word32 idx = 0;
RsaKey myKey;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
enum wc_HashType hashType = WC_HASH_TYPE_NONE;
int ret;
word32 idx = 0;
RsaKey myKey;
(void)ssl;
(void)ctx;
(void)cbInfo;
switch (hash) {
#ifndef NO_SHA256
@@ -2242,13 +2346,21 @@ static INLINE int myRsaPssVerify(WOLFSSL* ssl, byte* sig, word32 sigSz,
static INLINE int myRsaPssSignCheck(WOLFSSL* ssl, byte* sig, word32 sigSz,
byte** out, int hash, int mgf, const byte* key, word32 keySz, void* ctx)
{
int ret;
word32 idx = 0;
RsaKey myKey;
byte* keyBuf = (byte*)key;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
enum wc_HashType hashType = WC_HASH_TYPE_NONE;
int ret;
word32 idx = 0;
RsaKey myKey;
(void)ssl;
(void)ctx;
(void)cbInfo;
#ifdef TEST_PK_PRIVKEY
ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
if (ret != 0)
return ret;
#endif
switch (hash) {
#ifndef NO_SHA256
@@ -2270,7 +2382,7 @@ static INLINE int myRsaPssSignCheck(WOLFSSL* ssl, byte* sig, word32 sigSz,
ret = wc_InitRsaKey(&myKey, NULL);
if (ret == 0) {
ret = wc_RsaPrivateKeyDecode(key, &idx, &myKey, keySz);
ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
if (ret == 0) {
ret = wc_RsaPSS_VerifyInline(sig, sigSz, out, hashType, mgf,
&myKey);
@@ -2278,6 +2390,10 @@ static INLINE int myRsaPssSignCheck(WOLFSSL* ssl, byte* sig, word32 sigSz,
wc_FreeRsaKey(&myKey);
}
#ifdef TEST_PK_PRIVKEY
free(keyBuf);
#endif
return ret;
}
#endif
@@ -2287,13 +2403,14 @@ static INLINE int myRsaEnc(WOLFSSL* ssl, const byte* in, word32 inSz,
byte* out, word32* outSz, const byte* key,
word32 keySz, void* ctx)
{
int ret;
word32 idx = 0;
RsaKey myKey;
WC_RNG rng;
int ret;
word32 idx = 0;
RsaKey myKey;
WC_RNG rng;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
(void)ssl;
(void)ctx;
(void)cbInfo;
ret = wc_InitRng(&rng);
if (ret != 0)
@@ -2320,16 +2437,24 @@ static INLINE int myRsaDec(WOLFSSL* ssl, byte* in, word32 inSz,
byte** out,
const byte* key, word32 keySz, void* ctx)
{
int ret;
word32 idx = 0;
RsaKey myKey;
int ret;
word32 idx = 0;
RsaKey myKey;
byte* keyBuf = (byte*)key;
PkCbInfo* cbInfo = (PkCbInfo*)ctx;
(void)ssl;
(void)ctx;
(void)cbInfo;
#ifdef TEST_PK_PRIVKEY
ret = load_key_file(cbInfo->ourKey, &keyBuf, &keySz);
if (ret != 0)
return ret;
#endif
ret = wc_InitRsaKey(&myKey, NULL);
if (ret == 0) {
ret = wc_RsaPrivateKeyDecode(key, &idx, &myKey, keySz);
ret = wc_RsaPrivateKeyDecode(keyBuf, &idx, &myKey, keySz);
if (ret == 0) {
#ifdef WC_RSA_BLINDING
ret = wc_RsaSetRNG(&myKey, wolfSSL_GetRNG(ssl));
@@ -2343,15 +2468,18 @@ static INLINE int myRsaDec(WOLFSSL* ssl, byte* in, word32 inSz,
wc_FreeRsaKey(&myKey);
}
#ifdef TEST_PK_PRIVKEY
free(keyBuf);
#endif
return ret;
}
#endif /* NO_RSA */
static INLINE void SetupPkCallbacks(WOLFSSL_CTX* ctx, WOLFSSL* ssl)
static INLINE void SetupPkCallbacks(WOLFSSL_CTX* ctx)
{
(void)ctx;
(void)ssl;
#ifdef HAVE_ECC
wolfSSL_CTX_SetEccSignCb(ctx, myEccSign);
@@ -2382,8 +2510,36 @@ static INLINE void SetupPkCallbacks(WOLFSSL_CTX* ctx, WOLFSSL* ssl)
#endif /* NO_RSA */
}
#endif /* HAVE_PK_CALLBACKS */
static INLINE void SetupPkCallbackContexts(WOLFSSL* ssl, void* myCtx)
{
#ifdef HAVE_ECC
wolfSSL_SetEccSignCtx(ssl, myCtx);
wolfSSL_SetEccVerifyCtx(ssl, myCtx);
wolfSSL_SetEccSharedSecretCtx(ssl, myCtx);
#endif /* HAVE_ECC */
#ifndef NO_DH
wolfSSL_SetDhAgreeCtx(ssl, myCtx);
#endif
#ifdef HAVE_ED25519
wolfSSL_SetEd25519SignCtx(ssl, myCtx);
wolfSSL_SetEd25519VerifyCtx(ssl, myCtx);
#endif
#ifdef HAVE_CURVE25519
wolfSSL_SetX25519SharedSecretCtx(ssl, myCtx);
#endif
#ifndef NO_RSA
wolfSSL_SetRsaSignCtx(ssl, myCtx);
wolfSSL_SetRsaVerifyCtx(ssl, myCtx);
#ifdef WC_RSA_PSS
wolfSSL_SetRsaPssSignCtx(ssl, myCtx);
wolfSSL_SetRsaPssVerifyCtx(ssl, myCtx);
#endif
wolfSSL_SetRsaEncCtx(ssl, myCtx);
wolfSSL_SetRsaDecCtx(ssl, myCtx);
#endif /* NO_RSA */
}
#endif /* HAVE_PK_CALLBACKS */

View File

@@ -541,6 +541,8 @@ int wc_ecc_import_point_der(byte* in, word32 inLen, const int curve_idx,
WOLFSSL_API
int wc_ecc_size(ecc_key* key);
WOLFSSL_API
int wc_ecc_sig_size_calc(int sz);
WOLFSSL_API
int wc_ecc_sig_size(ecc_key* key);
WOLFSSL_API

View File

@@ -103,8 +103,11 @@ enum {
#ifdef OPENSSL_EXTRA
RSA_PKCS1_PADDING_SIZE = 11,
RSA_PKCS1_OAEP_PADDING_SIZE = 42 /* (2 * hashlen(SHA-1)) + 2 */
#endif
RSA_PKCS1_OAEP_PADDING_SIZE = 42, /* (2 * hashlen(SHA-1)) + 2 */
#endif
#ifdef WC_RSA_PSS
RSA_PSS_PAD_TERM = 0xBC,
#endif
};
/* RSA */