Merge most of internal headers into internal.h

Fix the includes accordingly and get rid of some unused ones.
This commit is contained in:
Lucas Gabriel Vuotto 2024-06-17 21:52:07 +00:00
parent 9177e021ab
commit cef67c9f09
24 changed files with 218 additions and 362 deletions

3
aead.c
View File

@ -14,8 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "lilcrypto.h" #include "internal.h"
#include "aead.h"
int int

29
aead.h
View File

@ -1,29 +0,0 @@
/*
* Copyright (c) 2024 Lucas Gabriel Vuotto <lucas@lgv5.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stddef.h>
#include <stdint.h>
struct lc_aead_impl {
int (*seal)(uint8_t *, size_t *, void *, const uint8_t *, size_t,
const uint8_t *, size_t);
int (*open)(uint8_t *, size_t *, void *, const uint8_t *, size_t,
const uint8_t *, size_t);
size_t argsz;
size_t blocklen;
};

View File

@ -14,10 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "lilcrypto.h" #include "internal.h"
#include "aead.h"
#include "impl_chacha20.h"
#include "util.h" #include "util.h"

4
auth.c
View File

@ -15,10 +15,8 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "lilcrypto.h" #include "internal.h"
#include "auth.h"
int int

35
auth.h
View File

@ -1,35 +0,0 @@
/*
* Copyright (c) 2024 Lucas Gabriel Vuotto <lucas@lgv5.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stddef.h>
#include <stdint.h>
struct lc_auth_impl {
int (*init)(void *, void *);
int (*update)(void *, const uint8_t *, size_t);
int (*final)(void *, uint8_t *, size_t *);
int (*auth)(uint8_t *, size_t *, void *, const uint8_t *, size_t);
size_t argsz;
size_t blocklen;
size_t taglen;
};
struct lc_auth_ctx {
const struct lc_auth_impl *impl;
void *arg;
};

View File

@ -14,13 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <stdlib.h> #include "internal.h"
#include "lilcrypto.h"
#include "auth.h"
#include "hash.h"
#include "impl_hmac.h"
#include "util.h" #include "util.h"

View File

@ -14,12 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <stdlib.h> #include "internal.h"
#include "lilcrypto.h"
#include "auth.h"
#include "impl_poly1305.h"
#include "util.h" #include "util.h"

View File

@ -16,8 +16,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "lilcrypto.h" #include "internal.h"
#include "cipher.h"
int int

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) 2024 Lucas Gabriel Vuotto <lucas@lgv5.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stddef.h>
#include <stdint.h>
struct lc_cipher_impl {
int (*encrypt_init)(void *, void *);
int (*encrypt_update)(void *, uint8_t *, size_t *, const uint8_t *,
size_t);
int (*encrypt_final)(void *, uint8_t *, size_t *);
int (*encrypt)(uint8_t *, size_t *, void *, const uint8_t *,
size_t);
int (*decrypt_init)(void *, void *);
int (*decrypt_update)(void *, uint8_t *, size_t *, const uint8_t *,
size_t);
int (*decrypt_final)(void *, uint8_t *, size_t *);
int (*decrypt)(uint8_t *, size_t *, void *, const uint8_t *,
size_t);
size_t argsz;
size_t blocklen;
};
struct lc_cipher_ctx {
const struct lc_cipher_impl *impl;
void *arg;
};

View File

@ -15,12 +15,8 @@
*/ */
#include <limits.h> #include <limits.h>
#include <stdlib.h>
#include "lilcrypto.h"
#include "cipher.h"
#include "impl_chacha20.h"
#include "internal.h"
#include "util.h" #include "util.h"

4
hash.c
View File

@ -15,10 +15,8 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "lilcrypto.h" #include "internal.h"
#include "hash.h"
int int

35
hash.h
View File

