Fixed Hmac types, fixed wolfSSL version

pull/2/head
Daniele Lacamera 2019-03-27 18:09:26 +01:00
parent a54f2b66f5
commit 94c39551d4
4 changed files with 14 additions and 6 deletions

View File

@ -90,6 +90,7 @@ ffi.cdef(
typedef struct { ...; } Hmac;
int wc_HmacInit(Hmac* hmac, void* heap, int devId);
int wc_HmacSetKey(Hmac*, int, const byte*, word32);
int wc_HmacUpdate(Hmac*, const byte*, word32);
int wc_HmacFinal(Hmac*, byte*);

View File

@ -127,7 +127,10 @@ def make_flags(prefix):
# hashes and MACs
flags.append("--enable-sha")
flags.append("--enable-sha256")
flags.append("--enable-sha384")
flags.append("--enable-sha512")
flags.append("--enable-hkdf")
flags.append("--disable-md5")
flags.append("--disable-sha224")

View File

@ -191,10 +191,10 @@ class Sha512(_Hash):
# Hmac types
_TYPE_SHA = 1
_TYPE_SHA256 = 2
_TYPE_SHA384 = 5
_TYPE_SHA512 = 4
_TYPE_SHA = 4
_TYPE_SHA256 = 6
_TYPE_SHA384 = 7
_TYPE_SHA512 = 8
_HMAC_TYPES = [_TYPE_SHA, _TYPE_SHA256, _TYPE_SHA384, _TYPE_SHA512]
@ -230,7 +230,12 @@ class _Hmac(_Hash):
return cls(key, string)
def _init(self, hmac, key):
return _lib.wc_HmacSetKey(self._native_object, hmac, key, len(key))
if _lib.wc_HmacInit(self._native_object, _ffi.NULL, -2) != 0:
raise WolfCryptError("wc_HmacInit error")
ret = _lib.wc_HmacSetKey(self._native_object, hmac, key, len(key))
if ret < 0:
raise WolfCryptError("wc_HmacSetKey returned %d" % ret)
return ret
def _update(self, data):
return _lib.wc_HmacUpdate(self._native_object, data, len(data))

View File

@ -80,7 +80,6 @@ def hash_cls(request):
def hash_new(cls, data=None):
if cls in [Sha, Sha256, Sha384, Sha512]:
return cls(data)
return cls("python", data)