Просмотр исходного кода

Change messages types to void *

Frank Denis 9 лет назад
Родитель
Сommit
f26a85a3f4
4 измененных файлов с 24 добавлено и 20 удалено
  1. 6 7
      hydrogen.h
  2. 7 5
      impl/hash.h
  3. 7 6
      impl/hash128.h
  4. 4 2
      impl/secretbox.h

+ 6 - 7
hydrogen.h

@@ -67,12 +67,11 @@ void hydro_hash_keygen(uint8_t *key, size_t key_len);
 int hydro_hash_init(hydro_hash_state *state, const uint8_t *key, size_t key_len,
     size_t out_len);
 
-int hydro_hash_update(
-    hydro_hash_state *state, const uint8_t *in, size_t in_len);
+int hydro_hash_update(hydro_hash_state *state, const void *in_, size_t in_len);
 
 int hydro_hash_final(hydro_hash_state *state, uint8_t *out, size_t out_len);
 
-int hydro_hash_hash(uint8_t *out, size_t out_len, const uint8_t *in,
+int hydro_hash_hash(uint8_t *out, size_t out_len, const void *in_,
     size_t in_len, const uint8_t *key, size_t key_len);
 
 /* ---------------- */
@@ -89,14 +88,14 @@ typedef struct hydro_hash128_state {
 
 void hydro_hash128_keygen(uint8_t key[hydro_hash128_KEYBYTES]);
 
-int hydro_hash128_hash(uint8_t out[hydro_hash128_BYTES], const uint8_t *in,
+int hydro_hash128_hash(uint8_t out[hydro_hash128_BYTES], const void *in_,
     size_t in_len, const uint8_t key[hydro_hash128_KEYBYTES]);
 
 int hydro_hash128_init(
     hydro_hash128_state *state, const uint8_t key[hydro_hash128_KEYBYTES]);
 
 int hydro_hash128_update(
-    hydro_hash128_state *state, const uint8_t *in, size_t in_len);
+    hydro_hash128_state *state, const void *in_, size_t in_len);
 
 int hydro_hash128_final(
     hydro_hash128_state *state, uint8_t out[hydro_hash128_BYTES]);
@@ -108,10 +107,10 @@ int hydro_hash128_final(
 
 void hydro_secretbox_keygen(uint8_t key[hydro_secretbox_KEYBYTES]);
 
-int hydro_secretbox_encrypt(uint8_t *c, const uint8_t *m, size_t mlen,
+int hydro_secretbox_encrypt(uint8_t *c, const void *m_, size_t mlen,
     const uint8_t key[hydro_secretbox_KEYBYTES]);
 
-int hydro_secretbox_decrypt(uint8_t *m, const uint8_t *c, size_t clen,
+int hydro_secretbox_decrypt(void *m_, const uint8_t *c, size_t clen,
     const uint8_t key[hydro_secretbox_KEYBYTES])
     __attribute__((warn_unused_result));
 

+ 7 - 5
impl/hash.h

@@ -151,11 +151,12 @@ int hydro_hash_init(
     return 0;
 }
 
-int hydro_hash_update(hydro_hash_state *state, const uint8_t *in, size_t in_len)
+int hydro_hash_update(hydro_hash_state *state, const void *in_, size_t in_len)
 {
-    size_t left;
-    size_t ps;
-    size_t i;
+    const uint8_t *in = (const uint8_t *)in_;
+    size_t         left;
+    size_t         ps;
+    size_t         i;
 
     while (in_len > 0) {
         left = hydro_hash_BLOCKBYTES - state->buf_off;
@@ -220,10 +221,11 @@ int hydro_hash_final(hydro_hash_state *state, uint8_t *out, size_t out_len)
     return 0;
 }
 
-int hydro_hash_hash(uint8_t *out, size_t out_len, const uint8_t *in,
+int hydro_hash_hash(uint8_t *out, size_t out_len, const void *in_,
     size_t in_len, const uint8_t *key, size_t key_len)
 {
     hydro_hash_state st;
+    const uint8_t *  in = (const uint8_t *)in_;
 
     if (hydro_hash_init(&st, key, key_len, out_len) != 0 ||
         hydro_hash_update(&st, in, in_len) != 0 ||

+ 7 - 6
impl/hash128.h

@@ -47,11 +47,12 @@ static void hydro_hash128_hashblock(
 }
 
 int hydro_hash128_update(
-    hydro_hash128_state *state, const uint8_t *in, size_t in_len)
+    hydro_hash128_state *state, const void *in_, size_t in_len)
 {
-    size_t left;
-    size_t ps;
-    size_t i;
+    const uint8_t *in = (const uint8_t *)in_;
+    size_t         left;
+    size_t         ps;
+    size_t         i;
 
     state->b += (uint8_t)in_len;
     while (in_len > 0) {
@@ -98,13 +99,13 @@ int hydro_hash128_final(
     return 0;
 }
 
-int hydro_hash128_hash(uint8_t out[hydro_hash128_BYTES], const uint8_t *in,
+int hydro_hash128_hash(uint8_t out[hydro_hash128_BYTES], const void *in_,
     size_t in_len, const uint8_t key[hydro_hash128_KEYBYTES])
 {
     hydro_hash128_state st;
 
     hydro_hash128_init(&st, key);
-    hydro_hash128_update(&st, in, in_len);
+    hydro_hash128_update(&st, in_, in_len);
 
     return hydro_hash128_final(&st, out);
 }

+ 4 - 2
impl/secretbox.h

@@ -4,13 +4,14 @@ void hydro_secretbox_keygen(uint8_t key[hydro_secretbox_KEYBYTES])
     randombytes_buf(key, hydro_secretbox_KEYBYTES);
 }
 
-int hydro_secretbox_encrypt(uint8_t *c, const uint8_t *m, size_t mlen,
+int hydro_secretbox_encrypt(uint8_t *c, const void *m_, size_t mlen,
     const uint8_t key[hydro_secretbox_KEYBYTES])
 {
     hydro_hash128_state st;
     uint8_t             t0[hydro_stream_chacha20_block_BYTES];
     uint8_t             k0[hydro_stream_hchacha20_KEYBYTES];
     uint8_t             nonce[hydro_stream_hchacha20_BYTES];
+    const uint8_t *     m  = (const uint8_t *)m_;
     const uint8_t *mac_key = &t0[0], *nonce_key = &t0[16], *ct_key = &t0[32];
 
     COMPILER_ASSERT(hydro_stream_chacha20_block_BYTES ==
@@ -36,13 +37,14 @@ int hydro_secretbox_encrypt(uint8_t *c, const uint8_t *m, size_t mlen,
     return 0;
 }
 
-int hydro_secretbox_decrypt(uint8_t *m, const uint8_t *c, size_t clen,
+int hydro_secretbox_decrypt(void *m_, const uint8_t *c, size_t clen,
     const uint8_t key[hydro_secretbox_KEYBYTES])
 {
     hydro_hash128_state st;
     uint8_t             t0[hydro_stream_chacha20_block_BYTES];
     uint8_t             nonce[hydro_stream_hchacha20_BYTES];
     uint8_t             mac[hydro_secretbox_MACBYTES];
+    uint8_t *           m       = (uint8_t *)m_;
     const uint8_t *     mac_key = &t0[0], *ct_key = &t0[32];
     size_t              mlen;