Ungate constants and gate tests

pull/36/head
Andrew Hutchings 2022-02-09 14:18:23 +00:00
parent 3327d9ae39
commit e58d81533c
2 changed files with 41 additions and 40 deletions

View File

@ -432,21 +432,22 @@ if _lib.RSA_ENABLED:
assert 1024 / 8 == len(signature) == rsa_private.output_size
assert plaintext == rsa_private.verify(signature)
def test_rsa_pss_sign_verify(rsa_private, rsa_public):
plaintext = t2b("Everyone gets Friday off yippee.")
if _lib.RSA_PSS_ENABLED:
def test_rsa_pss_sign_verify(rsa_private, rsa_public):
plaintext = t2b("Everyone gets Friday off yippee.")
# normal usage, sign with private, verify with public
signature = rsa_private.sign_pss(plaintext, HASH_TYPE_SHA256, MGF1SHA256)
# normal usage, sign with private, verify with public
signature = rsa_private.sign_pss(plaintext, HASH_TYPE_SHA256, MGF1SHA256)
assert 1024 / 8 == len(signature) == rsa_private.output_size
assert 0 == rsa_public.verify_pss(plaintext, signature, HASH_TYPE_SHA256, MGF1SHA256)
assert 1024 / 8 == len(signature) == rsa_private.output_size
assert 0 == rsa_public.verify_pss(plaintext, signature, HASH_TYPE_SHA256, MGF1SHA256)
# private object holds both private and public info, so it can also verify
# using the known public key.
signature = rsa_private.sign_pss(plaintext, HASH_TYPE_SHA256, MGF1SHA256)
# private object holds both private and public info, so it can also verify
# using the known public key.
signature = rsa_private.sign_pss(plaintext, HASH_TYPE_SHA256, MGF1SHA256)
assert 1024 / 8 == len(signature) == rsa_private.output_size
assert 0 == rsa_private.verify_pss(plaintext, signature, HASH_TYPE_SHA256, MGF1SHA256)
assert 1024 / 8 == len(signature) == rsa_private.output_size
assert 0 == rsa_private.verify_pss(plaintext, signature, HASH_TYPE_SHA256, MGF1SHA256)
def test_rsa_sign_verify_pem(rsa_private_pem, rsa_public_pem):
plaintext = t2b("Everyone gets Friday off.")

View File

@ -372,6 +372,34 @@ if HMAC_ENABLED:
if RSA_ENABLED:
_cdef += """
static const int WC_RSA_PKCSV15_PAD;
static const int WC_RSA_OAEP_PAD;
static const int WC_RSA_PSS_PAD;
static const int WC_RSA_NO_PAD;
static const int WC_MGF1NONE;
static const int WC_MGF1SHA1;
static const int WC_MGF1SHA224;
static const int WC_MGF1SHA256;
static const int WC_MGF1SHA384;
static const int WC_MGF1SHA512;
static const int WC_HASH_TYPE_NONE;
static const int WC_HASH_TYPE_MD2;
static const int WC_HASH_TYPE_MD4;
static const int WC_HASH_TYPE_MD5;
static const int WC_HASH_TYPE_SHA;
static const int WC_HASH_TYPE_SHA224;
static const int WC_HASH_TYPE_SHA256;
static const int WC_HASH_TYPE_SHA384;
static const int WC_HASH_TYPE_SHA512;
static const int WC_HASH_TYPE_MD5_SHA;
static const int WC_HASH_TYPE_SHA3_224;
static const int WC_HASH_TYPE_SHA3_256;
static const int WC_HASH_TYPE_SHA3_384;
static const int WC_HASH_TYPE_SHA3_512;
static const int WC_HASH_TYPE_BLAKE2B;
static const int WC_HASH_TYPE_BLAKE2S;
typedef struct {...; } RsaKey;
int wc_InitRsaKey(RsaKey* key, void*);
@ -392,37 +420,9 @@ if RSA_ENABLED:
byte* out, word32 outLen, RsaKey* key, int type,
enum wc_HashType hash, int mgf, byte* label, word32 labelSz);
"""
if RSA_PSS_ENABLED:
_cdef += """
static const int WC_RSA_PKCSV15_PAD;
static const int WC_RSA_OAEP_PAD;
static const int WC_RSA_PSS_PAD;
static const int WC_RSA_NO_PAD;
static const int WC_MGF1NONE;
static const int WC_MGF1SHA1;
static const int WC_MGF1SHA224;
static const int WC_MGF1SHA256;
static const int WC_MGF1SHA384;
static const int WC_MGF1SHA512;
static const int WC_HASH_TYPE_NONE;
static const int WC_HASH_TYPE_MD2;
static const int WC_HASH_TYPE_MD4;
static const int WC_HASH_TYPE_MD5;
static const int WC_HASH_TYPE_SHA;
static const int WC_HASH_TYPE_SHA224;
static const int WC_HASH_TYPE_SHA256;
static const int WC_HASH_TYPE_SHA384;
static const int WC_HASH_TYPE_SHA512;
static const int WC_HASH_TYPE_MD5_SHA;
static const int WC_HASH_TYPE_SHA3_224;
static const int WC_HASH_TYPE_SHA3_256;
static const int WC_HASH_TYPE_SHA3_384;
static const int WC_HASH_TYPE_SHA3_512;
static const int WC_HASH_TYPE_BLAKE2B;
static const int WC_HASH_TYPE_BLAKE2S;
int wc_RsaPSS_Sign(const byte* in, word32 inLen, byte* out, word32 outLen,
enum wc_HashType hash, int mgf, RsaKey* key, WC_RNG* rng);
int wc_RsaPSS_Verify(byte* in, word32 inLen, byte* out, word32 outLen,