Merge pull request #29 from haydenroche5/fipsv5
Call wc_SetSeed_Cb in __init__.py if needed.pull/30/head
commit
d2668d507a
|
@ -45,3 +45,18 @@ __all__ = [
|
||||||
"__author__", "__email__", "__license__", "__copyright__",
|
"__author__", "__email__", "__license__", "__copyright__",
|
||||||
"ciphers", "hashes", "random", "pwdbased"
|
"ciphers", "hashes", "random", "pwdbased"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
try:
|
||||||
|
from wolfcrypt._ffi import ffi as _ffi
|
||||||
|
from wolfcrypt._ffi import lib as _lib
|
||||||
|
except ImportError:
|
||||||
|
# FFI not built. Not running initialization code.
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
from wolfcrypt.exceptions import WolfCryptError
|
||||||
|
|
||||||
|
if hasattr(_lib, 'WC_RNG_SEED_CB_ENABLED'):
|
||||||
|
if _lib.WC_RNG_SEED_CB_ENABLED:
|
||||||
|
ret = _lib.wc_SetSeed_Cb(_ffi.addressof(_lib, "wc_GenerateSeed"))
|
||||||
|
if ret < 0:
|
||||||
|
raise WolfCryptError("wc_SetSeed_Cb failed (%d)" % ret)
|
||||||
|
|
|
@ -70,6 +70,7 @@ FIPS_ENABLED = 0
|
||||||
FIPS_VERSION = 0
|
FIPS_VERSION = 0
|
||||||
ERROR_STRINGS_ENABLED = 1
|
ERROR_STRINGS_ENABLED = 1
|
||||||
ASN_ENABLED = 1
|
ASN_ENABLED = 1
|
||||||
|
WC_RNG_SEED_CB_ENABLED = 0
|
||||||
|
|
||||||
# detect native features based on options.h defines
|
# detect native features based on options.h defines
|
||||||
if featureDetection:
|
if featureDetection:
|
||||||
|
@ -93,6 +94,7 @@ if featureDetection:
|
||||||
PWDBASED_ENABLED = 0 if '#define NO_PWDBASED' in optionsHeaderStr else 1
|
PWDBASED_ENABLED = 0 if '#define NO_PWDBASED' in optionsHeaderStr else 1
|
||||||
ERROR_STRINGS_ENABLED = 0 if '#define NO_ERROR_STRINGS' in optionsHeaderStr else 1
|
ERROR_STRINGS_ENABLED = 0 if '#define NO_ERROR_STRINGS' in optionsHeaderStr else 1
|
||||||
ASN_ENABLED = 0 if '#define NO_ASN' in optionsHeaderStr else 1
|
ASN_ENABLED = 0 if '#define NO_ASN' in optionsHeaderStr else 1
|
||||||
|
WC_RNG_SEED_CB_ENABLED = 1 if '#define WC_RNG_SEED_CB' in optionsHeaderStr else 0
|
||||||
|
|
||||||
if '#define HAVE_FIPS' in optionsHeaderStr:
|
if '#define HAVE_FIPS' in optionsHeaderStr:
|
||||||
FIPS_ENABLED = 1
|
FIPS_ENABLED = 1
|
||||||
|
@ -156,6 +158,7 @@ ffibuilder.set_source(
|
||||||
int FIPS_ENABLED = """ + str(FIPS_ENABLED) + """;
|
int FIPS_ENABLED = """ + str(FIPS_ENABLED) + """;
|
||||||
int FIPS_VERSION = """ + str(FIPS_VERSION) + """;
|
int FIPS_VERSION = """ + str(FIPS_VERSION) + """;
|
||||||
int ASN_ENABLED = """ + str(ASN_ENABLED) + """;
|
int ASN_ENABLED = """ + str(ASN_ENABLED) + """;
|
||||||
|
int WC_RNG_SEED_CB_ENABLED = """ + str(WC_RNG_SEED_CB_ENABLED) + """;
|
||||||
""",
|
""",
|
||||||
include_dirs=[wolfssl_inc_path()],
|
include_dirs=[wolfssl_inc_path()],
|
||||||
library_dirs=[wolfssl_lib_path()],
|
library_dirs=[wolfssl_lib_path()],
|
||||||
|
@ -184,15 +187,19 @@ _cdef = """
|
||||||
extern int FIPS_ENABLED;
|
extern int FIPS_ENABLED;
|
||||||
extern int FIPS_VERSION;
|
extern int FIPS_VERSION;
|
||||||
extern int ASN_ENABLED;
|
extern int ASN_ENABLED;
|
||||||
|
extern int WC_RNG_SEED_CB_ENABLED;
|
||||||
|
|
||||||
typedef unsigned char byte;
|
typedef unsigned char byte;
|
||||||
typedef unsigned int word32;
|
typedef unsigned int word32;
|
||||||
|
|
||||||
typedef struct { ...; } WC_RNG;
|
typedef struct { ...; } WC_RNG;
|
||||||
|
typedef struct { ...; } OS_Seed;
|
||||||
|
|
||||||
int wc_InitRng(WC_RNG*);
|
int wc_InitRng(WC_RNG*);
|
||||||
int wc_RNG_GenerateBlock(WC_RNG*, byte*, word32);
|
int wc_RNG_GenerateBlock(WC_RNG*, byte*, word32);
|
||||||
int wc_RNG_GenerateByte(WC_RNG*, byte*);
|
int wc_RNG_GenerateByte(WC_RNG*, byte*);
|
||||||
int wc_FreeRng(WC_RNG*);
|
int wc_FreeRng(WC_RNG*);
|
||||||
|
int wc_GenerateSeed(OS_Seed* os, byte* seed, word32 sz);
|
||||||
|
|
||||||
int wc_GetPkcs8TraditionalOffset(byte* input, word32* inOutIdx, word32 sz);
|
int wc_GetPkcs8TraditionalOffset(byte* input, word32* inOutIdx, word32 sz);
|
||||||
"""
|
"""
|
||||||
|
@ -485,6 +492,13 @@ if ASN_ENABLED:
|
||||||
int hashOID);
|
int hashOID);
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if WC_RNG_SEED_CB_ENABLED:
|
||||||
|
_cdef += """
|
||||||
|
typedef int (*wc_RngSeed_Cb)(OS_Seed* os, byte* seed, word32 sz);
|
||||||
|
|
||||||
|
int wc_SetSeed_Cb(wc_RngSeed_Cb cb);
|
||||||
|
"""
|
||||||
|
|
||||||
ffibuilder.cdef(_cdef)
|
ffibuilder.cdef(_cdef)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue