Merge most of internal headers into internal.h
Fix the includes accordingly and get rid of some unused ones.
This commit is contained in:
parent
9177e021ab
commit
cef67c9f09
3
aead.c
3
aead.c
@ -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
29
aead.h
@ -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;
|
|
||||||
};
|
|
@ -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
4
auth.c
@ -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
35
auth.h
@ -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;
|
|
||||||
};
|
|
@ -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"
|
||||||
|
|
||||||
|
|
||||||
|
@ -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"
|
||||||
|
|
||||||
|
|
||||||
|
3
cipher.c
3
cipher.c
@ -16,8 +16,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "lilcrypto.h"
|
#include "internal.h"
|
||||||
#include "cipher.h"
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
|
43
cipher.h
43
cipher.h
@ -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;
|
|
||||||
};
|
|
@ -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
4
hash.c
@ -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
35
hash.h
@ -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;
|
|
||||||
};
|
|
@ -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"
|
||||||
|
|
||||||
|
|
||||||
|
@ -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"
|
||||||
|
|
||||||
|
|
||||||
|
@ -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"
|
||||||
|
|
||||||
|
|
||||||
|
@ -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 *);
|
|
26
impl_hmac.h
26
impl_hmac.h
@ -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];
|
|
||||||
};
|
|
@ -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"
|
||||||
|
|
||||||
|
|
||||||
|
@ -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]);
|
|
@ -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"
|
||||||
|
|
||||||
|
|
||||||
|
@ -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 *);
|
|
@ -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"
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
204
internal.h
Normal 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 */
|
Loading…
Reference in New Issue
Block a user