mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-19 10:05:05 -07:00
Require the generichash state to be aligned
Alignment is already required by other functions anyway.
This commit is contained in:
parent
1e7839a90c
commit
0187ba70ad
@ -41,6 +41,10 @@ size_t crypto_generichash_keybytes(void);
|
||||
SODIUM_EXPORT
|
||||
const char *crypto_generichash_primitive(void);
|
||||
|
||||
/*
|
||||
* Important when writing bindings for other programming languages:
|
||||
* the state address *must* be 64-bytes aligned.
|
||||
*/
|
||||
typedef crypto_generichash_blake2b_state crypto_generichash_state;
|
||||
|
||||
SODIUM_EXPORT
|
||||
|
@ -20,7 +20,7 @@ extern "C" {
|
||||
# pragma pack(push, 1)
|
||||
#endif
|
||||
|
||||
typedef struct crypto_generichash_blake2b_state {
|
||||
typedef struct CRYPTO_ALIGN(64) crypto_generichash_blake2b_state {
|
||||
uint64_t h[8];
|
||||
uint64_t t[2];
|
||||
uint64_t f[2];
|
||||
|
@ -41,28 +41,6 @@ main(void)
|
||||
printf("crypto_generichash_final() should have returned -1\n");
|
||||
}
|
||||
}
|
||||
sodium_free(st);
|
||||
|
||||
/* unaligned state */
|
||||
st = sodium_malloc(crypto_generichash_statebytes() + 1U);
|
||||
i = 0;
|
||||
if (crypto_generichash_init(st, k,
|
||||
crypto_generichash_KEYBYTES_MAX,
|
||||
crypto_generichash_BYTES_MAX) != 0) {
|
||||
printf("crypto_generichash_init(2)\n");
|
||||
return 1;
|
||||
}
|
||||
crypto_generichash_update(st, in, i);
|
||||
crypto_generichash_update(st, in, i);
|
||||
crypto_generichash_update(st, in, i);
|
||||
if (crypto_generichash_final(st, out,
|
||||
crypto_generichash_BYTES_MAX) != 0) {
|
||||
printf("crypto_generichash_final(2) should have returned 0\n");
|
||||
}
|
||||
for (j = 0; j < crypto_generichash_BYTES_MAX; ++j) {
|
||||
printf("%02x", (unsigned int) out[j]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
assert(crypto_generichash_init(st, k, sizeof k, 0U) == -1);
|
||||
assert(crypto_generichash_init(st, k, sizeof k,
|
||||
|
@ -62,4 +62,3 @@ d09b717a0c80f581c07b8813e0ae79cec2188f77122f7477954610655a20420f13eb1b68cacde8c1
|
||||
23ac1ccd5e7df51b65b284650158d662e7ef51ebae01b879f39cec484b688c792f8e854bd8ca31ffe8796d28f10e49ab402dab47878a21cb95556dc32b0a
|
||||
f8f5323ebcc28bf927e72d342b5b70d80ba67794afb4c28debad21b0dae24c7a9252e862eb4b83bea6d9c0bb7c108983c987f13d73f250c7f14483f0454a24
|
||||
55b97ca594d68ccf69a0a93fe7fa4004c7e2947a8cac4ca4a44e17ac6876f472e3f221b341a28004cd35a79cfad7fabb9378ce5af03e4c0445ebbe9540943bbd
|
||||
10ebb67700b1868efb4417987acf4690ae9d972fb7a590c2f02871799aaa4786b5e996e8f0f4eb981fc214b005f42d2ff4233499391653df7aefcbc13fc51568
|
||||
|
Loading…
Reference in New Issue
Block a user