@ -1,35 +0,0 @@
/*
* Copyright (c) 2024 Lucas Gabriel Vuotto <lucas@lgv5.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stddef.h>
#include <stdint.h>
struct lc_hash_impl {
int (*init)(void *);
int (*update)(void *, const uint8_t *, size_t);
int (*final)(void *, uint8_t *, size_t *);
int (*hash)(uint8_t *, size_t *, const uint8_t *, size_t);
size_t argsz;
size_t blocklen;
size_t hashlen;
};
struct lc_hash_ctx {
const struct lc_hash_impl *impl;
void *arg;
};

View File

@ -14,11 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <stdlib.h> #include "internal.h"
#include "lilcrypto.h"
#include "hash.h"
#include "impl_sha256.h"
#include "util.h" #include "util.h"

View File

@ -14,11 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <stdlib.h> #include "internal.h"
#include "lilcrypto.h"
#include "hash.h"
#include "impl_sha512.h"
#include "util.h" #include "util.h"

View File

@ -14,10 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <stddef.h> #include "internal.h"
#include <stdint.h>
#include "impl_chacha20.h"
#include "util.h" #include "util.h"

View File

@ -1,37 +0,0 @@
/*
* Copyright (c) 2024 Lucas Gabriel Vuotto <lucas@lgv5.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "lilcrypto.h"
#define CHACHA20_BLOCKLEN_WORDS (LC_CHACHA20_BLOCKLEN / sizeof(uint32_t))
#define CHACHA20_CTRMAX 4294967295 /* 2^32 - 1 */
#define CHACHA20_KEY_WORDS (LC_CHACHA20_KEYLEN / sizeof(uint32_t))
#define CHACHA20_NONCE_WORDS 4
#define CHACHA20_ROUNDS 10
struct chacha20_state {
uint32_t s[CHACHA20_BLOCKLEN_WORDS];
uint32_t k[CHACHA20_KEY_WORDS];
uint32_t n[CHACHA20_NONCE_WORDS];
size_t blen;
uint8_t b[LC_CHACHA20_BLOCKLEN];
};
void chacha20_block(struct chacha20_state *);
void hchacha20_block(struct chacha20_state *);

View File

