Skip to content

Commit 1f71641

Browse files
committed
fixes for node v13
1 parent 0db6331 commit 1f71641

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/aes.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ static bool is_valid_key_len(size_t key_len)
1414
}
1515

1616
static bool are_valid_args(const unsigned char *key, size_t key_len,
17-
const unsigned char *bytes, uint32_t flags)
17+
const unsigned char *bytes, size_t bytes_len, uint32_t flags)
1818
{
19-
return key && is_valid_key_len(key_len) && bytes &&
19+
return key && is_valid_key_len(key_len) &&
20+
(bytes != NULL || (bytes == NULL && bytes_len == 0 && (flags & AES_FLAG_ENCRYPT))) &&
2021
(flags & ALL_OPS) != ALL_OPS;
2122
}
2223

@@ -77,7 +78,7 @@ int wally_aes(const unsigned char *key, size_t key_len,
7778
{
7879
AES256_ctx ctx;
7980

80-
if (!are_valid_args(key, key_len, bytes, flags) ||
81+
if (!are_valid_args(key, key_len, bytes, bytes_len, flags) ||
8182
len % AES_BLOCK_LEN || !bytes_len || bytes_len % AES_BLOCK_LEN ||
8283
flags & ~ALL_OPS || !bytes_out || !len)
8384
return WALLY_EINVAL;
@@ -106,7 +107,7 @@ int wally_aes_cbc(const unsigned char *key, size_t key_len,
106107
if (written)
107108
*written = 0;
108109

109-
if (!are_valid_args(key, key_len, bytes, flags) ||
110+
if (!are_valid_args(key, key_len, bytes, bytes_len, flags) ||
110111
((flags & AES_FLAG_ENCRYPT) && (len % AES_BLOCK_LEN)) ||
111112
((flags & AES_FLAG_DECRYPT) && (bytes_len % AES_BLOCK_LEN)) ||
112113
!iv || iv_len != AES_BLOCK_LEN || flags & ~ALL_OPS || !written)

src/internal.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int wally_sha256(const unsigned char *bytes, size_t bytes_len,
7575
struct sha256 sha;
7676
bool aligned = alignment_ok(bytes_out, sizeof(sha.u.u32));
7777

78-
if (!bytes || !bytes_out || len != SHA256_LEN)
78+
if ((!bytes && bytes_len != 0) || !bytes_out || len != SHA256_LEN)
7979
return WALLY_EINVAL;
8080

8181
sha256(aligned ? (struct sha256 *)bytes_out : &sha, bytes, bytes_len);
@@ -102,7 +102,7 @@ int wally_sha256_midstate(const unsigned char *bytes, size_t bytes_len,
102102
struct sha256_ctx ctx;
103103
bool aligned = alignment_ok(bytes_out, sizeof(sha.u.u32));
104104

105-
if (!bytes || !bytes_out || len != SHA256_LEN)
105+
if ((!bytes && bytes_len != 0) || !bytes_out || len != SHA256_LEN)
106106
return WALLY_EINVAL;
107107

108108
sha256_init(&ctx);
@@ -123,7 +123,7 @@ int wally_sha256d(const unsigned char *bytes, size_t bytes_len,
123123
struct sha256 sha_1, sha_2;
124124
bool aligned = alignment_ok(bytes_out, sizeof(sha_1.u.u32));
125125

126-
if (!bytes || !bytes_out || len != SHA256_LEN)
126+
if ((!bytes && bytes_len != 0) || !bytes_out || len != SHA256_LEN)
127127
return WALLY_EINVAL;
128128

129129
sha256(&sha_1, bytes, bytes_len);
@@ -142,7 +142,7 @@ int wally_sha512(const unsigned char *bytes, size_t bytes_len,
142142
struct sha512 sha;
143143
bool aligned = alignment_ok(bytes_out, sizeof(sha.u.u64));
144144

145-
if (!bytes || !bytes_out || len != SHA512_LEN)
145+
if ((!bytes && bytes_len != 0) || !bytes_out || len != SHA512_LEN)
146146
return WALLY_EINVAL;
147147

148148
sha512(aligned ? (struct sha512 *)bytes_out : &sha, bytes, bytes_len);
@@ -160,7 +160,7 @@ int wally_hash160(const unsigned char *bytes, size_t bytes_len,
160160
struct ripemd160 ripemd;
161161
bool aligned = alignment_ok(bytes_out, sizeof(ripemd.u.u32));
162162

163-
if (!bytes || !bytes_out || len != HASH160_LEN)
163+
if ((!bytes && bytes_len != 0) || !bytes_out || len != HASH160_LEN)
164164
return WALLY_EINVAL;
165165

166166
BUILD_ASSERT(sizeof(ripemd) == HASH160_LEN);

src/swig_python/contrib/sha.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def test_wrong_types(self):
5050
# Python3 raises TypeError
5151
self._test_wrong_types_py3()
5252

53+
5354
def test_pass_none(self):
54-
for shaX in [sha256, sha256d, sha512]:
55-
with self.assertRaises(ValueError) as cm:
56-
shaX(None)
57-
self.assertEqual(str(cm.exception), "Invalid argument")
55+
self.assertEquals(b2h(sha256(None)), "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
56+
self.assertEquals(b2h(sha256d(None)), "5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456")
57+
self.assertEquals(b2h(sha512(None)), "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e")
5858

5959

6060
if __name__ == '__main__':

0 commit comments

Comments
 (0)