Permalink
Browse files

Format

  • Loading branch information...
jedisct1 committed Dec 30, 2017
1 parent c223fbe commit c6f6e00fe2d0921f7e3548ba91aaa4cee085d973
Showing with 456 additions and 611 deletions.
  1. +1 −1 .clang-format
  2. +65 −87 hydrogen.h
  3. +6 −5 impl/common.h
  4. +29 −33 impl/core.h
  5. +4 −8 impl/gimli-core/ssse3.h
  6. +16 −22 impl/hash.h
  7. +17 −23 impl/hydrogen_p.h
  8. +2 −4 impl/kdf.h
  9. +53 −78 impl/kx.h
  10. +66 −86 impl/pwhash.h
  11. +29 −35 impl/random.h
  12. +40 −51 impl/secretbox.h
  13. +25 −34 impl/sign.h
  14. +52 −69 impl/x25519.h
  15. +51 −75 tests/tests.c
View
@@ -37,7 +37,7 @@ BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
View
@@ -6,17 +6,17 @@
#include <stdlib.h>
#ifdef __cplusplus
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wlong-long"
#endif
# ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wlong-long"
# endif
extern "C" {
#endif
#ifndef __GNUC__
#ifdef __attribute__
#undef __attribute__
#endif
#define __attribute__(a)
# ifdef __attribute__
# undef __attribute__
# endif
# define __attribute__(a)
#endif
#define HYDRO_VERSION_MAJOR 1
@@ -55,17 +55,15 @@ typedef struct hydro_hash_state {
void hydro_hash_keygen(uint8_t *key, size_t key_len);
int hydro_hash_init(hydro_hash_state *state,
const char ctx[hydro_hash_CONTEXTBYTES], const uint8_t *key,
size_t key_len);
int hydro_hash_init(hydro_hash_state *state, const char ctx[hydro_hash_CONTEXTBYTES],
const uint8_t *key, size_t key_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 void *in_,
size_t in_len, const char ctx[hydro_hash_CONTEXTBYTES],
const uint8_t *key, size_t key_len);
int hydro_hash_hash(uint8_t *out, size_t out_len, const void *in_, size_t in_len,
const char ctx[hydro_hash_CONTEXTBYTES], const uint8_t *key, size_t key_len);
/* ---------------- */
@@ -76,27 +74,22 @@ int hydro_hash_hash(uint8_t *out, size_t out_len, const void *in_,
void hydro_secretbox_keygen(uint8_t key[hydro_secretbox_KEYBYTES]);
int hydro_secretbox_encrypt(uint8_t *c, const void *m_, size_t mlen,
uint64_t msg_id,
int hydro_secretbox_encrypt(uint8_t *c, const void *m_, size_t mlen, uint64_t msg_id,
const char ctx[hydro_secretbox_CONTEXTBYTES],
const uint8_t key[hydro_secretbox_KEYBYTES]);
int hydro_secretbox_decrypt(void *m_, const uint8_t *c, size_t clen,
uint64_t msg_id,
int hydro_secretbox_decrypt(void *m_, const uint8_t *c, size_t clen, uint64_t msg_id,
const char ctx[hydro_secretbox_CONTEXTBYTES],
const uint8_t key[hydro_secretbox_KEYBYTES])
__attribute__((warn_unused_result));
void hydro_secretbox_probe_create(uint8_t probe[hydro_secretbox_PROBEBYTES],
const uint8_t *c, size_t c_len,
const char ctx[hydro_secretbox_CONTEXTBYTES],
void hydro_secretbox_probe_create(uint8_t probe[hydro_secretbox_PROBEBYTES], const uint8_t *c,
size_t c_len, const char ctx[hydro_secretbox_CONTEXTBYTES],
const uint8_t key[hydro_secretbox_KEYBYTES]);
int
hydro_secretbox_probe_verify(const uint8_t probe[hydro_secretbox_PROBEBYTES],
const uint8_t *c, size_t c_len,
const char ctx[hydro_secretbox_CONTEXTBYTES],
const uint8_t key[hydro_secretbox_KEYBYTES])
int hydro_secretbox_probe_verify(const uint8_t probe[hydro_secretbox_PROBEBYTES], const uint8_t *c,
size_t c_len, const char ctx[hydro_secretbox_CONTEXTBYTES],
const uint8_t key[hydro_secretbox_KEYBYTES])
__attribute__((warn_unused_result));
/* ---------------- */
@@ -108,8 +101,7 @@ hydro_secretbox_probe_verify(const uint8_t probe[hydro_secretbox_PROBEBYTES],
void hydro_kdf_keygen(uint8_t key[hydro_kdf_KEYBYTES]);
int hydro_kdf_derive_from_key(uint8_t *subkey, size_t subkey_len,
uint64_t subkey_id,
int hydro_kdf_derive_from_key(uint8_t *subkey, size_t subkey_len, uint64_t subkey_id,
const char ctx[hydro_kdf_CONTEXTBYTES],
const uint8_t key[hydro_kdf_KEYBYTES]);
@@ -133,28 +125,25 @@ typedef struct hydro_sign_keypair {
void hydro_sign_keygen(hydro_sign_keypair *kp);
void hydro_sign_keygen_deterministic(hydro_sign_keypair *kp,
const uint8_t seed[hydro_sign_SEEDBYTES]);
const uint8_t seed[hydro_sign_SEEDBYTES]);
int hydro_sign_init(hydro_sign_state *state,
const char ctx[hydro_sign_CONTEXTBYTES]);
int hydro_sign_init(hydro_sign_state *state, const char ctx[hydro_sign_CONTEXTBYTES]);
int hydro_sign_update(hydro_sign_state *state, const void *m_, size_t mlen);
int hydro_sign_final_create(hydro_sign_state *state,
uint8_t csig[hydro_sign_BYTES],
const uint8_t sk[hydro_sign_SECRETKEYBYTES]);
int hydro_sign_final_create(hydro_sign_state *state, uint8_t csig[hydro_sign_BYTES],
const uint8_t sk[hydro_sign_SECRETKEYBYTES]);
int hydro_sign_final_verify(hydro_sign_state *state,
const uint8_t csig[hydro_sign_BYTES],
const uint8_t pk[hydro_sign_PUBLICKEYBYTES])
int hydro_sign_final_verify(hydro_sign_state *state, const uint8_t csig[hydro_sign_BYTES],
const uint8_t pk[hydro_sign_PUBLICKEYBYTES])
__attribute__((warn_unused_result));
int hydro_sign_create(uint8_t csig[hydro_sign_BYTES], const void *m_,
size_t mlen, const char ctx[hydro_sign_CONTEXTBYTES],
int hydro_sign_create(uint8_t csig[hydro_sign_BYTES], const void *m_, size_t mlen,
const char ctx[hydro_sign_CONTEXTBYTES],
const uint8_t sk[hydro_sign_SECRETKEYBYTES]);
int hydro_sign_verify(const uint8_t csig[hydro_sign_BYTES], const void *m_,
size_t mlen, const char ctx[hydro_sign_CONTEXTBYTES],
int hydro_sign_verify(const uint8_t csig[hydro_sign_BYTES], const void *m_, size_t mlen,
const char ctx[hydro_sign_CONTEXTBYTES],
const uint8_t pk[hydro_sign_PUBLICKEYBYTES])
__attribute__((warn_unused_result));
@@ -192,22 +181,18 @@ void hydro_kx_keygen(hydro_kx_keypair *static_kp);
void hydro_kx_keygen_deterministic(hydro_kx_keypair *static_kp,
const uint8_t seed[hydro_kx_SEEDBYTES]);
int hydro_kx_xx_1(hydro_kx_state *state,
uint8_t response1[hydro_kx_RESPONSE1BYTES],
const uint8_t psk[hydro_kx_PSKBYTES]);
int hydro_kx_xx_1(hydro_kx_state *state, uint8_t response1[hydro_kx_RESPONSE1BYTES],
const uint8_t psk[hydro_kx_PSKBYTES]);
int hydro_kx_xx_2(hydro_kx_state * state,
uint8_t response2[hydro_kx_RESPONSE2BYTES],
const uint8_t response1[hydro_kx_RESPONSE1BYTES],
const uint8_t psk[hydro_kx_PSKBYTES],
const hydro_kx_keypair *static_kp);
int hydro_kx_xx_2(hydro_kx_state *state, uint8_t response2[hydro_kx_RESPONSE2BYTES],
const uint8_t response1[hydro_kx_RESPONSE1BYTES],
const uint8_t psk[hydro_kx_PSKBYTES], const hydro_kx_keypair *static_kp);
int hydro_kx_xx_3(hydro_kx_state *state, hydro_kx_session_keypair *kp,
uint8_t response3[hydro_kx_RESPONSE3BYTES],
uint8_t peer_static_pk[hydro_kx_PUBLICKEYBYTES],
const uint8_t response2[hydro_kx_RESPONSE2BYTES],
const uint8_t psk[hydro_kx_PSKBYTES],
const hydro_kx_keypair *static_kp);
const uint8_t psk[hydro_kx_PSKBYTES], const hydro_kx_keypair *static_kp);
int hydro_kx_xx_4(hydro_kx_state *state, hydro_kx_session_keypair *kp,
uint8_t peer_static_pk[hydro_kx_PUBLICKEYBYTES],
@@ -222,38 +207,33 @@ int hydro_kx_xx_4(hydro_kx_state *state, hydro_kx_session_keypair *kp,
void hydro_pwhash_keygen(uint8_t master_key[hydro_pwhash_MASTERKEYBYTES]);
int hydro_pwhash_deterministic(
uint8_t *h, size_t h_len, const char *passwd, size_t passwd_len,
const char ctx[hydro_pwhash_CONTEXTBYTES],
const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES], uint64_t opslimit,
size_t memlimit, uint8_t threads);
int hydro_pwhash_deterministic(uint8_t *h, size_t h_len, const char *passwd, size_t passwd_len,
const char ctx[hydro_pwhash_CONTEXTBYTES],
const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
uint64_t opslimit, size_t memlimit, uint8_t threads);
int hydro_pwhash_create(uint8_t stored[hydro_pwhash_STOREDBYTES],
const char *passwd, size_t passwd_len,
const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
int hydro_pwhash_create(uint8_t stored[hydro_pwhash_STOREDBYTES], const char *passwd,
size_t passwd_len, const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
uint64_t opslimit, size_t memlimit, uint8_t threads);
int hydro_pwhash_verify(const uint8_t stored[hydro_pwhash_STOREDBYTES],
const char *passwd, size_t passwd_len,
const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
uint64_t opslimit_max, size_t memlimit_max,
uint8_t threads_max);
int hydro_pwhash_verify(const uint8_t stored[hydro_pwhash_STOREDBYTES], const char *passwd,
size_t passwd_len, const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
uint64_t opslimit_max, size_t memlimit_max, uint8_t threads_max);
int hydro_pwhash_derive_static_key(
uint8_t *static_key, size_t static_key_len,
const uint8_t stored[hydro_pwhash_STOREDBYTES], const char *passwd,
size_t passwd_len, const char ctx[hydro_pwhash_CONTEXTBYTES],
const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
uint64_t opslimit_max, size_t memlimit_max, uint8_t threads_max);
int hydro_pwhash_derive_static_key(uint8_t *static_key, size_t static_key_len,
const uint8_t stored[hydro_pwhash_STOREDBYTES],
const char *passwd, size_t passwd_len,
const char ctx[hydro_pwhash_CONTEXTBYTES],
const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
uint64_t opslimit_max, size_t memlimit_max, uint8_t threads_max);
int hydro_pwhash_reencrypt(
uint8_t stored[hydro_pwhash_STOREDBYTES],
const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
const uint8_t new_master_key[hydro_pwhash_MASTERKEYBYTES]);
int hydro_pwhash_reencrypt(uint8_t stored[hydro_pwhash_STOREDBYTES],
const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
const uint8_t new_master_key[hydro_pwhash_MASTERKEYBYTES]);
int hydro_pwhash_upgrade(uint8_t stored[hydro_pwhash_STOREDBYTES],
const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
uint64_t opslimit, size_t memlimit, uint8_t threads);
const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES], uint64_t opslimit,
size_t memlimit, uint8_t threads);
/* ---------------- */
@@ -265,27 +245,25 @@ bool hydro_equal(const void *b1_, const void *b2_, size_t len);
int hydro_compare(const uint8_t *b1_, const uint8_t *b2_, size_t len);
char *hydro_bin2hex(char *hex, size_t hex_maxlen, const uint8_t *bin,
size_t bin_len);
char *hydro_bin2hex(char *hex, size_t hex_maxlen, const uint8_t *bin, size_t bin_len);
int hydro_hex2bin(uint8_t *bin, size_t bin_maxlen, const char *hex,
size_t hex_len, const char *ignore, size_t *bin_len,
const char **hex_end);
int hydro_hex2bin(uint8_t *bin, size_t bin_maxlen, const char *hex, size_t hex_len,
const char *ignore, size_t *bin_len, const char **hex_end);
int hydro_pad(size_t *padded_buflen_p, unsigned char *buf,
size_t unpadded_buflen, size_t blocksize, size_t max_buflen);
int hydro_pad(size_t *padded_buflen_p, unsigned char *buf, size_t unpadded_buflen, size_t blocksize,
size_t max_buflen);
int hydro_unpad(size_t *unpadded_buflen_p, const unsigned char *buf,
size_t padded_buflen, size_t blocksize);
int hydro_unpad(size_t *unpadded_buflen_p, const unsigned char *buf, size_t padded_buflen,
size_t blocksize);
/* ---------------- */
#define HYDRO_HWTYPE_ATMEGA328 1
#ifndef HYDRO_HWTYPE
#ifdef __AVR__
#define HYDRO_HWTYPE HYDRO_HWTYPE_ATMEGA328
#endif
# ifdef __AVR__
# define HYDRO_HWTYPE HYDRO_HWTYPE_ATMEGA328
# endif
#endif
#ifdef __cplusplus
View
@@ -15,7 +15,8 @@
# define __restrict__
#endif
#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define NATIVE_BIG_ENDIAN
#endif
#ifndef NATIVE_BIG_ENDIAN
@@ -34,7 +35,7 @@
# if defined(__INTEL_COMPILER) || defined(_MSC_VER)
# define CRYPTO_ALIGN(x) __declspec(align(x))
# else
# define CRYPTO_ALIGN(x) __attribute__ ((aligned(x)))
# define CRYPTO_ALIGN(x) __attribute__((aligned(x)))
# endif
#endif
@@ -297,10 +298,10 @@ mem_xor(void *__restrict__ dst_, const void *__restrict__ src_, size_t n)
}
static inline void
mem_xor2(void *__restrict__ dst_, const void *__restrict__ src1_,
const void *__restrict__ src2_, size_t n)
mem_xor2(void *__restrict__ dst_, const void *__restrict__ src1_, const void *__restrict__ src2_,
size_t n)
{
unsigned char * dst = (unsigned char *) dst_;
unsigned char * dst = (unsigned char *) dst_;
const unsigned char *src1 = (const unsigned char *) src1_;
const unsigned char *src2 = (const unsigned char *) src2_;
size_t i;
Oops, something went wrong.

0 comments on commit c6f6e00

Please sign in to comment.