@ -1,26 +0,0 @@
/*
* Copyright (c) 2024 Lucas Gabriel Vuotto <lucas@lgv5.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "lilcrypto.h"
#define HMAC_BLOCKLEN_MAX LC_SHA512_BLOCKLEN
struct hmac_state {
struct lc_hash_ctx *hash;
uint8_t key[HMAC_BLOCKLEN_MAX];
};

View File

@ -14,10 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <stddef.h> #include "internal.h"
#include <stdint.h>
#include "impl_poly1305.h"
#include "util.h" #include "util.h"

View File

@ -1,35 +0,0 @@
/*
* Copyright (c) 2024 Lucas Gabriel Vuotto <lucas@lgv5.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "lilcrypto.h"
#define POLY1305_TAGLEN_WORDS (LC_POLY1305_TAGLEN / sizeof(uint32_t))
struct poly1305_state {
uint32_t h0, h1, h2, h3, h4;
uint32_t r0, r1, r2, r3, r4;
uint32_t x1, x2, x3, x4;
uint32_t s0, s1, s2, s3;
size_t blen;
uint8_t b[LC_POLY1305_BLOCKLEN];
};
void poly1305_block(struct poly1305_state *, uint32_t);
void poly1305_reduce(struct poly1305_state *,
uint32_t [POLY1305_TAGLEN_WORDS]);

View File

@ -14,10 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <stddef.h> #include "internal.h"
#include <stdint.h>
#include "impl_sha256.h"
#include "util.h" #include "util.h"

View File

@ -1,32 +0,0 @@
/*
* Copyright (c) 2024 Lucas Gabriel Vuotto <lucas@lgv5.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "lilcrypto.h"
#define SHA256_BLOCKLEN_WORDS (LC_SHA256_BLOCKLEN / sizeof(uint32_t))
#define SHA256_ROUNDS 64
struct sha256_state {
uint32_t h0, h1, h2, h3, h4, h5, h6, h7;
uint64_t sz;
size_t blen;
uint8_t b[LC_SHA256_BLOCKLEN];
};
void sha256_block(struct sha256_state *);

View File

@ -14,10 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <stddef.h> #include "internal.h"
#include <stdint.h>
#include "impl_sha512.h"
#include "util.h" #include "util.h"

View File

@ -1,32 +0,0 @@
/*
* Copyright (c) 2024 Lucas Gabriel Vuotto <lucas@lgv5.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "lilcrypto.h"
#define SHA512_BLOCKLEN_WORDS (LC_SHA512_BLOCKLEN / sizeof(uint64_t))
#define SHA512_ROUNDS 80
struct sha512_state {
uint64_t h0, h1, h2, h3, h4, h5, h6, h7;
uint64_t szhi, szlo;
size_t blen;
uint8_t b[LC_SHA512_BLOCKLEN];
};
void sha512_block(struct sha512_state *);

204
internal.h Normal file
View File

@ -0,0 +1,204 @@
/*
* Copyright (c) 2024 Lucas Gabriel Vuotto <lucas@lgv5.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef LC_INTERNAL_H
#define LC_INTERNAL_H
#include "lilcrypto.h"
/*
* CONSTANTS
*/
/* Authentitcation. */
#define HMAC_BLOCKLEN_MAX LC_SHA512_BLOCKLEN
#define POLY1305_TAGLEN_WORDS (LC_POLY1305_TAGLEN / sizeof(uint32_t))
/* Ciphers. */
#define CHACHA20_BLOCKLEN_WORDS (LC_CHACHA20_BLOCKLEN / sizeof(uint32_t))
#define CHACHA20_CTRMAX 4294967295 /* 2^32 - 1 */
#define CHACHA20_KEY_WORDS (LC_CHACHA20_KEYLEN / sizeof(uint32_t))
#define CHACHA20_NONCE_WORDS 4
#define CHACHA20_ROUNDS 10
/* Hashes. */
#define SHA256_BLOCKLEN_WORDS (LC_SHA256_BLOCKLEN / sizeof(uint32_t))
#define SHA256_ROUNDS 64
#define SHA512_BLOCKLEN_WORDS (LC_SHA512_BLOCKLEN / sizeof(uint64_t))
#define SHA512_ROUNDS 80
/*
* STRUCTS
*/
/*
* *_impl provides the function pointers to the actual implementation of methods,
* serving as an interface to the cryptographic algorithms.
*/
struct lc_aead_impl {
int (*seal)(uint8_t *, size_t *, void *, const uint8_t *, size_t,
const uint8_t *, size_t);
int (*open)(uint8_t *, size_t *, void *, const uint8_t *, size_t,
const uint8_t *, size_t);
size_t argsz;
size_t blocklen;
};
struct lc_auth_impl {
int (*init)(void *, void *);
int (*update)(void *, const uint8_t *, size_t);
int (*final)(void *, uint8_t *, size_t *);
int (*auth)(uint8_t *, size_t *, void *, const uint8_t *, size_t);
size_t argsz;
size_t blocklen;
size_t taglen;
};
struct lc_cipher_impl {
int (*encrypt_init)(void *, void *);
int (*encrypt_update)(void *, uint8_t *, size_t *, const uint8_t *,
size_t);
int (*encrypt_final)(void *, uint8_t *, size_t *);
int (*encrypt)(uint8_t *, size_t *, void *, const uint8_t *,
size_t);
int (*decrypt_init)(void *, void *);
int (*decrypt_update)(void *, uint8_t *, size_t *, const uint8_t *,
size_t);
int (*decrypt_final)(void *, uint8_t *, size_t *);
int (*decrypt)(uint8_t *, size_t *, void *, const uint8_t *,
size_t);
size_t argsz;
size_t blocklen;
};
struct lc_hash_impl {
int (*init)(void *);
int (*update)(void *, const uint8_t *, size_t);
int (*final)(void *, uint8_t *, size_t *);
int (*hash)(uint8_t *, size_t *, const uint8_t *, size_t);
size_t argsz;
size_t blocklen;
size_t hashlen;
};
/*
* *_ctx binds an *_impl with an state, effectively representing an instance of a
* cryptographic algorithm.
*/
struct lc_auth_ctx {
const struct lc_auth_impl *impl;
void *arg;
};
struct lc_cipher_ctx {
const struct lc_cipher_impl *impl;
void *arg;
};
struct lc_hash_ctx {
const struct lc_hash_impl *impl;
void *arg;
};
/*
* *_state holds the internal state of the cryptographic algorithms.
*/
/* Authentication. */
struct hmac_state {
struct lc_hash_ctx *hash;
uint8_t key[HMAC_BLOCKLEN_MAX];
};
struct poly1305_state {
uint32_t h0, h1, h2, h3, h4;
uint32_t r0, r1, r2, r3, r4;
uint32_t x1, x2, x3, x4;
uint32_t s0, s1, s2, s3;
size_t blen;
uint8_t b[LC_POLY1305_BLOCKLEN];
};
/* Ciphers. */
struct chacha20_state {
uint32_t s[CHACHA20_BLOCKLEN_WORDS];
uint32_t k[CHACHA20_KEY_WORDS];
uint32_t n[CHACHA20_NONCE_WORDS];
size_t blen;
uint8_t b[LC_CHACHA20_BLOCKLEN];
};
/* Hashes. */
struct sha256_state {
uint32_t h0, h1, h2, h3, h4, h5, h6, h7;
uint64_t sz;
size_t blen;
uint8_t b[LC_SHA256_BLOCKLEN];
};
struct sha512_state {
uint64_t h0, h1, h2, h3, h4, h5, h6, h7;
uint64_t szhi, szlo;
size_t blen;
uint8_t b[LC_SHA512_BLOCKLEN];
};
/*
* PROTOTYPES
*/
/* Authentitcation. */
void poly1305_block(struct poly1305_state *, uint32_t);
void poly1305_reduce(struct poly1305_state *, uint32_t [POLY1305_TAGLEN_WORDS]);
/* Ciphers. */
void chacha20_block(struct chacha20_state *);
void hchacha20_block(struct chacha20_state *);
/* Hashes. */
void sha256_block(struct sha256_state *);
void sha512_block(struct sha512_state *);
#endif /* LC_INTERNAL_H */