first commit
Some checks failed
/ buid (push) Has been cancelled

This commit is contained in:
2026-04-16 14:48:09 +07:00
commit 4b968a3347
5625 changed files with 1685474 additions and 0 deletions

View File

@ -0,0 +1,185 @@
/* aes.h
The aes/rijndael block cipher.
Copyright (C) 2001, 2013 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_AES_H_INCLUDED
#define NETTLE_AES_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define aes_set_encrypt_key nettle_aes_set_encrypt_key
#define aes_set_decrypt_key nettle_aes_set_decrypt_key
#define aes_invert_key nettle_aes_invert_key
#define aes_encrypt nettle_aes_encrypt
#define aes_decrypt nettle_aes_decrypt
#define aes128_set_encrypt_key nettle_aes128_set_encrypt_key
#define aes128_set_decrypt_key nettle_aes128_set_decrypt_key
#define aes128_invert_key nettle_aes128_invert_key
#define aes128_encrypt nettle_aes128_encrypt
#define aes128_decrypt nettle_aes128_decrypt
#define aes192_set_encrypt_key nettle_aes192_set_encrypt_key
#define aes192_set_decrypt_key nettle_aes192_set_decrypt_key
#define aes192_invert_key nettle_aes192_invert_key
#define aes192_encrypt nettle_aes192_encrypt
#define aes192_decrypt nettle_aes192_decrypt
#define aes256_set_encrypt_key nettle_aes256_set_encrypt_key
#define aes256_set_decrypt_key nettle_aes256_set_decrypt_key
#define aes256_invert_key nettle_aes256_invert_key
#define aes256_encrypt nettle_aes256_encrypt
#define aes256_decrypt nettle_aes256_decrypt
#define AES_BLOCK_SIZE 16
#define AES128_KEY_SIZE 16
#define AES192_KEY_SIZE 24
#define AES256_KEY_SIZE 32
#define _AES128_ROUNDS 10
#define _AES192_ROUNDS 12
#define _AES256_ROUNDS 14
struct aes128_ctx
{
uint32_t keys[4 * (_AES128_ROUNDS + 1)];
};
void
aes128_set_encrypt_key(struct aes128_ctx *ctx, const uint8_t *key);
void
aes128_set_decrypt_key(struct aes128_ctx *ctx, const uint8_t *key);
void
aes128_invert_key(struct aes128_ctx *dst,
const struct aes128_ctx *src);
void
aes128_encrypt(const struct aes128_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
void
aes128_decrypt(const struct aes128_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
struct aes192_ctx
{
uint32_t keys[4 * (_AES192_ROUNDS + 1)];
};
void
aes192_set_encrypt_key(struct aes192_ctx *ctx, const uint8_t *key);
void
aes192_set_decrypt_key(struct aes192_ctx *ctx, const uint8_t *key);
void
aes192_invert_key(struct aes192_ctx *dst,
const struct aes192_ctx *src);
void
aes192_encrypt(const struct aes192_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
void
aes192_decrypt(const struct aes192_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
struct aes256_ctx
{
uint32_t keys[4 * (_AES256_ROUNDS + 1)];
};
void
aes256_set_encrypt_key(struct aes256_ctx *ctx, const uint8_t *key);
void
aes256_set_decrypt_key(struct aes256_ctx *ctx, const uint8_t *key);
void
aes256_invert_key(struct aes256_ctx *dst,
const struct aes256_ctx *src);
void
aes256_encrypt(const struct aes256_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
void
aes256_decrypt(const struct aes256_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
/* The older nettle-2.7 AES interface is deprecated, please migrate to
the newer interface where each algorithm has a fixed key size. */
/* Variable key size between 128 and 256 bits. But the only valid
* values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */
#define AES_MIN_KEY_SIZE AES128_KEY_SIZE
#define AES_MAX_KEY_SIZE AES256_KEY_SIZE
#define AES_KEY_SIZE 32
struct aes_ctx
{
unsigned key_size; /* In octets */
union {
struct aes128_ctx ctx128;
struct aes192_ctx ctx192;
struct aes256_ctx ctx256;
} u;
};
void
aes_set_encrypt_key(struct aes_ctx *ctx,
size_t length, const uint8_t *key)
_NETTLE_ATTRIBUTE_DEPRECATED;
void
aes_set_decrypt_key(struct aes_ctx *ctx,
size_t length, const uint8_t *key)
_NETTLE_ATTRIBUTE_DEPRECATED;
void
aes_invert_key(struct aes_ctx *dst,
const struct aes_ctx *src)
_NETTLE_ATTRIBUTE_DEPRECATED;
void
aes_encrypt(const struct aes_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src) _NETTLE_ATTRIBUTE_DEPRECATED;
void
aes_decrypt(const struct aes_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src) _NETTLE_ATTRIBUTE_DEPRECATED;
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_AES_H_INCLUDED */

View File

@ -0,0 +1,79 @@
/* arcfour.h
The arcfour/rc4 stream cipher.
Copyright (C) 2001, 2014 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_ARCFOUR_H_INCLUDED
#define NETTLE_ARCFOUR_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define arcfour128_set_key nettle_arcfour128_set_key
#define arcfour_set_key nettle_arcfour_set_key
#define arcfour_crypt nettle_arcfour_crypt
/* Minimum and maximum keysizes, and a reasonable default. In
* octets.*/
#define ARCFOUR_MIN_KEY_SIZE 1
#define ARCFOUR_MAX_KEY_SIZE 256
#define ARCFOUR_KEY_SIZE 16
#define ARCFOUR128_KEY_SIZE 16
struct arcfour_ctx
{
uint8_t S[256];
uint8_t i;
uint8_t j;
};
void
arcfour_set_key(struct arcfour_ctx *ctx,
size_t length, const uint8_t *key);
void
arcfour128_set_key(struct arcfour_ctx *ctx, const uint8_t *key);
void
arcfour_crypt(struct arcfour_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ARCFOUR_H_INCLUDED */

View File

@ -0,0 +1,103 @@
/* arctwo.h
The arctwo/rfc2268 block cipher.
Copyright (C) 2004 Simon Josefsson
Copyright (C) 2002, 2004, 2014 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_ARCTWO_H_INCLUDED
#define NETTLE_ARCTWO_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define arctwo_set_key nettle_arctwo_set_key
#define arctwo_set_key_ekb nettle_arctwo_set_key_ekb
#define arctwo_set_key_gutmann nettle_arctwo_set_key_gutmann
#define arctwo40_set_key nettle_arctwo40_set_key
#define arctwo64_set_key nettle_arctwo64_set_key
#define arctwo128_set_key nettle_arctwo128_set_key
#define arctwo128_set_key_gutmann nettle_arctwo128_set_key_gutmann
#define arctwo_encrypt nettle_arctwo_encrypt
#define arctwo_decrypt nettle_arctwo_decrypt
#define ARCTWO_BLOCK_SIZE 8
/* Variable key size from 1 byte to 128 bytes. */
#define ARCTWO_MIN_KEY_SIZE 1
#define ARCTWO_MAX_KEY_SIZE 128
#define ARCTWO_KEY_SIZE 8
struct arctwo_ctx
{
uint16_t S[64];
};
/* Key expansion function that takes the "effective key bits", 1-1024,
as an explicit argument. 0 means maximum key bits. */
void
arctwo_set_key_ekb (struct arctwo_ctx *ctx,
size_t length, const uint8_t * key, unsigned ekb);
/* Equvivalent to arctwo_set_key_ekb, with ekb = 8 * length */
void
arctwo_set_key (struct arctwo_ctx *ctx, size_t length, const uint8_t *key);
void
arctwo40_set_key (struct arctwo_ctx *ctx, const uint8_t *key);
void
arctwo64_set_key (struct arctwo_ctx *ctx, const uint8_t *key);
void
arctwo128_set_key (struct arctwo_ctx *ctx, const uint8_t *key);
/* Equvivalent to arctwo_set_key_ekb, with ekb = 1024 */
void
arctwo_set_key_gutmann (struct arctwo_ctx *ctx,
size_t length, const uint8_t *key);
void
arctwo128_set_key_gutmann (struct arctwo_ctx *ctx,
const uint8_t *key);
void
arctwo_encrypt (struct arctwo_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
arctwo_decrypt (struct arctwo_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ARCTWO_H_INCLUDED */

View File

@ -0,0 +1,152 @@
/* asn1.h
Limited support for ASN.1 DER decoding.
Copyright (C) 2005 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_ASN1_H_INCLUDED
#define NETTLE_ASN1_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define asn1_der_iterator_first nettle_asn1_der_iterator_first
#define asn1_der_iterator_next nettle_asn1_der_iterator_next
#define asn1_der_decode_constructed nettle_asn1_der_decode_constructed
#define asn1_der_decode_constructed_last nettle_asn1_der_decode_constructed_last
#define asn1_der_decode_bitstring nettle_asn1_der_decode_bitstring
#define asn1_der_decode_bitstring_last nettle_asn1_der_decode_bitstring_last
#define asn1_der_get_uint32 nettle_asn1_der_get_uint32
#define asn1_der_get_bignum nettle_asn1_der_get_bignum
/* enum asn1_type keeps the class number and the constructive in bits
13-14, and the constructive flag in bit 12. The remaining 14 bits
are the tag (although currently, only tags in the range 0-30 are
supported). */
enum
{
ASN1_TYPE_CONSTRUCTED = 1 << 12,
ASN1_CLASS_UNIVERSAL = 0,
ASN1_CLASS_APPLICATION = 1 << 13,
ASN1_CLASS_CONTEXT_SPECIFIC = 2 << 13,
ASN1_CLASS_PRIVATE = 3 << 13,
ASN1_CLASS_MASK = 3 << 13,
ASN1_CLASS_SHIFT = 13,
};
enum asn1_type
{
ASN1_BOOLEAN = 1,
ASN1_INTEGER = 2,
ASN1_BITSTRING = 3,
ASN1_OCTETSTRING = 4,
ASN1_NULL = 5,
ASN1_IDENTIFIER = 6,
ASN1_REAL = 9,
ASN1_ENUMERATED = 10,
ASN1_UTF8STRING = 12,
ASN1_SEQUENCE = 16 | ASN1_TYPE_CONSTRUCTED,
ASN1_SET = 17 | ASN1_TYPE_CONSTRUCTED,
ASN1_PRINTABLESTRING = 19,
ASN1_TELETEXSTRING = 20,
ASN1_IA5STRING = 22,
ASN1_UTC = 23,
ASN1_UNIVERSALSTRING = 28,
ASN1_BMPSTRING = 30,
};
enum asn1_iterator_result
{
ASN1_ITERATOR_ERROR,
ASN1_ITERATOR_PRIMITIVE,
ASN1_ITERATOR_CONSTRUCTED,
ASN1_ITERATOR_END,
};
/* Parsing DER objects. */
struct asn1_der_iterator
{
size_t buffer_length;
const uint8_t *buffer;
/* Next object to parse. */
size_t pos;
enum asn1_type type;
/* Pointer to the current object */
size_t length;
const uint8_t *data;
};
/* Initializes the iterator. */
enum asn1_iterator_result
asn1_der_iterator_first(struct asn1_der_iterator *iterator,
size_t length, const uint8_t *input);
enum asn1_iterator_result
asn1_der_iterator_next(struct asn1_der_iterator *iterator);
/* Starts parsing of a constructed object. */
enum asn1_iterator_result
asn1_der_decode_constructed(struct asn1_der_iterator *i,
struct asn1_der_iterator *contents);
/* For the common case that we have a sequence at the end of the
object. Checks that the current object is the final one, and then
reinitializes the iterator to parse its ontents. */
enum asn1_iterator_result
asn1_der_decode_constructed_last(struct asn1_der_iterator *i);
enum asn1_iterator_result
asn1_der_decode_bitstring(struct asn1_der_iterator *i,
struct asn1_der_iterator *contents);
enum asn1_iterator_result
asn1_der_decode_bitstring_last(struct asn1_der_iterator *i);
/* All these functions return 1 on success, 0 on failure */
int
asn1_der_get_uint32(struct asn1_der_iterator *i,
uint32_t *x);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ASN1_H_INCLUDED */

View File

@ -0,0 +1,98 @@
/* balloon.h
Balloon password-hashing algorithm.
Copyright (C) 2022 Zoltan Fridrich
Copyright (C) 2022 Red Hat, Inc.
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
/* For a description of the algorithm, see:
* Boneh, D., Corrigan-Gibbs, H., Schechter, S. (2017, May 12). Balloon Hashing:
* A Memory-Hard Function Providing Provable Protection Against Sequential Attacks.
* Retrieved Sep 1, 2022, from https://eprint.iacr.org/2016/027.pdf
*/
#ifndef NETTLE_BALLOON_H_INCLUDED
#define NETTLE_BALLOON_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define balloon nettle_balloon
#define balloon_itch nettle_balloon_itch
#define balloon_sha1 nettle_balloon_sha1
#define balloon_sha256 nettle_balloon_sha256
#define balloon_sha384 nettle_balloon_sha384
#define balloon_sha512 nettle_balloon_sha512
void
balloon(void *hash_ctx,
nettle_hash_update_func *update,
nettle_hash_digest_func *digest,
size_t digest_size, size_t s_cost, size_t t_cost,
size_t passwd_length, const uint8_t *passwd,
size_t salt_length, const uint8_t *salt,
uint8_t *scratch, uint8_t *dst);
size_t
balloon_itch(size_t digest_size, size_t s_cost);
void
balloon_sha1(size_t s_cost, size_t t_cost,
size_t passwd_length, const uint8_t *passwd,
size_t salt_length, const uint8_t *salt,
uint8_t *scratch, uint8_t *dst);
void
balloon_sha256(size_t s_cost, size_t t_cost,
size_t passwd_length, const uint8_t *passwd,
size_t salt_length, const uint8_t *salt,
uint8_t *scratch, uint8_t *dst);
void
balloon_sha384(size_t s_cost, size_t t_cost,
size_t passwd_length, const uint8_t *passwd,
size_t salt_length, const uint8_t *salt,
uint8_t *scratch, uint8_t *dst);
void
balloon_sha512(size_t s_cost, size_t t_cost,
size_t passwd_length, const uint8_t *passwd,
size_t salt_length, const uint8_t *salt,
uint8_t *scratch, uint8_t *dst);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BALLOON_H_INCLUDED */

View File

@ -0,0 +1,110 @@
/* base16.h
Hex encoding and decoding, following spki conventions (i.e.
allowing whitespace between digits).
Copyright (C) 2002 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_BASE16_H_INCLUDED
#define NETTLE_BASE16_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define base16_encode_single nettle_base16_encode_single
#define base16_encode_update nettle_base16_encode_update
#define base16_decode_init nettle_base16_decode_init
#define base16_decode_single nettle_base16_decode_single
#define base16_decode_update nettle_base16_decode_update
#define base16_decode_final nettle_base16_decode_final
/* Base16 encoding */
/* Maximum length of output for base16_encode_update. */
#define BASE16_ENCODE_LENGTH(length) ((length) * 2)
/* Encodes a single byte. Always stores two digits in dst[0] and dst[1]. */
void
base16_encode_single(char *dst,
uint8_t src);
/* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */
void
base16_encode_update(char *dst,
size_t length,
const uint8_t *src);
/* Base16 decoding */
/* Maximum length of output for base16_decode_update. */
/* We have at most 4 buffered bits, and a total of (length + 1) * 4 bits. */
#define BASE16_DECODE_LENGTH(length) (((length) + 1) / 2)
struct base16_decode_ctx
{
unsigned char word; /* Leftover bits */
unsigned char bits; /* Number buffered bits */
};
void
base16_decode_init(struct base16_decode_ctx *ctx);
/* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
* errors. */
int
base16_decode_single(struct base16_decode_ctx *ctx,
uint8_t *dst,
char src);
/* Returns 1 on success, 0 on error. DST should point to an area of
* size at least BASE16_DECODE_LENGTH(length). The amount of data
* generated is returned in *DST_LENGTH. */
int
base16_decode_update(struct base16_decode_ctx *ctx,
size_t *dst_length,
uint8_t *dst,
size_t src_length,
const char *src);
/* Returns 1 on success. */
int
base16_decode_final(struct base16_decode_ctx *ctx);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BASE16_H_INCLUDED */

View File

@ -0,0 +1,172 @@
/* base64.h
Base-64 encoding and decoding.
Copyright (C) 2002 Niels Möller, Dan Egnor
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_BASE64_H_INCLUDED
#define NETTLE_BASE64_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define base64_encode_init nettle_base64_encode_init
#define base64url_encode_init nettle_base64url_encode_init
#define base64_encode_single nettle_base64_encode_single
#define base64_encode_update nettle_base64_encode_update
#define base64_encode_final nettle_base64_encode_final
#define base64_encode_raw nettle_base64_encode_raw
#define base64_encode_group nettle_base64_encode_group
#define base64_decode_init nettle_base64_decode_init
#define base64url_decode_init nettle_base64url_decode_init
#define base64_decode_single nettle_base64_decode_single
#define base64_decode_update nettle_base64_decode_update
#define base64_decode_final nettle_base64_decode_final
#define BASE64_BINARY_BLOCK_SIZE 3
#define BASE64_TEXT_BLOCK_SIZE 4
/* Base64 encoding */
/* Maximum length of output for base64_encode_update. NOTE: Doesn't
* include any padding that base64_encode_final may add. */
/* We have at most 4 buffered bits, and a total of (4 + length * 8) bits. */
#define BASE64_ENCODE_LENGTH(length) (((length) * 8 + 4)/6)
/* Maximum length of output generated by base64_encode_final. */
#define BASE64_ENCODE_FINAL_LENGTH 3
/* Exact length of output generated by base64_encode_raw, including
* padding. */
#define BASE64_ENCODE_RAW_LENGTH(length) ((((length) + 2)/3)*4)
struct base64_encode_ctx
{
const char *alphabet; /* Alphabet to use for encoding */
unsigned short word; /* Leftover bits */
unsigned char bits; /* Number of bits, always 0, 2, or 4. */
};
/* Initialize encoding context for base-64 */
void
base64_encode_init(struct base64_encode_ctx *ctx);
/* Initialize encoding context for URL safe alphabet, RFC 4648. */
void
base64url_encode_init(struct base64_encode_ctx *ctx);
/* Encodes a single byte. Returns amount of output (always 1 or 2). */
size_t
base64_encode_single(struct base64_encode_ctx *ctx,
char *dst,
uint8_t src);
/* Returns the number of output characters. DST should point to an
* area of size at least BASE64_ENCODE_LENGTH(length). */
size_t
base64_encode_update(struct base64_encode_ctx *ctx,
char *dst,
size_t length,
const uint8_t *src);
/* DST should point to an area of size at least
* BASE64_ENCODE_FINAL_LENGTH */
size_t
base64_encode_final(struct base64_encode_ctx *ctx,
char *dst);
/* Lower level functions */
/* Encodes a string in one go, including any padding at the end.
* Generates exactly BASE64_ENCODE_RAW_LENGTH(length) bytes of output.
* Supports overlapped operation, if src <= dst. FIXME: Use of overlap
* is deprecated, if needed there should be a separate public fucntion
* to do that.*/
void
base64_encode_raw(char *dst, size_t length, const uint8_t *src);
void
base64_encode_group(char *dst, uint32_t group);
/* Base64 decoding */
/* Maximum length of output for base64_decode_update. */
/* We have at most 6 buffered bits, and a total of (length + 1) * 6 bits. */
#define BASE64_DECODE_LENGTH(length) ((((length) + 1) * 6) / 8)
struct base64_decode_ctx
{
const signed char *table; /* Decoding table */
unsigned short word; /* Leftover bits */
unsigned char bits; /* Number buffered bits */
/* Number of padding characters encountered */
unsigned char padding;
};
/* Initialize decoding context for base-64 */
void
base64_decode_init(struct base64_decode_ctx *ctx);
/* Initialize encoding context for URL safe alphabet, RFC 4648. */
void
base64url_decode_init(struct base64_decode_ctx *ctx);
/* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
* errors. */
int
base64_decode_single(struct base64_decode_ctx *ctx,
uint8_t *dst,
char src);
/* Returns 1 on success, 0 on error. DST should point to an area of
* size at least BASE64_DECODE_LENGTH(length). The amount of data
* generated is returned in *DST_LENGTH. */
int
base64_decode_update(struct base64_decode_ctx *ctx,
size_t *dst_length,
uint8_t *dst,
size_t src_length,
const char *src);
/* Returns 1 on success. */
int
base64_decode_final(struct base64_decode_ctx *ctx);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BASE64_H_INCLUDED */

View File

@ -0,0 +1,129 @@
/* bignum.h
Bignum operations that are missing from gmp.
Copyright (C) 2001 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_BIGNUM_H_INCLUDED
#define NETTLE_BIGNUM_H_INCLUDED
#include "nettle-types.h"
/* For NETTLE_USE_MINI_GMP */
#include "version.h"
#if NETTLE_USE_MINI_GMP
# include "mini-gmp.h"
# define GMP_NUMB_MASK (~(mp_limb_t) 0)
/* Side-channel silent powm not available in mini-gmp. */
# define mpz_powm_sec mpz_powm
#else
# include <gmp.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Size needed for signed encoding, including extra sign byte if
* necessary. */
size_t
nettle_mpz_sizeinbase_256_s(const mpz_t x);
/* Size needed for unsigned encoding */
size_t
nettle_mpz_sizeinbase_256_u(const mpz_t x);
/* Writes an integer as length octets, using big endian byte order,
* and two's complement for negative numbers. */
void
nettle_mpz_get_str_256(size_t length, uint8_t *s, const mpz_t x);
/* Reads a big endian, two's complement, integer. */
void
nettle_mpz_set_str_256_s(mpz_t x,
size_t length, const uint8_t *s);
void
nettle_mpz_init_set_str_256_s(mpz_t x,
size_t length, const uint8_t *s);
/* Similar, but for unsigned format. These function don't interpret
* the most significant bit as the sign. */
void
nettle_mpz_set_str_256_u(mpz_t x,
size_t length, const uint8_t *s);
void
nettle_mpz_init_set_str_256_u(mpz_t x,
size_t length, const uint8_t *s);
/* Returns a uniformly distributed random number 0 <= x < 2^n */
void
nettle_mpz_random_size(mpz_t x,
void *ctx, nettle_random_func *random,
unsigned bits);
/* Returns a number x, almost uniformly random in the range
* 0 <= x < n. */
void
nettle_mpz_random(mpz_t x,
void *ctx, nettle_random_func *random,
const mpz_t n);
void
nettle_random_prime(mpz_t p, unsigned bits, int top_bits_set,
void *ctx, nettle_random_func *random,
void *progress_ctx, nettle_progress_func *progress);
/* sexp parsing */
struct sexp_iterator;
/* If LIMIT is non-zero, the number must be at most LIMIT bits.
* Implies sexp_iterator_next. */
int
nettle_mpz_set_sexp(mpz_t x, unsigned limit, struct sexp_iterator *i);
/* der parsing */
struct asn1_der_iterator;
int
nettle_asn1_der_get_bignum(struct asn1_der_iterator *iterator,
mpz_t x, unsigned max_bits);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BIGNUM_H_INCLUDED */

View File

@ -0,0 +1,106 @@
/* blowfish.h
Blowfish block cipher.
Copyright (C) 2014 Niels Möller
Copyright (C) 1998, 2001 FSF, Ray Dassen, Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_BLOWFISH_H_INCLUDED
#define NETTLE_BLOWFISH_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define blowfish_set_key nettle_blowfish_set_key
#define blowfish128_set_key nettle_blowfish128_set_key
#define blowfish_encrypt nettle_blowfish_encrypt
#define blowfish_decrypt nettle_blowfish_decrypt
#define blowfish_bcrypt_hash nettle_blowfish_bcrypt_hash
#define blowfish_bcrypt_verify nettle_blowfish_bcrypt_verify
#define BLOWFISH_BLOCK_SIZE 8
/* Variable key size between 64 and 448 bits. */
#define BLOWFISH_MIN_KEY_SIZE 8
#define BLOWFISH_MAX_KEY_SIZE 56
/* Default to 128 bits */
#define BLOWFISH_KEY_SIZE 16
#define BLOWFISH128_KEY_SIZE 16
#define _BLOWFISH_ROUNDS 16
#define BLOWFISH_BCRYPT_HASH_SIZE (60 + 1) /* Including null-terminator */
#define BLOWFISH_BCRYPT_BINSALT_SIZE 16 /* Binary string size */
struct blowfish_ctx
{
uint32_t s[4][256];
uint32_t p[_BLOWFISH_ROUNDS+2];
};
/* Returns 0 for weak keys, otherwise 1. */
int
blowfish_set_key(struct blowfish_ctx *ctx,
size_t length, const uint8_t *key);
int
blowfish128_set_key(struct blowfish_ctx *ctx, const uint8_t *key);
void
blowfish_encrypt(const struct blowfish_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
void
blowfish_decrypt(const struct blowfish_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
/* dst parameter must point to a buffer of minimally
* BLOWFISH_BCRYPT_HASH_SIZE bytes */
int
blowfish_bcrypt_hash(uint8_t *dst,
size_t lenkey, const uint8_t *key,
size_t lenscheme, const uint8_t *scheme,
int log2rounds,
const uint8_t *salt);
int
blowfish_bcrypt_verify(size_t lenkey, const uint8_t *key,
size_t lenhashed, const uint8_t *hashed);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BLOWFISH_H_INCLUDED */

View File

@ -0,0 +1,106 @@
/* buffer.h
A bare-bones string stream.
Copyright (C) 2002 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_BUFFER_H_INCLUDED
#define NETTLE_BUFFER_H_INCLUDED
#include "realloc.h"
#ifdef __cplusplus
extern "C" {
#endif
struct nettle_buffer
{
uint8_t *contents;
/* Allocated size */
size_t alloc;
void *realloc_ctx;
nettle_realloc_func *realloc;
/* Current size */
size_t size;
};
/* Initializes a buffer that uses plain realloc */
void
nettle_buffer_init(struct nettle_buffer *buffer);
void
nettle_buffer_init_realloc(struct nettle_buffer *buffer,
void *realloc_ctx,
nettle_realloc_func *realloc);
/* Initializes a buffer of fix size */
void
nettle_buffer_init_size(struct nettle_buffer *buffer,
size_t length, uint8_t *space);
void
nettle_buffer_clear(struct nettle_buffer *buffer);
/* Resets the buffer, without freeing the buffer space. */
void
nettle_buffer_reset(struct nettle_buffer *buffer);
int
nettle_buffer_grow(struct nettle_buffer *buffer,
size_t length);
#define NETTLE_BUFFER_PUTC(buffer, c) \
( (((buffer)->size < (buffer)->alloc) || nettle_buffer_grow((buffer), 1)) \
&& ((buffer)->contents[(buffer)->size++] = (c), 1) )
int
nettle_buffer_write(struct nettle_buffer *buffer,
size_t length, const uint8_t *data);
/* Like nettle_buffer_write, but instead of copying data to the
* buffer, it returns a pointer to the area where the caller can copy
* the data. The pointer is valid only until the next call that can
* reallocate the buffer. */
uint8_t *
nettle_buffer_space(struct nettle_buffer *buffer,
size_t length);
/* Copy the contents of SRC to the end of DST. */
int
nettle_buffer_copy(struct nettle_buffer *dst,
const struct nettle_buffer *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_BUFFER_H_INCLUDED */

View File

@ -0,0 +1,143 @@
/* camellia.h
Copyright (C) 2006,2007 NTT
(Nippon Telegraph and Telephone Corporation).
Copyright (C) 2010, 2013 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_CAMELLIA_H_INCLUDED
#define NETTLE_CAMELLIA_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define camellia128_set_encrypt_key nettle_camellia128_set_encrypt_key
#define camellia128_set_decrypt_key nettle_camellia_set_decrypt_key
#define camellia128_invert_key nettle_camellia128_invert_key
#define camellia128_crypt nettle_camellia128_crypt
#define camellia192_set_encrypt_key nettle_camellia192_set_encrypt_key
#define camellia192_set_decrypt_key nettle_camellia192_set_decrypt_key
#define camellia256_set_encrypt_key nettle_camellia256_set_encrypt_key
#define camellia256_set_decrypt_key nettle_camellia256_set_decrypt_key
#define camellia256_invert_key nettle_camellia256_invert_key
#define camellia256_crypt nettle_camellia256_crypt
#define CAMELLIA_BLOCK_SIZE 16
/* Valid key sizes are 128, 192 or 256 bits (16, 24 or 32 bytes) */
#define CAMELLIA128_KEY_SIZE 16
#define CAMELLIA192_KEY_SIZE 24
#define CAMELLIA256_KEY_SIZE 32
/* For 128-bit keys, there are 18 regular rounds, pre- and
post-whitening, and two FL and FLINV rounds, using a total of 26
subkeys, each of 64 bit. For 192- and 256-bit keys, there are 6
additional regular rounds and one additional FL and FLINV, using a
total of 34 subkeys. */
/* The clever combination of subkeys imply one of the pre- and
post-whitening keys is folded with the round keys, so that subkey
#1 and the last one (#25 or #33) is not used. The result is that we
have only 24 or 32 subkeys at the end of key setup. */
#define _CAMELLIA128_NKEYS 24
#define _CAMELLIA256_NKEYS 32
struct camellia128_ctx
{
uint64_t keys[_CAMELLIA128_NKEYS];
};
void
camellia128_set_encrypt_key(struct camellia128_ctx *ctx,
const uint8_t *key);
void
camellia128_set_decrypt_key(struct camellia128_ctx *ctx,
const uint8_t *key);
void
camellia128_invert_key(struct camellia128_ctx *dst,
const struct camellia128_ctx *src);
void
camellia128_crypt(const struct camellia128_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
struct camellia256_ctx
{
uint64_t keys[_CAMELLIA256_NKEYS];
};
void
camellia256_set_encrypt_key(struct camellia256_ctx *ctx,
const uint8_t *key);
void
camellia256_set_decrypt_key(struct camellia256_ctx *ctx,
const uint8_t *key);
void
camellia256_invert_key(struct camellia256_ctx *dst,
const struct camellia256_ctx *src);
void
camellia256_crypt(const struct camellia256_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
/* camellia192 is the same as camellia256, except for the key
schedule. */
/* Slightly ugly with a #define on a struct tag, since it might cause
surprises if also used as a name of a variable. */
#define camellia192_ctx camellia256_ctx
void
camellia192_set_encrypt_key(struct camellia256_ctx *ctx,
const uint8_t *key);
void
camellia192_set_decrypt_key(struct camellia256_ctx *ctx,
const uint8_t *key);
#define camellia192_invert_key camellia256_invert_key
#define camellia192_crypt camellia256_crypt
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CAMELLIA_H_INCLUDED */

View File

@ -0,0 +1,86 @@
/* cast128.h
The CAST-128 block cipher.
Copyright (C) 2001, 2014 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_CAST128_H_INCLUDED
#define NETTLE_CAST128_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define cast5_set_key nettle_cast5_set_key
#define cast128_set_key nettle_cast128_set_key
#define cast128_encrypt nettle_cast128_encrypt
#define cast128_decrypt nettle_cast128_decrypt
#define CAST128_BLOCK_SIZE 8
/* Variable key size between 40 and 128. */
#define CAST5_MIN_KEY_SIZE 5
#define CAST5_MAX_KEY_SIZE 16
#define CAST128_KEY_SIZE 16
struct cast128_ctx
{
unsigned rounds; /* Number of rounds to use, 12 or 16 */
/* Expanded key, rotations (5 bits only) and 32-bit masks. */
unsigned char Kr[16];
uint32_t Km[16];
};
/* Using variable key size. */
void
cast5_set_key(struct cast128_ctx *ctx,
size_t length, const uint8_t *key);
void
cast128_set_key(struct cast128_ctx *ctx, const uint8_t *key);
void
cast128_encrypt(const struct cast128_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
void
cast128_decrypt(const struct cast128_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CAST128_H_INCLUDED */

View File

@ -0,0 +1,102 @@
/* cbc.h
Cipher block chaining mode.
Copyright (C) 2001 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_CBC_H_INCLUDED
#define NETTLE_CBC_H_INCLUDED
#include "nettle-types.h"
#include "aes.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define cbc_encrypt nettle_cbc_encrypt
#define cbc_decrypt nettle_cbc_decrypt
#define cbc_aes128_encrypt nettle_cbc_aes128_encrypt
#define cbc_aes192_encrypt nettle_cbc_aes192_encrypt
#define cbc_aes256_encrypt nettle_cbc_aes256_encrypt
void
cbc_encrypt(const void *ctx, nettle_cipher_func *f,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src);
void
cbc_decrypt(const void *ctx, nettle_cipher_func *f,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src);
#define CBC_CTX(type, size) \
{ type ctx; uint8_t iv[size]; }
#define CBC_SET_IV(ctx, data) \
memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
#define CBC_ENCRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0)) \
: cbc_encrypt((void *) &(self)->ctx, \
(nettle_cipher_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
#define CBC_DECRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0)) \
: cbc_decrypt((void *) &(self)->ctx, \
(nettle_cipher_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
void
cbc_aes128_encrypt(const struct aes128_ctx *ctx, uint8_t *iv,
size_t length, uint8_t *dst, const uint8_t *src);
void
cbc_aes192_encrypt(const struct aes192_ctx *ctx, uint8_t *iv,
size_t length, uint8_t *dst, const uint8_t *src);
void
cbc_aes256_encrypt(const struct aes256_ctx *ctx, uint8_t *iv,
size_t length, uint8_t *dst, const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CBC_H_INCLUDED */

View File

@ -0,0 +1,305 @@
/* ccm.h
Counter with CBC-MAC mode, specified by NIST,
http://csrc.nist.gov/publications/nistpubs/800-38C/SP800-38C_updated-July20_2007.pdf
Copyright (C) 2014 Exegin Technologies Limited
Copyright (C) 2014 Owen Kirby
Contributed to GNU Nettle by Owen Kirby
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
/* NIST SP800-38C doesn't specify the particular formatting and
* counter generation algorithm for CCM, but it does include an
* example algorithm. This example has become the de-factor standard,
* and has been adopted by both the IETF and IEEE across a wide
* variety of protocols.
*/
#ifndef NETTLE_CCM_H_INCLUDED
#define NETTLE_CCM_H_INCLUDED
#include "aes.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define ccm_set_nonce nettle_ccm_set_nonce
#define ccm_update nettle_ccm_update
#define ccm_encrypt nettle_ccm_encrypt
#define ccm_decrypt nettle_ccm_decrypt
#define ccm_digest nettle_ccm_digest
#define ccm_encrypt_message nettle_ccm_encrypt_message
#define ccm_decrypt_message nettle_ccm_decrypt_message
#define ccm_aes128_set_key nettle_ccm_aes128_set_key
#define ccm_aes128_set_nonce nettle_ccm_aes128_set_nonce
#define ccm_aes128_update nettle_ccm_aes128_update
#define ccm_aes128_encrypt nettle_ccm_aes128_encrypt
#define ccm_aes128_decrypt nettle_ccm_aes128_decrypt
#define ccm_aes128_digest nettle_ccm_aes128_digest
#define ccm_aes128_encrypt_message nettle_ccm_aes128_encrypt_message
#define ccm_aes128_decrypt_message nettle_ccm_aes128_decrypt_message
#define ccm_aes192_set_key nettle_ccm_aes192_set_key
#define ccm_aes192_set_nonce nettle_ccm_aes192_set_nonce
#define ccm_aes192_update nettle_ccm_aes192_update
#define ccm_aes192_encrypt nettle_ccm_aes192_encrypt
#define ccm_aes192_decrypt nettle_ccm_aes192_decrypt
#define ccm_aes192_digest nettle_ccm_aes192_digest
#define ccm_aes192_encrypt_message nettle_ccm_aes192_encrypt_message
#define ccm_aes192_decrypt_message nettle_ccm_aes192_decrypt_message
#define ccm_aes256_set_key nettle_ccm_aes256_set_key
#define ccm_aes256_set_nonce nettle_ccm_aes256_set_nonce
#define ccm_aes256_update nettle_ccm_aes256_update
#define ccm_aes256_encrypt nettle_ccm_aes256_encrypt
#define ccm_aes256_decrypt nettle_ccm_aes256_decrypt
#define ccm_aes256_digest nettle_ccm_aes256_digest
#define ccm_aes256_encrypt_message nettle_ccm_aes256_encrypt_message
#define ccm_aes256_decrypt_message nettle_ccm_aes256_decrypt_message
/* For CCM, the block size of the block cipher shall be 128 bits. */
#define CCM_BLOCK_SIZE 16
#define CCM_DIGEST_SIZE 16
#define CCM_MIN_NONCE_SIZE 7
#define CCM_MAX_NONCE_SIZE 14
/* Maximum cleartext message size, as a function of the nonce size N.
The length field is L octets, with L = 15 - N, and then the maximum
size M = 2^{8L} - 1. */
#define CCM_MAX_MSG_SIZE(N) \
((sizeof(size_t) + (N) <= 15) \
? ~(size_t) 0 \
: ((size_t) 1 << (8*(15 - N))) - 1)
/* Per-message state */
struct ccm_ctx {
union nettle_block16 ctr; /* Counter for CTR encryption. */
union nettle_block16 tag; /* CBC-MAC message tag. */
/* Length of data processed by the CBC-MAC modulus the block size */
unsigned int blength;
};
/*
* CCM mode requires the adata and message lengths when building the IV, which
* prevents streaming processing and it incompatible with the AEAD API.
*/
void
ccm_set_nonce(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
size_t noncelen, const uint8_t *nonce,
size_t authlen, size_t msglen, size_t taglen);
void
ccm_update(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
size_t length, const uint8_t *data);
void
ccm_encrypt(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src);
void
ccm_decrypt(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src);
void
ccm_digest(struct ccm_ctx *ctx, const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *digest);
/*
* All-in-one encryption and decryption API:
* tlength = sizeof(digest)
* mlength = sizeof(cleartext)
* clength = sizeof(ciphertext) = mlength + tlength
*
* The ciphertext will contain the encrypted payload with the message digest
* appended to the end.
*/
void
ccm_encrypt_message(const void *cipher, nettle_cipher_func *f,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t tlength,
size_t clength, uint8_t *dst, const uint8_t *src);
/*
* The decryption function will write the plaintext to dst and parse the digest
* from the final tlength bytes of the ciphertext. If the digest matched the
* value computed during decryption then this will return 1, or it will return
* 0 if the digest was invalid.
*/
int
ccm_decrypt_message(const void *cipher, nettle_cipher_func *f,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t tlength,
size_t mlength, uint8_t *dst, const uint8_t *src);
/* CCM Mode with AES-128 */
struct ccm_aes128_ctx {
struct ccm_ctx ccm;
struct aes128_ctx cipher;
};
void
ccm_aes128_set_key(struct ccm_aes128_ctx *ctx, const uint8_t *key);
void
ccm_aes128_set_nonce(struct ccm_aes128_ctx *ctx,
size_t length, const uint8_t *nonce,
size_t authlen, size_t msglen, size_t taglen);
void
ccm_aes128_update (struct ccm_aes128_ctx *ctx,
size_t length, const uint8_t *data);
void
ccm_aes128_encrypt(struct ccm_aes128_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
ccm_aes128_decrypt(struct ccm_aes128_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
ccm_aes128_digest(struct ccm_aes128_ctx *ctx,
size_t length, uint8_t *digest);
/* FIXME: For next API/ABI break: first argument should be const
struct aes128_ctx *, and similarly for other ccm_*_message
functions below. */
void
ccm_aes128_encrypt_message(struct ccm_aes128_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t tlength,
size_t clength, uint8_t *dst, const uint8_t *src);
int
ccm_aes128_decrypt_message(struct ccm_aes128_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t tlength,
size_t mlength, uint8_t *dst, const uint8_t *src);
struct ccm_aes192_ctx {
struct ccm_ctx ccm;
struct aes192_ctx cipher;
};
/* CCM Mode with AES-192 */
void
ccm_aes192_set_key(struct ccm_aes192_ctx *ctx, const uint8_t *key);
void
ccm_aes192_set_nonce(struct ccm_aes192_ctx *ctx,
size_t length, const uint8_t *nonce,
size_t authlen, size_t msglen, size_t taglen);
void
ccm_aes192_update(struct ccm_aes192_ctx *ctx,
size_t length, const uint8_t *data);
void
ccm_aes192_encrypt(struct ccm_aes192_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
ccm_aes192_decrypt(struct ccm_aes192_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
ccm_aes192_digest(struct ccm_aes192_ctx *ctx,
size_t length, uint8_t *digest);
void
ccm_aes192_encrypt_message(struct ccm_aes192_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t tlength,
size_t clength, uint8_t *dst, const uint8_t *src);
int
ccm_aes192_decrypt_message(struct ccm_aes192_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t tlength,
size_t mlength, uint8_t *dst, const uint8_t *src);
/* CCM Mode with AES-256 */
struct ccm_aes256_ctx {
struct ccm_ctx ccm;
struct aes256_ctx cipher;
};
void
ccm_aes256_set_key(struct ccm_aes256_ctx *ctx, const uint8_t *key);
void
ccm_aes256_set_nonce(struct ccm_aes256_ctx *ctx,
size_t length, const uint8_t *nonce,
size_t authlen, size_t msglen, size_t taglen);
void
ccm_aes256_update(struct ccm_aes256_ctx *ctx,
size_t length, const uint8_t *data);
void
ccm_aes256_encrypt(struct ccm_aes256_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
ccm_aes256_decrypt(struct ccm_aes256_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
ccm_aes256_digest(struct ccm_aes256_ctx *ctx,
size_t length, uint8_t *digest);
void
ccm_aes256_encrypt_message(struct ccm_aes256_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t tlength,
size_t clength, uint8_t *dst, const uint8_t *src);
int
ccm_aes256_decrypt_message(struct ccm_aes256_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t tlength,
size_t mlength, uint8_t *dst, const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CCM_H_INCLUDED */

View File

@ -0,0 +1,122 @@
/* cfb.h
Cipher feedback mode.
Copyright (C) 2015, 2017 Dmitry Eremin-Solenikov
Copyright (C) 2001 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_CFB_H_INCLUDED
#define NETTLE_CFB_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define cfb_encrypt nettle_cfb_encrypt
#define cfb_decrypt nettle_cfb_decrypt
#define cfb8_encrypt nettle_cfb8_encrypt
#define cfb8_decrypt nettle_cfb8_decrypt
void
cfb_encrypt(const void *ctx, nettle_cipher_func *f,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src);
void
cfb_decrypt(const void *ctx, nettle_cipher_func *f,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src);
void
cfb8_encrypt(const void *ctx, nettle_cipher_func *f,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src);
void
cfb8_decrypt(const void *ctx, nettle_cipher_func *f,
size_t block_size, uint8_t *iv,
size_t length, uint8_t *dst,
const uint8_t *src);
#define CFB_CTX(type, size) \
{ type ctx; uint8_t iv[size]; }
#define CFB_SET_IV(ctx, data) \
memcpy((ctx)->iv, (data), sizeof((ctx)->iv))
#define CFB8_CTX CFB_CTX
#define CFB8_SET_IV CFB_SET_IV
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
#define CFB_ENCRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0)) \
: cfb_encrypt((void *) &(self)->ctx, \
(nettle_cipher_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
#define CFB_DECRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0)) \
: cfb_decrypt((void *) &(self)->ctx, \
(nettle_cipher_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
#define CFB8_ENCRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0)) \
: cfb8_encrypt((void *) &(self)->ctx, \
(nettle_cipher_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
#define CFB8_DECRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0)) \
: cfb8_decrypt((void *) &(self)->ctx, \
(nettle_cipher_func *) (f), \
sizeof((self)->iv), (self)->iv, \
(length), (dst), (src)))
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CFB_H_INCLUDED */

View File

@ -0,0 +1,98 @@
/* chacha-poly1305.h
AEAD mechanism based on chacha and poly1305.
See draft-agl-tls-chacha20poly1305-04.
Copyright (C) 2014 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_CHACHA_POLY1305_H_INCLUDED
#define NETTLE_CHACHA_POLY1305_H_INCLUDED
#include "chacha.h"
#include "poly1305.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define chacha_poly1305_set_key nettle_chacha_poly1305_set_key
#define chacha_poly1305_set_nonce nettle_chacha_poly1305_set_nonce
#define chacha_poly1305_update nettle_chacha_poly1305_update
#define chacha_poly1305_decrypt nettle_chacha_poly1305_decrypt
#define chacha_poly1305_encrypt nettle_chacha_poly1305_encrypt
#define chacha_poly1305_digest nettle_chacha_poly1305_digest
#define CHACHA_POLY1305_BLOCK_SIZE 64
/* FIXME: Any need for 128-bit variant? */
#define CHACHA_POLY1305_KEY_SIZE 32
#define CHACHA_POLY1305_NONCE_SIZE CHACHA_NONCE96_SIZE
#define CHACHA_POLY1305_DIGEST_SIZE 16
struct chacha_poly1305_ctx
{
struct chacha_ctx chacha;
struct poly1305_ctx poly1305;
union nettle_block16 s;
uint64_t auth_size;
uint64_t data_size;
/* poly1305 block */
uint8_t block[POLY1305_BLOCK_SIZE];
unsigned index;
};
void
chacha_poly1305_set_key (struct chacha_poly1305_ctx *ctx,
const uint8_t *key);
void
chacha_poly1305_set_nonce (struct chacha_poly1305_ctx *ctx,
const uint8_t *nonce);
void
chacha_poly1305_update (struct chacha_poly1305_ctx *ctx,
size_t length, const uint8_t *data);
void
chacha_poly1305_encrypt (struct chacha_poly1305_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
chacha_poly1305_decrypt (struct chacha_poly1305_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
chacha_poly1305_digest (struct chacha_poly1305_ctx *ctx,
size_t length, uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CHACHA_POLY1305_H_INCLUDED */

View File

@ -0,0 +1,107 @@
/* chacha.h
The ChaCha stream cipher.
Copyright (C) 2013 Joachim Strömbergson
Copyright (C) 2012 Simon Josefsson
Copyright (C) 2014 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_CHACHA_H_INCLUDED
#define NETTLE_CHACHA_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define chacha_set_key nettle_chacha_set_key
#define chacha_set_nonce nettle_chacha_set_nonce
#define chacha_set_nonce96 nettle_chacha_set_nonce96
#define chacha_set_counter nettle_chacha_set_counter
#define chacha_set_counter32 nettle_chacha_set_counter32
#define chacha_crypt nettle_chacha_crypt
#define chacha_crypt32 nettle_chacha_crypt32
/* Currently, only 256-bit keys are supported. */
#define CHACHA_KEY_SIZE 32
#define CHACHA_BLOCK_SIZE 64
#define CHACHA_NONCE_SIZE 8
#define CHACHA_NONCE96_SIZE 12
#define CHACHA_COUNTER_SIZE 8
#define CHACHA_COUNTER32_SIZE 4
#define _CHACHA_STATE_LENGTH 16
struct chacha_ctx
{
/* Indices 0-3 holds a constant (SIGMA or TAU).
Indices 4-11 holds the key.
Indices 12-13 holds the block counter.
Indices 14-15 holds the IV:
This creates the state matrix:
C C C C
K K K K
K K K K
B B I I
*/
uint32_t state[_CHACHA_STATE_LENGTH];
};
void
chacha_set_key(struct chacha_ctx *ctx, const uint8_t *key);
void
chacha_set_nonce(struct chacha_ctx *ctx, const uint8_t *nonce);
void
chacha_set_nonce96(struct chacha_ctx *ctx, const uint8_t *nonce);
void
chacha_set_counter(struct chacha_ctx *ctx, const uint8_t *counter);
void
chacha_set_counter32(struct chacha_ctx *ctx, const uint8_t *counter);
void
chacha_crypt(struct chacha_ctx *ctx, size_t length,
uint8_t *dst, const uint8_t *src);
void
chacha_crypt32(struct chacha_ctx *ctx, size_t length,
uint8_t *dst, const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CHACHA_H_INCLUDED */

View File

@ -0,0 +1,237 @@
/* cmac.h
CMAC mode, as specified in RFC4493
Copyright (C) 2017 Red Hat, Inc.
Contributed by Nikos Mavrogiannopoulos
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_CMAC_H_INCLUDED
#define NETTLE_CMAC_H_INCLUDED
#include "aes.h"
#include "des.h"
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
#define CMAC128_DIGEST_SIZE 16
#define CMAC64_DIGEST_SIZE 8
#define cmac128_set_key nettle_cmac128_set_key
#define cmac128_init nettle_cmac128_init
#define cmac128_update nettle_cmac128_update
#define cmac128_digest nettle_cmac128_digest
#define cmac_aes128_set_key nettle_cmac_aes128_set_key
#define cmac_aes128_update nettle_cmac_aes128_update
#define cmac_aes128_digest nettle_cmac_aes128_digest
#define cmac_aes256_set_key nettle_cmac_aes256_set_key
#define cmac_aes256_update nettle_cmac_aes256_update
#define cmac_aes256_digest nettle_cmac_aes256_digest
#define cmac64_set_key nettle_cmac64_set_key
#define cmac64_init nettle_cmac64_init
#define cmac64_update nettle_cmac64_update
#define cmac64_digest nettle_cmac64_digest
#define cmac_des3_set_key nettle_cmac_des3_set_key
#define cmac_des3_update nettle_cmac_des3_update
#define cmac_des3_digest nettle_cmac_des3_digest
struct cmac128_key
{
union nettle_block16 K1;
union nettle_block16 K2;
};
struct cmac128_ctx
{
/* MAC state */
union nettle_block16 X;
/* Block buffer */
union nettle_block16 block;
size_t index;
};
struct cmac64_key
{
union nettle_block8 K1;
union nettle_block8 K2;
};
struct cmac64_ctx
{
/* MAC state */
union nettle_block8 X;
/* Block buffer */
union nettle_block8 block;
size_t index;
};
void
cmac128_set_key(struct cmac128_key *key, const void *cipher,
nettle_cipher_func *encrypt);
void
cmac128_init(struct cmac128_ctx *ctx);
void
cmac128_update(struct cmac128_ctx *ctx, const void *cipher,
nettle_cipher_func *encrypt,
size_t msg_len, const uint8_t *msg);
void
cmac128_digest(struct cmac128_ctx *ctx, const struct cmac128_key *key,
const void *cipher, nettle_cipher_func *encrypt,
unsigned length, uint8_t *digest);
#define CMAC128_CTX(type) \
{ struct cmac128_key key; struct cmac128_ctx ctx; type cipher; }
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
#define CMAC128_SET_KEY(self, set_key, encrypt, cmac_key) \
do { \
(set_key)(&(self)->cipher, (cmac_key)); \
if (0) (encrypt)(&(self)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0); \
cmac128_set_key(&(self)->key, &(self)->cipher, \
(nettle_cipher_func *) (encrypt)); \
cmac128_init(&(self)->ctx); \
} while (0)
#define CMAC128_UPDATE(self, encrypt, length, src) \
(0 ? (encrypt)(&(self)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0) \
: cmac128_update(&(self)->ctx, &(self)->cipher, \
(nettle_cipher_func *)encrypt, \
(length), (src)))
#define CMAC128_DIGEST(self, encrypt, length, digest) \
(0 ? (encrypt)(&(self)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0) \
: cmac128_digest(&(self)->ctx, &(self)->key, \
&(self)->cipher, \
(nettle_cipher_func *) (encrypt), \
(length), (digest)))
void
cmac64_set_key(struct cmac64_key *key, const void *cipher,
nettle_cipher_func *encrypt);
void
cmac64_init(struct cmac64_ctx *ctx);
void
cmac64_update(struct cmac64_ctx *ctx, const void *cipher,
nettle_cipher_func *encrypt,
size_t msg_len, const uint8_t *msg);
void
cmac64_digest(struct cmac64_ctx *ctx, const struct cmac64_key *key,
const void *cipher, nettle_cipher_func *encrypt,
unsigned length, uint8_t *digest);
#define CMAC64_CTX(type) \
{ struct cmac64_key key; struct cmac64_ctx ctx; type cipher; }
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
#define CMAC64_SET_KEY(self, set_key, encrypt, cmac_key) \
do { \
(set_key)(&(self)->cipher, (cmac_key)); \
if (0) (encrypt)(&(self)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0); \
cmac64_set_key(&(self)->key, &(self)->cipher, \
(nettle_cipher_func *) (encrypt)); \
cmac64_init(&(self)->ctx); \
} while (0)
#define CMAC64_UPDATE(self, encrypt, length, src) \
(0 ? (encrypt)(&(self)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0) \
: cmac64_update(&(self)->ctx, &(self)->cipher, \
(nettle_cipher_func *)encrypt, \
(length), (src)))
#define CMAC64_DIGEST(self, encrypt, length, digest) \
(0 ? (encrypt)(&(self)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0) \
: cmac64_digest(&(self)->ctx, &(self)->key, \
&(self)->cipher, \
(nettle_cipher_func *) (encrypt), \
(length), (digest)))
struct cmac_aes128_ctx CMAC128_CTX(struct aes128_ctx);
void
cmac_aes128_set_key(struct cmac_aes128_ctx *ctx, const uint8_t *key);
void
cmac_aes128_update(struct cmac_aes128_ctx *ctx,
size_t length, const uint8_t *data);
void
cmac_aes128_digest(struct cmac_aes128_ctx *ctx,
size_t length, uint8_t *digest);
struct cmac_aes256_ctx CMAC128_CTX(struct aes256_ctx);
void
cmac_aes256_set_key(struct cmac_aes256_ctx *ctx, const uint8_t *key);
void
cmac_aes256_update(struct cmac_aes256_ctx *ctx,
size_t length, const uint8_t *data);
void
cmac_aes256_digest(struct cmac_aes256_ctx *ctx,
size_t length, uint8_t *digest);
struct cmac_des3_ctx CMAC64_CTX(struct des3_ctx);
void
cmac_des3_set_key(struct cmac_des3_ctx *ctx, const uint8_t *key);
void
cmac_des3_update(struct cmac_des3_ctx *ctx,
size_t length, const uint8_t *data);
void
cmac_des3_digest(struct cmac_des3_ctx *ctx,
size_t length, uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* CMAC_H_INCLUDED */

View File

@ -0,0 +1,71 @@
/* ctr.h
Counter mode, using an network byte order incremented counter,
matching the testcases of NIST 800-38A.
Copyright (C) 2005 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_CTR_H_INCLUDED
#define NETTLE_CTR_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define ctr_crypt nettle_ctr_crypt
void
ctr_crypt(const void *ctx, nettle_cipher_func *f,
size_t block_size, uint8_t *ctr,
size_t length, uint8_t *dst,
const uint8_t *src);
#define CTR_CTX(type, size) \
{ type ctx; uint8_t ctr[size]; }
#define CTR_SET_COUNTER(ctx, data) \
memcpy((ctx)->ctr, (data), sizeof((ctx)->ctr))
#define CTR_CRYPT(self, f, length, dst, src) \
(0 ? ((f)(&(self)->ctx, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0)) \
: ctr_crypt((void *) &(self)->ctx, \
(nettle_cipher_func *) (f), \
sizeof((self)->ctr), (self)->ctr, \
(length), (dst), (src)))
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CTR_H_INCLUDED */

View File

@ -0,0 +1,60 @@
/* curve25519.h
Copyright (C) 2014 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_CURVE25519_H
#define NETTLE_CURVE25519_H
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define curve25519_mul_g nettle_curve25519_mul_g
#define curve25519_mul nettle_curve25519_mul
#define CURVE25519_SIZE 32
/* Indicates that curve25519_mul conforms to RFC 7748. */
#define NETTLE_CURVE25519_RFC7748 1
void
curve25519_mul_g (uint8_t *q, const uint8_t *n);
void
curve25519_mul (uint8_t *q, const uint8_t *n, const uint8_t *p);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CURVE25519_H */

View File

@ -0,0 +1,58 @@
/* curve448.h
Copyright (C) 2017 Daiki Ueno
Copyright (C) 2017 Red Hat, Inc.
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_CURVE448_H
#define NETTLE_CURVE448_H
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define curve448_mul_g nettle_curve448_mul_g
#define curve448_mul nettle_curve448_mul
#define CURVE448_SIZE 56
void
curve448_mul_g (uint8_t *q, const uint8_t *n);
void
curve448_mul (uint8_t *q, const uint8_t *n, const uint8_t *p);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_CURVE448_H */

View File

@ -0,0 +1,120 @@
/* des.h
The des block cipher. And triple des.
Copyright (C) 1992 Dana L. How
Copyright (C) 2001 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
/*
* des - fast & portable DES encryption & decryption.
* Copyright (C) 1992 Dana L. How
* Please see the file `../lib/descore.README' for the complete copyright
* notice.
*
* Slightly edited by Niels Möller, 1997
*/
#ifndef NETTLE_DES_H_INCLUDED
#define NETTLE_DES_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Namespace mangling */
#define des_set_key nettle_des_set_key
#define des_encrypt nettle_des_encrypt
#define des_decrypt nettle_des_decrypt
#define des_check_parity nettle_des_check_parity
#define des_fix_parity nettle_des_fix_parity
#define des3_set_key nettle_des3_set_key
#define des3_encrypt nettle_des3_encrypt
#define des3_decrypt nettle_des3_decrypt
#define DES_KEY_SIZE 8
#define DES_BLOCK_SIZE 8
/* Expanded key length */
#define _DES_KEY_LENGTH 32
struct des_ctx
{
uint32_t key[_DES_KEY_LENGTH];
};
/* Returns 1 for good keys and 0 for weak keys. */
int
des_set_key(struct des_ctx *ctx, const uint8_t *key);
void
des_encrypt(const struct des_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
void
des_decrypt(const struct des_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
int
des_check_parity(size_t length, const uint8_t *key);
void
des_fix_parity(size_t length, uint8_t *dst,
const uint8_t *src);
#define DES3_KEY_SIZE 24
#define DES3_BLOCK_SIZE DES_BLOCK_SIZE
struct des3_ctx
{
struct des_ctx des[3];
};
/* Returns 1 for good keys and 0 for weak keys. */
int
des3_set_key(struct des3_ctx *ctx, const uint8_t *key);
void
des3_encrypt(const struct des3_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
void
des3_decrypt(const struct des3_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_DES_H_INCLUDED */

View File

@ -0,0 +1,183 @@
/* dsa-compat.h
Old DSA publickey interface.
Copyright (C) 2002, 2013, 2014 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_DSA_COMPAT_H_INCLUDED
#define NETTLE_DSA_COMPAT_H_INCLUDED
#include "dsa.h"
#include "sha1.h"
#include "sha2.h"
/* Name mangling */
#define dsa_public_key_init nettle_dsa_public_key_init
#define dsa_public_key_clear nettle_dsa_public_key_clear
#define dsa_private_key_init nettle_dsa_private_key_init
#define dsa_private_key_clear nettle_dsa_private_key_clear
#define dsa_sha1_sign nettle_dsa_sha1_sign
#define dsa_sha1_verify nettle_dsa_sha1_verify
#define dsa_sha256_sign nettle_dsa_sha256_sign
#define dsa_sha256_verify nettle_dsa_sha256_verify
#define dsa_sha1_sign_digest nettle_dsa_sha1_sign_digest
#define dsa_sha1_verify_digest nettle_dsa_sha1_verify_digest
#define dsa_sha256_sign_digest nettle_dsa_sha256_sign_digest
#define dsa_sha256_verify_digest nettle_dsa_sha256_verify_digest
#define dsa_compat_generate_keypair nettle_dsa_compat_generate_keypair
/* Switch meaning of dsa_generate_keypair */
#undef dsa_generate_keypair
#define dsa_generate_keypair nettle_dsa_compat_generate_keypair
#ifdef __cplusplus
extern "C" {
#endif
struct dsa_public_key
{
/* Same as struct dsa_params, but can't use that struct here without
breaking backwards compatibility. Layout must be identical, since
this is cast to a struct dsa_param pointer for calling _dsa_sign
and _dsa_verify */
mpz_t p;
mpz_t q;
mpz_t g;
/* Public value */
mpz_t y;
};
struct dsa_private_key
{
/* Unlike an rsa public key, private key operations will need both
* the private and the public information. */
mpz_t x;
};
/* Signing a message works as follows:
*
* Store the private key in a dsa_private_key struct.
*
* Initialize a hashing context, by callling
* sha1_init
*
* Hash the message by calling
* sha1_update
*
* Create the signature by calling
* dsa_sha1_sign
*
* The signature is represented as a struct dsa_signature. This call also
* resets the hashing context.
*
* When done with the key and signature, don't forget to call
* dsa_signature_clear.
*/
/* Calls mpz_init to initialize bignum storage. */
void
dsa_public_key_init(struct dsa_public_key *key);
/* Calls mpz_clear to deallocate bignum storage. */
void
dsa_public_key_clear(struct dsa_public_key *key);
/* Calls mpz_init to initialize bignum storage. */
void
dsa_private_key_init(struct dsa_private_key *key);
/* Calls mpz_clear to deallocate bignum storage. */
void
dsa_private_key_clear(struct dsa_private_key *key);
int
dsa_sha1_sign(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx, nettle_random_func *random,
struct sha1_ctx *hash,
struct dsa_signature *signature);
int
dsa_sha256_sign(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx, nettle_random_func *random,
struct sha256_ctx *hash,
struct dsa_signature *signature);
int
dsa_sha1_verify(const struct dsa_public_key *key,
struct sha1_ctx *hash,
const struct dsa_signature *signature);
int
dsa_sha256_verify(const struct dsa_public_key *key,
struct sha256_ctx *hash,
const struct dsa_signature *signature);
int
dsa_sha1_sign_digest(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx, nettle_random_func *random,
const uint8_t *digest,
struct dsa_signature *signature);
int
dsa_sha256_sign_digest(const struct dsa_public_key *pub,
const struct dsa_private_key *key,
void *random_ctx, nettle_random_func *random,
const uint8_t *digest,
struct dsa_signature *signature);
int
dsa_sha1_verify_digest(const struct dsa_public_key *key,
const uint8_t *digest,
const struct dsa_signature *signature);
int
dsa_sha256_verify_digest(const struct dsa_public_key *key,
const uint8_t *digest,
const struct dsa_signature *signature);
/* Key generation */
int
dsa_generate_keypair(struct dsa_public_key *pub,
struct dsa_private_key *key,
void *random_ctx, nettle_random_func *random,
void *progress_ctx, nettle_progress_func *progress,
unsigned p_bits, unsigned q_bits);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_DSA_COMPAT_H_INCLUDED */

View File

@ -0,0 +1,210 @@
/* dsa.h
The DSA publickey algorithm.
Copyright (C) 2002, 2013, 2014 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_DSA_H_INCLUDED
#define NETTLE_DSA_H_INCLUDED
#include "nettle-types.h"
#include "bignum.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define dsa_params_init nettle_dsa_params_init
#define dsa_params_clear nettle_dsa_params_clear
#define dsa_signature_init nettle_dsa_signature_init
#define dsa_signature_clear nettle_dsa_signature_clear
#define dsa_sign nettle_dsa_sign
#define dsa_verify nettle_dsa_verify
#define dsa_generate_params nettle_dsa_generate_params
#define dsa_generate_keypair nettle_dsa_generate_keypair
#define dsa_signature_from_sexp nettle_dsa_signature_from_sexp
#define dsa_keypair_to_sexp nettle_dsa_keypair_to_sexp
#define dsa_keypair_from_sexp_alist nettle_dsa_keypair_from_sexp_alist
#define dsa_sha1_keypair_from_sexp nettle_dsa_sha1_keypair_from_sexp
#define dsa_sha256_keypair_from_sexp nettle_dsa_sha256_keypair_from_sexp
#define dsa_params_from_der_iterator nettle_dsa_params_from_der_iterator
#define dsa_public_key_from_der_iterator nettle_dsa_public_key_from_der_iterator
#define dsa_openssl_private_key_from_der_iterator nettle_dsa_openssl_private_key_from_der_iterator
#define dsa_openssl_private_key_from_der nettle_openssl_provate_key_from_der
/* For FIPS approved parameters */
#define DSA_SHA1_MIN_P_BITS 512
#define DSA_SHA1_Q_OCTETS 20
#define DSA_SHA1_Q_BITS 160
#define DSA_SHA256_MIN_P_BITS 1024
#define DSA_SHA256_Q_OCTETS 32
#define DSA_SHA256_Q_BITS 256
struct dsa_params
{
/* Modulo */
mpz_t p;
/* Group order */
mpz_t q;
/* Generator */
mpz_t g;
};
void
dsa_params_init (struct dsa_params *params);
void
dsa_params_clear (struct dsa_params *params);
struct dsa_signature
{
mpz_t r;
mpz_t s;
};
/* Calls mpz_init to initialize bignum storage. */
void
dsa_signature_init(struct dsa_signature *signature);
/* Calls mpz_clear to deallocate bignum storage. */
void
dsa_signature_clear(struct dsa_signature *signature);
int
dsa_sign(const struct dsa_params *params,
const mpz_t x,
void *random_ctx, nettle_random_func *random,
size_t digest_size,
const uint8_t *digest,
struct dsa_signature *signature);
int
dsa_verify(const struct dsa_params *params,
const mpz_t y,
size_t digest_size,
const uint8_t *digest,
const struct dsa_signature *signature);
/* Key generation */
int
dsa_generate_params(struct dsa_params *params,
void *random_ctx, nettle_random_func *random,
void *progress_ctx, nettle_progress_func *progress,
unsigned p_bits, unsigned q_bits);
void
dsa_generate_keypair (const struct dsa_params *params,
mpz_t pub, mpz_t key,
void *random_ctx, nettle_random_func *random);
/* Keys in sexp form. */
struct nettle_buffer;
/* Generates a public-key expression if PRIV is NULL .*/
int
dsa_keypair_to_sexp(struct nettle_buffer *buffer,
const char *algorithm_name, /* NULL means "dsa" */
const struct dsa_params *params,
const mpz_t pub,
const mpz_t priv);
struct sexp_iterator;
int
dsa_signature_from_sexp(struct dsa_signature *rs,
struct sexp_iterator *i,
unsigned q_bits);
int
dsa_keypair_from_sexp_alist(struct dsa_params *params,
mpz_t pub,
mpz_t priv,
unsigned p_max_bits,
unsigned q_bits,
struct sexp_iterator *i);
/* If PRIV is NULL, expect a public-key expression. If PUB is NULL,
* expect a private key expression and ignore the parts not needed for
* the public key. */
/* Keys must be initialized before calling this function, as usual. */
int
dsa_sha1_keypair_from_sexp(struct dsa_params *params,
mpz_t pub,
mpz_t priv,
unsigned p_max_bits,
size_t length, const uint8_t *expr);
int
dsa_sha256_keypair_from_sexp(struct dsa_params *params,
mpz_t pub,
mpz_t priv,
unsigned p_max_bits,
size_t length, const uint8_t *expr);
/* Keys in X.509 andd OpenSSL format. */
struct asn1_der_iterator;
int
dsa_params_from_der_iterator(struct dsa_params *params,
unsigned max_bits, unsigned q_bits,
struct asn1_der_iterator *i);
int
dsa_public_key_from_der_iterator(const struct dsa_params *params,
mpz_t pub,
struct asn1_der_iterator *i);
int
dsa_openssl_private_key_from_der_iterator(struct dsa_params *params,
mpz_t pub,
mpz_t priv,
unsigned p_max_bits,
struct asn1_der_iterator *i);
int
dsa_openssl_private_key_from_der(struct dsa_params *params,
mpz_t pub,
mpz_t priv,
unsigned p_max_bits,
size_t length, const uint8_t *data);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_DSA_H_INCLUDED */

View File

@ -0,0 +1,185 @@
/* eax.h
EAX mode, see http://www.cs.ucdavis.edu/~rogaway/papers/eax.pdf
Copyright (C) 2013 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_EAX_H_INCLUDED
#define NETTLE_EAX_H_INCLUDED
#include "aes.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define eax_set_key nettle_eax_set_key
#define eax_set_nonce nettle_eax_set_nonce
#define eax_update nettle_eax_update
#define eax_encrypt nettle_eax_encrypt
#define eax_decrypt nettle_eax_decrypt
#define eax_digest nettle_eax_digest
#define eax_aes128_set_key nettle_eax_aes128_set_key
#define eax_aes128_set_nonce nettle_eax_aes128_set_nonce
#define eax_aes128_update nettle_eax_aes128_update
#define eax_aes128_encrypt nettle_eax_aes128_encrypt
#define eax_aes128_decrypt nettle_eax_aes128_decrypt
#define eax_aes128_digest nettle_eax_aes128_digest
/* Restricted to block ciphers with 128 bit block size. FIXME: Reflect
this in naming? */
#define EAX_BLOCK_SIZE 16
#define EAX_DIGEST_SIZE 16
/* FIXME: Reasonable default? */
#define EAX_IV_SIZE 16
/* Values independent of message and nonce */
struct eax_key
{
union nettle_block16 pad_block;
union nettle_block16 pad_partial;
};
struct eax_ctx
{
union nettle_block16 omac_nonce;
union nettle_block16 omac_data;
union nettle_block16 omac_message;
union nettle_block16 ctr;
};
void
eax_set_key (struct eax_key *key, const void *cipher, nettle_cipher_func *f);
void
eax_set_nonce (struct eax_ctx *eax, const struct eax_key *key,
const void *cipher, nettle_cipher_func *f,
size_t nonce_length, const uint8_t *nonce);
void
eax_update (struct eax_ctx *eax, const struct eax_key *key,
const void *cipher, nettle_cipher_func *f,
size_t data_length, const uint8_t *data);
void
eax_encrypt (struct eax_ctx *eax, const struct eax_key *key,
const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src);
void
eax_decrypt (struct eax_ctx *eax, const struct eax_key *key,
const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src);
void
eax_digest (struct eax_ctx *eax, const struct eax_key *key,
const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *digest);
/* Put the cipher last, to get cipher-independent offsets for the EAX
* state. */
#define EAX_CTX(type) \
{ struct eax_key key; struct eax_ctx eax; type cipher; }
#define EAX_SET_KEY(ctx, set_key, encrypt, data) \
do { \
(set_key)(&(ctx)->cipher, (data)); \
if (0) (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0); \
eax_set_key (&(ctx)->key, &(ctx)->cipher, (nettle_cipher_func *) encrypt); \
} while (0)
#define EAX_SET_NONCE(ctx, encrypt, length, nonce) \
(0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0) \
: eax_set_nonce (&(ctx)->eax, &(ctx)->key, \
&(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
(length), (nonce)))
#define EAX_UPDATE(ctx, encrypt, length, data) \
(0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0) \
: eax_update (&(ctx)->eax, &(ctx)->key, \
&(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
(length), (data)))
#define EAX_ENCRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0) \
: eax_encrypt (&(ctx)->eax, &(ctx)->key, \
&(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
(length), (dst), (src)))
#define EAX_DECRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0) \
: eax_decrypt (&(ctx)->eax, &(ctx)->key, \
&(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
(length), (dst), (src)))
#define EAX_DIGEST(ctx, encrypt, length, digest) \
(0 ? (encrypt) (&(ctx)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0) \
: eax_digest (&(ctx)->eax, &(ctx)->key, \
&(ctx)->cipher, (nettle_cipher_func *) (encrypt), \
(length), (digest)))
struct eax_aes128_ctx EAX_CTX(struct aes128_ctx);
void
eax_aes128_set_key(struct eax_aes128_ctx *ctx, const uint8_t *key);
void
eax_aes128_set_nonce(struct eax_aes128_ctx *ctx,
size_t length, const uint8_t *iv);
void
eax_aes128_update(struct eax_aes128_ctx *ctx,
size_t length, const uint8_t *data);
void
eax_aes128_encrypt(struct eax_aes128_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
eax_aes128_decrypt(struct eax_aes128_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
eax_aes128_digest(struct eax_aes128_ctx *ctx, size_t length, uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_EAX_H_INCLUDED */

View File

@ -0,0 +1,58 @@
/* ecc-curve.h
Copyright (C) 2013 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
#ifndef NETTLE_ECC_CURVE_H_INCLUDED
#define NETTLE_ECC_CURVE_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* The contents of this struct is internal. */
struct ecc_curve;
const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_gost_gc256b(void);
const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_gost_gc512a(void);
const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_192r1(void);
const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_224r1(void);
const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_256r1(void);
const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_384r1(void);
const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_521r1(void);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ECC_CURVE_H_INCLUDED */

View File

@ -0,0 +1,159 @@
/* ecc.h
Copyright (C) 2013 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
#ifndef NETTLE_ECC_H_INCLUDED
#define NETTLE_ECC_H_INCLUDED
#include "nettle-types.h"
#include "bignum.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define ecc_point_init nettle_ecc_point_init
#define ecc_point_clear nettle_ecc_point_clear
#define ecc_point_set nettle_ecc_point_set
#define ecc_point_get nettle_ecc_point_get
#define ecc_point_mul nettle_ecc_point_mul
#define ecc_point_mul_g nettle_ecc_point_mul_g
#define ecc_scalar_init nettle_ecc_scalar_init
#define ecc_scalar_clear nettle_ecc_scalar_clear
#define ecc_scalar_set nettle_ecc_scalar_set
#define ecc_scalar_get nettle_ecc_scalar_get
#define ecc_scalar_random nettle_ecc_scalar_random
#define ecc_point_mul nettle_ecc_point_mul
#define ecc_bit_size nettle_ecc_bit_size
#define ecc_size nettle_ecc_size
#define ecc_size_a nettle_ecc_size_a
#define ecc_size_j nettle_ecc_size_j
struct ecc_curve;
/* High level interface, for ECDSA, DH, etc */
/* Represents a point on the ECC curve */
struct ecc_point
{
const struct ecc_curve *ecc;
/* Allocated using the same allocation function as GMP. */
mp_limb_t *p;
};
/* Represents a non-zero scalar, an element of Z_q^*, where q is the
group order of the curve. */
struct ecc_scalar
{
const struct ecc_curve *ecc;
/* Allocated using the same allocation function as GMP. */
mp_limb_t *p;
};
void
ecc_point_init (struct ecc_point *p, const struct ecc_curve *ecc);
void
ecc_point_clear (struct ecc_point *p);
/* Fails and returns zero if the point is not on the curve. */
int
ecc_point_set (struct ecc_point *p, const mpz_t x, const mpz_t y);
void
ecc_point_get (const struct ecc_point *p, mpz_t x, mpz_t y);
void
ecc_scalar_init (struct ecc_scalar *s, const struct ecc_curve *ecc);
void
ecc_scalar_clear (struct ecc_scalar *s);
/* Fails and returns zero if the scalar is not in the proper range. */
int
ecc_scalar_set (struct ecc_scalar *s, const mpz_t z);
void
ecc_scalar_get (const struct ecc_scalar *s, mpz_t z);
/* Generates a random scalar, suitable as an ECDSA private key or a
ECDH exponent. */
void
ecc_scalar_random (struct ecc_scalar *s,
void *random_ctx, nettle_random_func *random);
/* Computes r = n p */
void
ecc_point_mul (struct ecc_point *r, const struct ecc_scalar *n,
const struct ecc_point *p);
/* Computes r = n g */
void
ecc_point_mul_g (struct ecc_point *r, const struct ecc_scalar *n);
/* Low-level interface */
/* Points on a curve are represented as arrays of mp_limb_t, with
curve-specific representation. For the secp curves, we use Jacobian
coordinates (possibly in Montgomery form for mod multiplication).
For curve25519 we use homogeneous coordinates on an equivalent
Edwards curve. The suffix "_h" denotes this internal
representation.
Since we use additive notation for the groups, the infinity point
on the curve is denoted 0. The infinity point can be represented
with x = y = 0 in affine coordinates, and Z = 0 in Jacobian
coordinates. However, note that most of the ECC functions do *not*
support infinity as an input or output.
*/
/* Returns the bit size of a single coordinate (and of the prime p). */
unsigned
ecc_bit_size (const struct ecc_curve *ecc);
/* Returns the size of a single coordinate. */
mp_size_t
ecc_size (const struct ecc_curve *ecc);
/* Size of a point, using affine coordinates x, y. */
mp_size_t
ecc_size_a (const struct ecc_curve *ecc);
/* Size of a point, using jacobian coordinates X, Y and Z. */
mp_size_t
ecc_size_j (const struct ecc_curve *ecc);
/* FIXME: Define a generic ecc_dup, ecc_add, for any type of curve. Do
they need to handle infinity points? */
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ECC_H_INCLUDED */

View File

@ -0,0 +1,103 @@
/* ecdsa.h
Copyright (C) 2013 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
#ifndef NETTLE_ECDSA_H_INCLUDED
#define NETTLE_ECDSA_H_INCLUDED
#include "ecc.h"
#include "dsa.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define ecdsa_sign nettle_ecdsa_sign
#define ecdsa_verify nettle_ecdsa_verify
#define ecdsa_generate_keypair nettle_ecdsa_generate_keypair
#define ecc_ecdsa_sign nettle_ecc_ecdsa_sign
#define ecc_ecdsa_sign_itch nettle_ecc_ecdsa_sign_itch
#define ecc_ecdsa_verify nettle_ecc_ecdsa_verify
#define ecc_ecdsa_verify_itch nettle_ecc_ecdsa_verify_itch
/* High level ECDSA functions.
*
* A public key is represented as a struct ecc_point, and a private
* key as a struct ecc_scalar. */
void
ecdsa_sign (const struct ecc_scalar *key,
void *random_ctx, nettle_random_func *random,
size_t digest_length,
const uint8_t *digest,
struct dsa_signature *signature);
int
ecdsa_verify (const struct ecc_point *pub,
size_t length, const uint8_t *digest,
const struct dsa_signature *signature);
void
ecdsa_generate_keypair (struct ecc_point *pub,
struct ecc_scalar *key,
void *random_ctx, nettle_random_func *random);
/* Low-level ECDSA functions. */
mp_size_t
ecc_ecdsa_sign_itch (const struct ecc_curve *ecc);
void
ecc_ecdsa_sign (const struct ecc_curve *ecc,
const mp_limb_t *zp,
/* Random nonce, must be invertible mod ecc group
order. */
const mp_limb_t *kp,
size_t length, const uint8_t *digest,
mp_limb_t *rp, mp_limb_t *sp,
mp_limb_t *scratch);
mp_size_t
ecc_ecdsa_verify_itch (const struct ecc_curve *ecc);
int
ecc_ecdsa_verify (const struct ecc_curve *ecc,
const mp_limb_t *pp, /* Public key */
size_t length, const uint8_t *digest,
const mp_limb_t *rp, const mp_limb_t *sp,
mp_limb_t *scratch);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_ECDSA_H_INCLUDED */

View File

@ -0,0 +1,90 @@
/* eddsa.h
Copyright (C) 2014 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_EDDSA_H
#define NETTLE_EDDSA_H
#include "nettle-types.h"
#include "bignum.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define ed25519_sha512_set_private_key nettle_ed25519_sha512_set_private_key
#define ed25519_sha512_public_key nettle_ed25519_sha512_public_key
#define ed25519_sha512_sign nettle_ed25519_sha512_sign
#define ed25519_sha512_verify nettle_ed25519_sha512_verify
#define ed448_shake256_public_key nettle_ed448_shake256_public_key
#define ed448_shake256_sign nettle_ed448_shake256_sign
#define ed448_shake256_verify nettle_ed448_shake256_verify
#define ED25519_KEY_SIZE 32
#define ED25519_SIGNATURE_SIZE 64
void
ed25519_sha512_public_key (uint8_t *pub, const uint8_t *priv);
void
ed25519_sha512_sign (const uint8_t *pub,
const uint8_t *priv,
size_t length, const uint8_t *msg,
uint8_t *signature);
int
ed25519_sha512_verify (const uint8_t *pub,
size_t length, const uint8_t *msg,
const uint8_t *signature);
#define ED448_KEY_SIZE 57
#define ED448_SIGNATURE_SIZE 114
void
ed448_shake256_public_key (uint8_t *pub, const uint8_t *priv);
void
ed448_shake256_sign (const uint8_t *pub,
const uint8_t *priv,
size_t length, const uint8_t *msg,
uint8_t *signature);
int
ed448_shake256_verify (const uint8_t *pub,
size_t length, const uint8_t *msg,
const uint8_t *signature);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_EDDSA_H */

View File

@ -0,0 +1,353 @@
/* gcm.h
Galois counter mode, specified by NIST,
http://csrc.nist.gov/publications/nistpubs/800-38D/SP-800-38D.pdf
Copyright (C) 2011 Katholieke Universiteit Leuven
Copyright (C) 2011, 2014 Niels Möller
Contributed by Nikos Mavrogiannopoulos
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_GCM_H_INCLUDED
#define NETTLE_GCM_H_INCLUDED
#include "aes.h"
#include "camellia.h"
#include "sm4.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define gcm_set_key nettle_gcm_set_key
#define gcm_set_iv nettle_gcm_set_iv
#define gcm_update nettle_gcm_update
#define gcm_encrypt nettle_gcm_encrypt
#define gcm_decrypt nettle_gcm_decrypt
#define gcm_digest nettle_gcm_digest
#define gcm_aes128_set_key nettle_gcm_aes128_set_key
#define gcm_aes128_set_iv nettle_gcm_aes128_set_iv
#define gcm_aes128_update nettle_gcm_aes128_update
#define gcm_aes128_encrypt nettle_gcm_aes128_encrypt
#define gcm_aes128_decrypt nettle_gcm_aes128_decrypt
#define gcm_aes128_digest nettle_gcm_aes128_digest
#define gcm_aes192_set_key nettle_gcm_aes192_set_key
#define gcm_aes192_set_iv nettle_gcm_aes192_set_iv
#define gcm_aes192_update nettle_gcm_aes192_update
#define gcm_aes192_encrypt nettle_gcm_aes192_encrypt
#define gcm_aes192_decrypt nettle_gcm_aes192_decrypt
#define gcm_aes192_digest nettle_gcm_aes192_digest
#define gcm_aes256_set_key nettle_gcm_aes256_set_key
#define gcm_aes256_set_iv nettle_gcm_aes256_set_iv
#define gcm_aes256_update nettle_gcm_aes256_update
#define gcm_aes256_encrypt nettle_gcm_aes256_encrypt
#define gcm_aes256_decrypt nettle_gcm_aes256_decrypt
#define gcm_aes256_digest nettle_gcm_aes256_digest
#define gcm_aes_set_key nettle_gcm_aes_set_key
#define gcm_aes_set_iv nettle_gcm_aes_set_iv
#define gcm_aes_update nettle_gcm_aes_update
#define gcm_aes_encrypt nettle_gcm_aes_encrypt
#define gcm_aes_decrypt nettle_gcm_aes_decrypt
#define gcm_aes_digest nettle_gcm_aes_digest
#define gcm_camellia128_set_key nettle_gcm_camellia128_set_key
#define gcm_camellia128_set_iv nettle_gcm_camellia128_set_iv
#define gcm_camellia128_update nettle_gcm_camellia128_update
#define gcm_camellia128_encrypt nettle_gcm_camellia128_encrypt
#define gcm_camellia128_decrypt nettle_gcm_camellia128_decrypt
#define gcm_camellia128_digest nettle_gcm_camellia128_digest
#define gcm_camellia256_set_key nettle_gcm_camellia256_set_key
#define gcm_camellia256_set_iv nettle_gcm_camellia256_set_iv
#define gcm_camellia256_update nettle_gcm_camellia256_update
#define gcm_camellia256_encrypt nettle_gcm_camellia256_encrypt
#define gcm_camellia256_decrypt nettle_gcm_camellia256_decrypt
#define gcm_camellia256_digest nettle_gcm_camellia256_digest
#define gcm_sm4_set_key nettle_gcm_sm4_set_key
#define gcm_sm4_set_iv nettle_gcm_sm4_set_iv
#define gcm_sm4_update nettle_gcm_sm4_update
#define gcm_sm4_encrypt nettle_gcm_sm4_encrypt
#define gcm_sm4_decrypt nettle_gcm_sm4_decrypt
#define gcm_sm4_digest nettle_gcm_sm4_digest
#define GCM_BLOCK_SIZE 16
#define GCM_IV_SIZE (GCM_BLOCK_SIZE - 4)
#define GCM_DIGEST_SIZE 16
#define GCM_TABLE_BITS 8
/* Hashing subkey */
struct gcm_key
{
union nettle_block16 h[1 << GCM_TABLE_BITS];
};
/* Per-message state, depending on the iv */
struct gcm_ctx {
/* Original counter block */
union nettle_block16 iv;
/* Updated for each block. */
union nettle_block16 ctr;
/* Hashing state */
union nettle_block16 x;
uint64_t auth_size;
uint64_t data_size;
};
void
gcm_set_key(struct gcm_key *key,
const void *cipher, nettle_cipher_func *f);
void
gcm_set_iv(struct gcm_ctx *ctx, const struct gcm_key *key,
size_t length, const uint8_t *iv);
void
gcm_update(struct gcm_ctx *ctx, const struct gcm_key *key,
size_t length, const uint8_t *data);
void
gcm_encrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_decrypt(struct gcm_ctx *ctx, const struct gcm_key *key,
const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_digest(struct gcm_ctx *ctx, const struct gcm_key *key,
const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *digest);
/* Convenience macrology (not sure how useful it is) */
/* All-in-one context, with hash subkey, message state, and cipher. */
#define GCM_CTX(type) \
{ struct gcm_key key; struct gcm_ctx gcm; type cipher; }
/* NOTE: Avoid using NULL, as we don't include anything defining it. */
#define GCM_SET_KEY(ctx, set_key, encrypt, gcm_key) \
do { \
(set_key)(&(ctx)->cipher, (gcm_key)); \
if (0) (encrypt)(&(ctx)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0); \
gcm_set_key(&(ctx)->key, &(ctx)->cipher, \
(nettle_cipher_func *) (encrypt)); \
} while (0)
#define GCM_SET_IV(ctx, length, data) \
gcm_set_iv(&(ctx)->gcm, &(ctx)->key, (length), (data))
#define GCM_UPDATE(ctx, length, data) \
gcm_update(&(ctx)->gcm, &(ctx)->key, (length), (data))
#define GCM_ENCRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt)(&(ctx)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0) \
: gcm_encrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
(nettle_cipher_func *) (encrypt), \
(length), (dst), (src)))
#define GCM_DECRYPT(ctx, encrypt, length, dst, src) \
(0 ? (encrypt)(&(ctx)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0) \
: gcm_decrypt(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
(nettle_cipher_func *) (encrypt), \
(length), (dst), (src)))
#define GCM_DIGEST(ctx, encrypt, length, digest) \
(0 ? (encrypt)(&(ctx)->cipher, ~(size_t) 0, \
(uint8_t *) 0, (const uint8_t *) 0) \
: gcm_digest(&(ctx)->gcm, &(ctx)->key, &(ctx)->cipher, \
(nettle_cipher_func *) (encrypt), \
(length), (digest)))
struct gcm_aes128_ctx GCM_CTX(struct aes128_ctx);
void
gcm_aes128_set_key(struct gcm_aes128_ctx *ctx, const uint8_t *key);
/* FIXME: Define _update and _set_iv as some kind of aliaes,
there's nothing aes-specific. */
void
gcm_aes128_update (struct gcm_aes128_ctx *ctx,
size_t length, const uint8_t *data);
void
gcm_aes128_set_iv (struct gcm_aes128_ctx *ctx,
size_t length, const uint8_t *iv);
void
gcm_aes128_encrypt(struct gcm_aes128_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_aes128_decrypt(struct gcm_aes128_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_aes128_digest(struct gcm_aes128_ctx *ctx,
size_t length, uint8_t *digest);
struct gcm_aes192_ctx GCM_CTX(struct aes192_ctx);
void
gcm_aes192_set_key(struct gcm_aes192_ctx *ctx, const uint8_t *key);
void
gcm_aes192_update (struct gcm_aes192_ctx *ctx,
size_t length, const uint8_t *data);
void
gcm_aes192_set_iv (struct gcm_aes192_ctx *ctx,
size_t length, const uint8_t *iv);
void
gcm_aes192_encrypt(struct gcm_aes192_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_aes192_decrypt(struct gcm_aes192_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_aes192_digest(struct gcm_aes192_ctx *ctx,
size_t length, uint8_t *digest);
struct gcm_aes256_ctx GCM_CTX(struct aes256_ctx);
void
gcm_aes256_set_key(struct gcm_aes256_ctx *ctx, const uint8_t *key);
void
gcm_aes256_update (struct gcm_aes256_ctx *ctx,
size_t length, const uint8_t *data);
void
gcm_aes256_set_iv (struct gcm_aes256_ctx *ctx,
size_t length, const uint8_t *iv);
void
gcm_aes256_encrypt(struct gcm_aes256_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_aes256_decrypt(struct gcm_aes256_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void
gcm_aes256_digest(struct gcm_aes256_ctx *ctx,
size_t length, uint8_t *digest);
/* Old deprecated aes interface, for backwards compatibility */
struct gcm_aes_ctx GCM_CTX(struct aes_ctx);
void
gcm_aes_set_key(struct gcm_aes_ctx *ctx,
size_t length, const uint8_t *key) _NETTLE_ATTRIBUTE_DEPRECATED;
void
gcm_aes_set_iv(struct gcm_aes_ctx *ctx,
size_t length, const uint8_t *iv) _NETTLE_ATTRIBUTE_DEPRECATED;
void
gcm_aes_update(struct gcm_aes_ctx *ctx,
size_t length, const uint8_t *data) _NETTLE_ATTRIBUTE_DEPRECATED;
void
gcm_aes_encrypt(struct gcm_aes_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src)
_NETTLE_ATTRIBUTE_DEPRECATED;
void
gcm_aes_decrypt(struct gcm_aes_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src)
_NETTLE_ATTRIBUTE_DEPRECATED;
void
gcm_aes_digest(struct gcm_aes_ctx *ctx, size_t length, uint8_t *digest)
_NETTLE_ATTRIBUTE_DEPRECATED;
struct gcm_camellia128_ctx GCM_CTX(struct camellia128_ctx);
void gcm_camellia128_set_key(struct gcm_camellia128_ctx *ctx,
const uint8_t *key);
void gcm_camellia128_set_iv(struct gcm_camellia128_ctx *ctx,
size_t length, const uint8_t *iv);
void gcm_camellia128_update(struct gcm_camellia128_ctx *ctx,
size_t length, const uint8_t *data);
void gcm_camellia128_encrypt(struct gcm_camellia128_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void gcm_camellia128_decrypt(struct gcm_camellia128_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void gcm_camellia128_digest(struct gcm_camellia128_ctx *ctx,
size_t length, uint8_t *digest);
struct gcm_camellia256_ctx GCM_CTX(struct camellia256_ctx);
void gcm_camellia256_set_key(struct gcm_camellia256_ctx *ctx,
const uint8_t *key);
void gcm_camellia256_set_iv(struct gcm_camellia256_ctx *ctx,
size_t length, const uint8_t *iv);
void gcm_camellia256_update(struct gcm_camellia256_ctx *ctx,
size_t length, const uint8_t *data);
void gcm_camellia256_encrypt(struct gcm_camellia256_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void gcm_camellia256_decrypt(struct gcm_camellia256_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void gcm_camellia256_digest(struct gcm_camellia256_ctx *ctx,
size_t length, uint8_t *digest);
struct gcm_sm4_ctx GCM_CTX(struct sm4_ctx);
void gcm_sm4_set_key(struct gcm_sm4_ctx *ctx, const uint8_t *key);
void gcm_sm4_set_iv(struct gcm_sm4_ctx *ctx,
size_t length, const uint8_t *iv);
void gcm_sm4_update(struct gcm_sm4_ctx *ctx,
size_t length, const uint8_t *data);
void gcm_sm4_encrypt(struct gcm_sm4_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void gcm_sm4_decrypt(struct gcm_sm4_ctx *ctx,
size_t length, uint8_t *dst, const uint8_t *src);
void gcm_sm4_digest(struct gcm_sm4_ctx *ctx,
size_t length, uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_GCM_H_INCLUDED */

View File

@ -0,0 +1,107 @@
/* gostdsa.h
Copyright (C) 2015 Dmity Eremin-Solenikov
Copyright (C) 2013 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_GOSTDSA_H_INCLUDED
#define NETTLE_GOSTDSA_H_INCLUDED
#include "ecc.h"
#include "dsa.h"
#include "ecdsa.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define gostdsa_sign nettle_gostdsa_sign
#define gostdsa_verify nettle_gostdsa_verify
#define gostdsa_vko nettle_gostdsa_vko
#define ecc_gostdsa_sign nettle_ecc_gostdsa_sign
#define ecc_gostdsa_sign_itch nettle_ecc_gostdsa_sign_itch
#define ecc_gostdsa_verify nettle_ecc_gostdsa_verify
#define ecc_gostdsa_verify_itch nettle_ecc_gostdsa_verify_itch
/* Just use ECDSA function for key generation */
#define gostdsa_generate_keypair ecdsa_generate_keypair
/* High level GOST DSA functions.
*
* A public key is represented as a struct ecc_point, and a private
* key as a struct ecc_scalar. */
void
gostdsa_sign (const struct ecc_scalar *key,
void *random_ctx, nettle_random_func *random,
size_t digest_length,
const uint8_t *digest,
struct dsa_signature *signature);
int
gostdsa_verify (const struct ecc_point *pub,
size_t length, const uint8_t *digest,
const struct dsa_signature *signature);
void
gostdsa_vko (const struct ecc_scalar *key,
const struct ecc_point *pub,
size_t ukm_length, const uint8_t *ukm,
uint8_t *out);
/* Low-level GOSTDSA functions. */
mp_size_t
ecc_gostdsa_sign_itch (const struct ecc_curve *ecc);
void
ecc_gostdsa_sign (const struct ecc_curve *ecc,
const mp_limb_t *zp,
/* Random nonce, must be invertible mod ecc group
order. */
const mp_limb_t *kp,
size_t length, const uint8_t *digest,
mp_limb_t *rp, mp_limb_t *sp,
mp_limb_t *scratch);
mp_size_t
ecc_gostdsa_verify_itch (const struct ecc_curve *ecc);
int
ecc_gostdsa_verify (const struct ecc_curve *ecc,
const mp_limb_t *pp, /* Public key */
size_t length, const uint8_t *digest,
const mp_limb_t *rp, const mp_limb_t *sp,
mp_limb_t *scratch);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_GOSTDSA_H_INCLUDED */

View File

@ -0,0 +1,112 @@
/* gosthash94.h
The GOST R 34.11-94 hash function, described in RFC 5831.
Copyright (C) 2012 Nikos Mavrogiannopoulos, Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
/* Based on rhash gost.h. */
/* Copyright: 2009-2012 Aleksey Kravchenko <rhash.admin@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Ported to nettle by Nikos Mavrogiannopoulos.
*/
#ifndef NETTLE_GOSTHASH94_H_INCLUDED
#define NETTLE_GOSTHASH94_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
#define gosthash94_init nettle_gosthash94_init
#define gosthash94_update nettle_gosthash94_update
#define gosthash94_digest nettle_gosthash94_digest
#define gosthash94cp_update nettle_gosthash94cp_update
#define gosthash94cp_digest nettle_gosthash94cp_digest
#define GOSTHASH94_BLOCK_SIZE 32
#define GOSTHASH94_DIGEST_SIZE 32
/* For backwards compatibility */
#define GOSTHASH94_DATA_SIZE GOSTHASH94_BLOCK_SIZE
#define GOSTHASH94CP_BLOCK_SIZE GOSTHASH94_BLOCK_SIZE
#define GOSTHASH94CP_DIGEST_SIZE GOSTHASH94_DIGEST_SIZE
struct gosthash94_ctx
{
uint32_t hash[8]; /* algorithm 256-bit state */
uint32_t sum[8]; /* sum of processed message blocks */
uint64_t count; /* Block count */
unsigned index; /* Into buffer */
uint8_t block[GOSTHASH94_BLOCK_SIZE]; /* 256-bit buffer for leftovers */
};
#define gosthash94cp_ctx gosthash94_ctx
void gosthash94_init(struct gosthash94_ctx *ctx);
void gosthash94_update(struct gosthash94_ctx *ctx,
size_t length, const uint8_t *msg);
void gosthash94_digest(struct gosthash94_ctx *ctx,
size_t length, uint8_t *result);
#define gosthash94cp_init gosthash94_init
void gosthash94cp_update(struct gosthash94_ctx *ctx,
size_t length, const uint8_t *msg);
void gosthash94cp_digest(struct gosthash94_ctx *ctx,
size_t length, uint8_t *result);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_GOSTHASH94_H_INCLUDED */

View File

@ -0,0 +1,67 @@
/* hkdf.h
TLS PRF code (RFC-5246, RFC-2246).
Copyright (C) 2017 Red Hat, Inc.
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_HKDF_H_INCLUDED
#define NETTLE_HKDF_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Namespace mangling */
#define hkdf_extract nettle_hkdf_extract
#define hkdf_expand nettle_hkdf_expand
void
hkdf_extract(void *mac_ctx,
nettle_hash_update_func *update,
nettle_hash_digest_func *digest,
size_t digest_size,
size_t secret_size, const uint8_t *secret,
uint8_t *dst);
void
hkdf_expand(void *mac_ctx,
nettle_hash_update_func *update,
nettle_hash_digest_func *digest,
size_t digest_size,
size_t info_size, const uint8_t *info,
size_t length, uint8_t *dst);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_HKDF_H_INCLUDED */

View File

@ -0,0 +1,299 @@
/* hmac.h
HMAC message authentication code (RFC-2104).
Copyright (C) 2001, 2002 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_HMAC_H_INCLUDED
#define NETTLE_HMAC_H_INCLUDED
#include "nettle-meta.h"
#include "gosthash94.h"
#include "md5.h"
#include "ripemd160.h"
#include "sha1.h"
#include "sha2.h"
#include "streebog.h"
#include "sm3.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Namespace mangling */
#define hmac_set_key nettle_hmac_set_key
#define hmac_update nettle_hmac_update
#define hmac_digest nettle_hmac_digest
#define hmac_md5_set_key nettle_hmac_md5_set_key
#define hmac_md5_update nettle_hmac_md5_update
#define hmac_md5_digest nettle_hmac_md5_digest
#define hmac_ripemd160_set_key nettle_hmac_ripemd160_set_key
#define hmac_ripemd160_update nettle_hmac_ripemd160_update
#define hmac_ripemd160_digest nettle_hmac_ripemd160_digest
#define hmac_sha1_set_key nettle_hmac_sha1_set_key
#define hmac_sha1_update nettle_hmac_sha1_update
#define hmac_sha1_digest nettle_hmac_sha1_digest
#define hmac_sha224_set_key nettle_hmac_sha224_set_key
#define hmac_sha224_digest nettle_hmac_sha224_digest
#define hmac_sha256_set_key nettle_hmac_sha256_set_key
#define hmac_sha256_update nettle_hmac_sha256_update
#define hmac_sha256_digest nettle_hmac_sha256_digest
#define hmac_sha384_set_key nettle_hmac_sha384_set_key
#define hmac_sha384_digest nettle_hmac_sha384_digest
#define hmac_sha512_set_key nettle_hmac_sha512_set_key
#define hmac_sha512_update nettle_hmac_sha512_update
#define hmac_sha512_digest nettle_hmac_sha512_digest
#define hmac_gosthash94_set_key nettle_hmac_gosthash94_set_key
#define hmac_gosthash94_update nettle_hmac_gosthash94_update
#define hmac_gosthash94_digest nettle_hmac_gosthash94_digest
#define hmac_gosthash94cp_set_key nettle_hmac_gosthash94cp_set_key
#define hmac_gosthash94cp_update nettle_hmac_gosthash94cp_update
#define hmac_gosthash94cp_digest nettle_hmac_gosthash94cp_digest
#define hmac_streebog256_set_key nettle_hmac_streebog256_set_key
#define hmac_streebog256_digest nettle_hmac_streebog256_digest
#define hmac_streebog512_set_key nettle_hmac_streebog512_set_key
#define hmac_streebog512_update nettle_hmac_streebog512_update
#define hmac_streebog512_digest nettle_hmac_streebog512_digest
#define hmac_sm3_set_key nettle_hmac_sm3_set_key
#define hmac_sm3_update nettle_hmac_sm3_update
#define hmac_sm3_digest nettle_hmac_sm3_digest
void
hmac_set_key(void *outer, void *inner, void *state,
const struct nettle_hash *hash,
size_t length, const uint8_t *key);
/* This function is not strictly needed, it's s just the same as the
* hash update function. */
void
hmac_update(void *state,
const struct nettle_hash *hash,
size_t length, const uint8_t *data);
void
hmac_digest(const void *outer, const void *inner, void *state,
const struct nettle_hash *hash,
size_t length, uint8_t *digest);
#define HMAC_CTX(type) \
{ type outer; type inner; type state; }
#define HMAC_SET_KEY(ctx, hash, length, key) \
hmac_set_key( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
(hash), (length), (key) )
#define HMAC_DIGEST(ctx, hash, length, digest) \
hmac_digest( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
(hash), (length), (digest) )
/* HMAC using specific hash functions */
/* hmac-md5 */
struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
void
hmac_md5_set_key(struct hmac_md5_ctx *ctx,
size_t key_length, const uint8_t *key);
void
hmac_md5_update(struct hmac_md5_ctx *ctx,
size_t length, const uint8_t *data);
void
hmac_md5_digest(struct hmac_md5_ctx *ctx,
size_t length, uint8_t *digest);
/* hmac-ripemd160 */
struct hmac_ripemd160_ctx HMAC_CTX(struct ripemd160_ctx);
void
hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx,
size_t key_length, const uint8_t *key);
void
hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx,
size_t length, const uint8_t *data);
void
hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx,
size_t length, uint8_t *digest);
/* hmac-sha1 */
struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
void
hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
size_t key_length, const uint8_t *key);
void
hmac_sha1_update(struct hmac_sha1_ctx *ctx,
size_t length, const uint8_t *data);
void
hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
size_t length, uint8_t *digest);
/* hmac-sha256 */
struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx);
void
hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
size_t key_length, const uint8_t *key);
void
hmac_sha256_update(struct hmac_sha256_ctx *ctx,
size_t length, const uint8_t *data);
void
hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
size_t length, uint8_t *digest);
/* hmac-sha224 */
#define hmac_sha224_ctx hmac_sha256_ctx
void
hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
size_t key_length, const uint8_t *key);
#define hmac_sha224_update nettle_hmac_sha256_update
void
hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
size_t length, uint8_t *digest);
/* hmac-sha512 */
struct hmac_sha512_ctx HMAC_CTX(struct sha512_ctx);
void
hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
size_t key_length, const uint8_t *key);
void
hmac_sha512_update(struct hmac_sha512_ctx *ctx,
size_t length, const uint8_t *data);
void
hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
size_t length, uint8_t *digest);
/* hmac-sha384 */
#define hmac_sha384_ctx hmac_sha512_ctx
void
hmac_sha384_set_key(struct hmac_sha512_ctx *ctx,
size_t key_length, const uint8_t *key);
#define hmac_sha384_update nettle_hmac_sha512_update
void
hmac_sha384_digest(struct hmac_sha512_ctx *ctx,
size_t length, uint8_t *digest);
/* hmac-gosthash94 */
struct hmac_gosthash94_ctx HMAC_CTX(struct gosthash94_ctx);
void
hmac_gosthash94_set_key(struct hmac_gosthash94_ctx *ctx,
size_t key_length, const uint8_t *key);
void
hmac_gosthash94_update(struct hmac_gosthash94_ctx *ctx,
size_t length, const uint8_t *data);
void
hmac_gosthash94_digest(struct hmac_gosthash94_ctx *ctx,
size_t length, uint8_t *digest);
struct hmac_gosthash94cp_ctx HMAC_CTX(struct gosthash94cp_ctx);
void
hmac_gosthash94cp_set_key(struct hmac_gosthash94cp_ctx *ctx,
size_t key_length, const uint8_t *key);
void
hmac_gosthash94cp_update(struct hmac_gosthash94cp_ctx *ctx,
size_t length, const uint8_t *data);
void
hmac_gosthash94cp_digest(struct hmac_gosthash94cp_ctx *ctx,
size_t length, uint8_t *digest);
/* hmac-streebog */
struct hmac_streebog512_ctx HMAC_CTX(struct streebog512_ctx);
void
hmac_streebog512_set_key(struct hmac_streebog512_ctx *ctx,
size_t key_length, const uint8_t *key);
void
hmac_streebog512_update(struct hmac_streebog512_ctx *ctx,
size_t length, const uint8_t *data);
void
hmac_streebog512_digest(struct hmac_streebog512_ctx *ctx,
size_t length, uint8_t *digest);
#define hmac_streebog256_ctx hmac_streebog512_ctx
void
hmac_streebog256_set_key(struct hmac_streebog256_ctx *ctx,
size_t key_length, const uint8_t *key);
#define hmac_streebog256_update hmac_streebog512_update
void
hmac_streebog256_digest(struct hmac_streebog256_ctx *ctx,
size_t length, uint8_t *digest);
/* hmac-sm3 */
struct hmac_sm3_ctx HMAC_CTX(struct sm3_ctx);
void
hmac_sm3_set_key(struct hmac_sm3_ctx *ctx,
size_t key_length, const uint8_t *key);
void
hmac_sm3_update(struct hmac_sm3_ctx *ctx,
size_t length, const uint8_t *data);
void
hmac_sm3_digest(struct hmac_sm3_ctx *ctx,
size_t length, uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_HMAC_H_INCLUDED */

View File

@ -0,0 +1,80 @@
/* knuth-lfib.h
The "lagged fibonacci" pseudorandomness generator, described in
Knuth, TAoCP, 3.6
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
/* NOTE: This generator is totally inappropriate for cryptographic
* applications. It is useful for generating deterministic but
* random-looking test data, and is used by the Nettle testsuite. */
#ifndef NETTLE_KNUTH_LFIB_H_INCLUDED
#define NETTLE_KNUTH_LFIB_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Namespace mangling */
#define knuth_lfib_init nettle_knuth_lfib_init
#define knuth_lfib_get nettle_knuth_lfib_get
#define knuth_lfib_get_array nettle_knuth_lfib_get_array
#define knuth_lfib_random nettle_knuth_lfib_random
#define _KNUTH_LFIB_KK 100
struct knuth_lfib_ctx
{
uint32_t x[_KNUTH_LFIB_KK];
unsigned index;
};
void
knuth_lfib_init(struct knuth_lfib_ctx *ctx, uint32_t seed);
/* Get's a single number in the range 0 ... 2^30-1 */
uint32_t
knuth_lfib_get(struct knuth_lfib_ctx *ctx);
/* Get an array of numbers */
void
knuth_lfib_get_array(struct knuth_lfib_ctx *ctx,
size_t n, uint32_t *a);
/* Get an array of octets. */
void
knuth_lfib_random(struct knuth_lfib_ctx *ctx,
size_t n, uint8_t *dst);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_KNUTH_LFIB_H_INCLUDED */

View File

@ -0,0 +1,245 @@
/* macros.h
Copyright (C) 2001, 2010 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_MACROS_H_INCLUDED
#define NETTLE_MACROS_H_INCLUDED
/* Reads a 64-bit integer, in network, big-endian, byte order */
#define READ_UINT64(p) \
( (((uint64_t) (p)[0]) << 56) \
| (((uint64_t) (p)[1]) << 48) \
| (((uint64_t) (p)[2]) << 40) \
| (((uint64_t) (p)[3]) << 32) \
| (((uint64_t) (p)[4]) << 24) \
| (((uint64_t) (p)[5]) << 16) \
| (((uint64_t) (p)[6]) << 8) \
| ((uint64_t) (p)[7]))
#define WRITE_UINT64(p, i) \
do { \
(p)[0] = ((i) >> 56) & 0xff; \
(p)[1] = ((i) >> 48) & 0xff; \
(p)[2] = ((i) >> 40) & 0xff; \
(p)[3] = ((i) >> 32) & 0xff; \
(p)[4] = ((i) >> 24) & 0xff; \
(p)[5] = ((i) >> 16) & 0xff; \
(p)[6] = ((i) >> 8) & 0xff; \
(p)[7] = (i) & 0xff; \
} while(0)
/* Reads a 32-bit integer, in network, big-endian, byte order */
#define READ_UINT32(p) \
( (((uint32_t) (p)[0]) << 24) \
| (((uint32_t) (p)[1]) << 16) \
| (((uint32_t) (p)[2]) << 8) \
| ((uint32_t) (p)[3]))
#define WRITE_UINT32(p, i) \
do { \
(p)[0] = ((i) >> 24) & 0xff; \
(p)[1] = ((i) >> 16) & 0xff; \
(p)[2] = ((i) >> 8) & 0xff; \
(p)[3] = (i) & 0xff; \
} while(0)
/* Analogous macros, for 24 and 16 bit numbers */
#define READ_UINT24(p) \
( (((uint32_t) (p)[0]) << 16) \
| (((uint32_t) (p)[1]) << 8) \
| ((uint32_t) (p)[2]))
#define WRITE_UINT24(p, i) \
do { \
(p)[0] = ((i) >> 16) & 0xff; \
(p)[1] = ((i) >> 8) & 0xff; \
(p)[2] = (i) & 0xff; \
} while(0)
#define READ_UINT16(p) \
( (((uint32_t) (p)[0]) << 8) \
| ((uint32_t) (p)[1]))
#define WRITE_UINT16(p, i) \
do { \
(p)[0] = ((i) >> 8) & 0xff; \
(p)[1] = (i) & 0xff; \
} while(0)
/* And the other, little-endian, byteorder */
#define LE_READ_UINT64(p) \
( (((uint64_t) (p)[7]) << 56) \
| (((uint64_t) (p)[6]) << 48) \
| (((uint64_t) (p)[5]) << 40) \
| (((uint64_t) (p)[4]) << 32) \
| (((uint64_t) (p)[3]) << 24) \
| (((uint64_t) (p)[2]) << 16) \
| (((uint64_t) (p)[1]) << 8) \
| ((uint64_t) (p)[0]))
#define LE_WRITE_UINT64(p, i) \
do { \
(p)[7] = ((i) >> 56) & 0xff; \
(p)[6] = ((i) >> 48) & 0xff; \
(p)[5] = ((i) >> 40) & 0xff; \
(p)[4] = ((i) >> 32) & 0xff; \
(p)[3] = ((i) >> 24) & 0xff; \
(p)[2] = ((i) >> 16) & 0xff; \
(p)[1] = ((i) >> 8) & 0xff; \
(p)[0] = (i) & 0xff; \
} while (0)
#define LE_READ_UINT32(p) \
( (((uint32_t) (p)[3]) << 24) \
| (((uint32_t) (p)[2]) << 16) \
| (((uint32_t) (p)[1]) << 8) \
| ((uint32_t) (p)[0]))
#define LE_WRITE_UINT32(p, i) \
do { \
(p)[3] = ((i) >> 24) & 0xff; \
(p)[2] = ((i) >> 16) & 0xff; \
(p)[1] = ((i) >> 8) & 0xff; \
(p)[0] = (i) & 0xff; \
} while(0)
/* Analogous macros, for 16 bit numbers */
#define LE_READ_UINT16(p) \
( (((uint32_t) (p)[1]) << 8) \
| ((uint32_t) (p)[0]))
#define LE_WRITE_UINT16(p, i) \
do { \
(p)[1] = ((i) >> 8) & 0xff; \
(p)[0] = (i) & 0xff; \
} while(0)
/* Macro to make it easier to loop over several blocks. */
#define FOR_BLOCKS(length, dst, src, blocksize) \
assert( !((length) % (blocksize))); \
for (; (length); ((length) -= (blocksize), \
(dst) += (blocksize), \
(src) += (blocksize)) )
/* The masking of the right shift is needed to allow n == 0 (using
just 32 - n and 64 - n results in undefined behaviour). Most uses
of these macros use a constant and non-zero rotation count. */
#define ROTL32(n,x) (((x)<<(n)) | ((x)>>((-(n)&31))))
#define ROTL64(n,x) (((x)<<(n)) | ((x)>>((-(n))&63)))
/* Requires that size > 0 */
#define INCREMENT(size, ctr) \
do { \
unsigned increment_i = (size) - 1; \
if (++(ctr)[increment_i] == 0) \
while (increment_i > 0 \
&& ++(ctr)[--increment_i] == 0 ) \
; \
} while (0)
/* Helper macro for Merkle-Damgård hash functions. Assumes the context
structs includes the following fields:
uint8_t block[...]; // Buffer holding one block
unsigned int index; // Index into block
*/
/* Currently used by sha512 (and sha384) only. */
#define MD_INCR(ctx) ((ctx)->count_high += !++(ctx)->count_low)
/* Takes the compression function f as argument. NOTE: also clobbers
length and data. */
#define MD_UPDATE(ctx, length, data, f, incr) \
do { \
if ((ctx)->index) \
{ \
/* Try to fill partial block */ \
unsigned __md_left = sizeof((ctx)->block) - (ctx)->index; \
if ((length) < __md_left) \
{ \
memcpy((ctx)->block + (ctx)->index, (data), (length)); \
(ctx)->index += (length); \
goto __md_done; /* Finished */ \
} \
else \
{ \
memcpy((ctx)->block + (ctx)->index, (data), __md_left); \
\
f((ctx), (ctx)->block); \
(incr); \
\
(data) += __md_left; \
(length) -= __md_left; \
} \
} \
while ((length) >= sizeof((ctx)->block)) \
{ \
f((ctx), (data)); \
(incr); \
\
(data) += sizeof((ctx)->block); \
(length) -= sizeof((ctx)->block); \
} \
memcpy ((ctx)->block, (data), (length)); \
(ctx)->index = (length); \
__md_done: \
; \
} while (0)
/* Pads the block to a block boundary with the bit pattern 1 0*,
leaving size octets for the length field at the end. If needed,
compresses the block and starts a new one. */
#define MD_PAD(ctx, size, f) \
do { \
unsigned __md_i; \
__md_i = (ctx)->index; \
\
/* Set the first char of padding to 0x80. This is safe since there \
is always at least one byte free */ \
\
assert(__md_i < sizeof((ctx)->block)); \
(ctx)->block[__md_i++] = 0x80; \
\
if (__md_i > (sizeof((ctx)->block) - (size))) \
{ /* No room for length in this block. Process it and \
pad with another one */ \
memset((ctx)->block + __md_i, 0, sizeof((ctx)->block) - __md_i); \
\
f((ctx), (ctx)->block); \
__md_i = 0; \
} \
memset((ctx)->block + __md_i, 0, \
sizeof((ctx)->block) - (size) - __md_i); \
\
} while (0)
#endif /* NETTLE_MACROS_H_INCLUDED */

View File

@ -0,0 +1,79 @@
/* md2.h
The MD2 hash function, described in RFC 1319.
Copyright (C) 2003 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_MD2_H_INCLUDED
#define NETTLE_MD2_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define md2_init nettle_md2_init
#define md2_update nettle_md2_update
#define md2_digest nettle_md2_digest
#define MD2_DIGEST_SIZE 16
#define MD2_BLOCK_SIZE 16
/* For backwards compatibility */
#define MD2_DATA_SIZE MD2_BLOCK_SIZE
struct md2_ctx
{
uint8_t C[MD2_BLOCK_SIZE];
uint8_t X[3 * MD2_BLOCK_SIZE];
unsigned index; /* Into buffer */
uint8_t block[MD2_BLOCK_SIZE]; /* Block buffer */
};
void
md2_init(struct md2_ctx *ctx);
void
md2_update(struct md2_ctx *ctx,
size_t length,
const uint8_t *data);
void
md2_digest(struct md2_ctx *ctx,
size_t length,
uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MD2_H_INCLUDED */

View File

@ -0,0 +1,83 @@
/* md4.h
The MD4 hash function, described in RFC 1320.
Copyright (C) 2003 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_MD4_H_INCLUDED
#define NETTLE_MD4_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define md4_init nettle_md4_init
#define md4_update nettle_md4_update
#define md4_digest nettle_md4_digest
#define MD4_DIGEST_SIZE 16
#define MD4_BLOCK_SIZE 64
/* For backwards compatibility */
#define MD4_DATA_SIZE MD4_BLOCK_SIZE
/* Digest is kept internally as 4 32-bit words. */
#define _MD4_DIGEST_LENGTH 4
/* FIXME: Identical to md5_ctx */
struct md4_ctx
{
uint32_t state[_MD4_DIGEST_LENGTH];
uint64_t count; /* Block count */
unsigned index; /* Into buffer */
uint8_t block[MD4_BLOCK_SIZE]; /* Block buffer */
};
void
md4_init(struct md4_ctx *ctx);
void
md4_update(struct md4_ctx *ctx,
size_t length,
const uint8_t *data);
void
md4_digest(struct md4_ctx *ctx,
size_t length,
uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MD4_H_INCLUDED */

View File

@ -0,0 +1,58 @@
/* md5-compat.h
The md5 hash function, RFC 1321-style interface.
Copyright (C) 2001 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_MD5_COMPAT_H_INCLUDED
#define NETTLE_MD5_COMPAT_H_INCLUDED
#include "md5.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define MD5Init nettle_MD5Init
#define MD5Update nettle_MD5Update
#define MD5Final nettle_MD5Final
typedef struct md5_ctx MD5_CTX;
void MD5Init(MD5_CTX *ctx);
void MD5Update(MD5_CTX *ctx, const unsigned char *data, unsigned int length);
void MD5Final(unsigned char *out, MD5_CTX *ctx);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MD5_COMPAT_H_INCLUDED */

View File

@ -0,0 +1,90 @@
/* md5.h
The MD5 hash function, described in RFC 1321.
Copyright (C) 2001 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_MD5_H_INCLUDED
#define NETTLE_MD5_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define md5_init nettle_md5_init
#define md5_update nettle_md5_update
#define md5_digest nettle_md5_digest
#define md5_compress nettle_md5_compress
#define MD5_DIGEST_SIZE 16
#define MD5_BLOCK_SIZE 64
/* For backwards compatibility */
#define MD5_DATA_SIZE MD5_BLOCK_SIZE
/* Digest is kept internally as 4 32-bit words. */
#define _MD5_DIGEST_LENGTH 4
struct md5_ctx
{
uint32_t state[_MD5_DIGEST_LENGTH];
uint64_t count; /* Block count */
unsigned index; /* Into buffer */
uint8_t block[MD5_BLOCK_SIZE]; /* Block buffer */
};
void
md5_init(struct md5_ctx *ctx);
void
md5_update(struct md5_ctx *ctx,
size_t length,
const uint8_t *data);
void
md5_digest(struct md5_ctx *ctx,
size_t length,
uint8_t *digest);
/* MD5 compression function. STATE points to 4 uint32_t words,
and DATA points to 64 bytes of input data, possibly unaligned. */
void
md5_compress(uint32_t *state, const uint8_t *data);
/* Old name, for backwards compatibility. */
#define _nettle_md5_compress nettle_md5_compress
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MD5_H_INCLUDED */

View File

@ -0,0 +1,57 @@
/* memops.h
Copyright (C) 2016 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_MEMOPS_H_INCLUDED
#define NETTLE_MEMOPS_H_INCLUDED
#include "memxor.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define cnd_memcpy nettle_cnd_memcpy
#define memeql_sec nettle_memeql_sec
int
memeql_sec (const void *a, const void *b, size_t n);
/* Side-channel silent conditional memcpy. cnd must be 0 (nop) or 1
(copy). */
void
cnd_memcpy(int cnd, volatile void *dst, const volatile void *src, size_t n);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MEMOPS_H_INCLUDED */

View File

@ -0,0 +1,25 @@
/* memxor.h
*
*/
#ifndef NETTLE_MEMXOR_H_INCLUDED
#define NETTLE_MEMXOR_H_INCLUDED
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define memxor nettle_memxor
#define memxor3 nettle_memxor3
void *memxor(void *dst, const void *src, size_t n);
void *memxor3(void *dst, const void *a, const void *b, size_t n);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_MEMXOR_H_INCLUDED */

View File

@ -0,0 +1,303 @@
/* nettle-meta.h
Information about algorithms.
Copyright (C) 2002, 2014, 2020 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_META_H_INCLUDED
#define NETTLE_META_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
struct nettle_cipher
{
const char *name;
unsigned context_size;
/* Zero for stream ciphers */
unsigned block_size;
/* Suggested key size; other sizes are sometimes possible. */
unsigned key_size;
nettle_set_key_func *set_encrypt_key;
nettle_set_key_func *set_decrypt_key;
nettle_cipher_func *encrypt;
nettle_cipher_func *decrypt;
};
/* null-terminated list of ciphers implemented by this version of nettle */
const struct nettle_cipher * const * _NETTLE_ATTRIBUTE_PURE
nettle_get_ciphers (void);
#define nettle_ciphers (nettle_get_ciphers())
extern const struct nettle_cipher nettle_aes128;
extern const struct nettle_cipher nettle_aes192;
extern const struct nettle_cipher nettle_aes256;
extern const struct nettle_cipher nettle_camellia128;
extern const struct nettle_cipher nettle_camellia192;
extern const struct nettle_cipher nettle_camellia256;
extern const struct nettle_cipher nettle_cast128;
extern const struct nettle_cipher nettle_serpent128;
extern const struct nettle_cipher nettle_serpent192;
extern const struct nettle_cipher nettle_serpent256;
extern const struct nettle_cipher nettle_twofish128;
extern const struct nettle_cipher nettle_twofish192;
extern const struct nettle_cipher nettle_twofish256;
extern const struct nettle_cipher nettle_arctwo40;
extern const struct nettle_cipher nettle_arctwo64;
extern const struct nettle_cipher nettle_arctwo128;
extern const struct nettle_cipher nettle_arctwo_gutmann128;
extern const struct nettle_cipher nettle_sm4;
struct nettle_hash
{
const char *name;
/* Size of the context struct */
unsigned context_size;
/* Size of digests */
unsigned digest_size;
/* Internal block size */
unsigned block_size;
nettle_hash_init_func *init;
nettle_hash_update_func *update;
nettle_hash_digest_func *digest;
};
#define _NETTLE_HASH(name, NAME) { \
#name, \
sizeof(struct name##_ctx), \
NAME##_DIGEST_SIZE, \
NAME##_BLOCK_SIZE, \
(nettle_hash_init_func *) name##_init, \
(nettle_hash_update_func *) name##_update, \
(nettle_hash_digest_func *) name##_digest \
}
/* null-terminated list of digests implemented by this version of nettle */
const struct nettle_hash * const * _NETTLE_ATTRIBUTE_PURE
nettle_get_hashes (void);
#define nettle_hashes (nettle_get_hashes())
const struct nettle_hash *
nettle_lookup_hash (const char *name);
extern const struct nettle_hash nettle_md2;
extern const struct nettle_hash nettle_md4;
extern const struct nettle_hash nettle_md5;
extern const struct nettle_hash nettle_gosthash94;
extern const struct nettle_hash nettle_gosthash94cp;
extern const struct nettle_hash nettle_ripemd160;
extern const struct nettle_hash nettle_sha1;
extern const struct nettle_hash nettle_sha224;
extern const struct nettle_hash nettle_sha256;
extern const struct nettle_hash nettle_sha384;
extern const struct nettle_hash nettle_sha512;
extern const struct nettle_hash nettle_sha512_224;
extern const struct nettle_hash nettle_sha512_256;
extern const struct nettle_hash nettle_sha3_224;
extern const struct nettle_hash nettle_sha3_256;
extern const struct nettle_hash nettle_sha3_384;
extern const struct nettle_hash nettle_sha3_512;
extern const struct nettle_hash nettle_streebog256;
extern const struct nettle_hash nettle_streebog512;
extern const struct nettle_hash nettle_sm3;
struct nettle_mac
{
const char *name;
/* Size of the context struct */
unsigned context_size;
/* Size of digests */
unsigned digest_size;
/* Key size */
unsigned key_size;
nettle_set_key_func *set_key;
nettle_hash_update_func *update;
nettle_hash_digest_func *digest;
};
struct nettle_aead
{
const char *name;
unsigned context_size;
/* Block size for encrypt and decrypt. */
unsigned block_size;
unsigned key_size;
unsigned nonce_size;
unsigned digest_size;
nettle_set_key_func *set_encrypt_key;
nettle_set_key_func *set_decrypt_key;
nettle_set_key_func *set_nonce;
nettle_hash_update_func *update;
nettle_crypt_func *encrypt;
nettle_crypt_func *decrypt;
/* FIXME: Drop length argument? */
nettle_hash_digest_func *digest;
};
/* null-terminated list of aead constructions implemented by this
version of nettle */
const struct nettle_aead * const * _NETTLE_ATTRIBUTE_PURE
nettle_get_aeads (void);
#define nettle_aeads (nettle_get_aeads())
extern const struct nettle_aead nettle_gcm_aes128;
extern const struct nettle_aead nettle_gcm_aes192;
extern const struct nettle_aead nettle_gcm_aes256;
extern const struct nettle_aead nettle_gcm_camellia128;
extern const struct nettle_aead nettle_gcm_camellia256;
extern const struct nettle_aead nettle_gcm_sm4;
extern const struct nettle_aead nettle_eax_aes128;
extern const struct nettle_aead nettle_chacha_poly1305;
struct nettle_armor
{
const char *name;
unsigned encode_context_size;
unsigned decode_context_size;
unsigned encode_final_length;
nettle_armor_init_func *encode_init;
nettle_armor_length_func *encode_length;
nettle_armor_encode_update_func *encode_update;
nettle_armor_encode_final_func *encode_final;
nettle_armor_init_func *decode_init;
nettle_armor_length_func *decode_length;
nettle_armor_decode_update_func *decode_update;
nettle_armor_decode_final_func *decode_final;
};
#define _NETTLE_ARMOR(name, NAME) { \
#name, \
sizeof(struct name##_encode_ctx), \
sizeof(struct name##_decode_ctx), \
NAME##_ENCODE_FINAL_LENGTH, \
(nettle_armor_init_func *) name##_encode_init, \
(nettle_armor_length_func *) name##_encode_length, \
(nettle_armor_encode_update_func *) name##_encode_update, \
(nettle_armor_encode_final_func *) name##_encode_final, \
(nettle_armor_init_func *) name##_decode_init, \
(nettle_armor_length_func *) name##_decode_length, \
(nettle_armor_decode_update_func *) name##_decode_update, \
(nettle_armor_decode_final_func *) name##_decode_final, \
}
#define _NETTLE_ARMOR_0(name, NAME) { \
#name, \
0, \
sizeof(struct name##_decode_ctx), \
NAME##_ENCODE_FINAL_LENGTH, \
(nettle_armor_init_func *) name##_encode_init, \
(nettle_armor_length_func *) name##_encode_length, \
(nettle_armor_encode_update_func *) name##_encode_update, \
(nettle_armor_encode_final_func *) name##_encode_final, \
(nettle_armor_init_func *) name##_decode_init, \
(nettle_armor_length_func *) name##_decode_length, \
(nettle_armor_decode_update_func *) name##_decode_update, \
(nettle_armor_decode_final_func *) name##_decode_final, \
}
/* null-terminated list of armor schemes implemented by this version of nettle */
const struct nettle_armor * const * _NETTLE_ATTRIBUTE_PURE
nettle_get_armors (void);
#define nettle_armors (nettle_get_armors())
extern const struct nettle_armor nettle_base64;
extern const struct nettle_armor nettle_base64url;
extern const struct nettle_armor nettle_base16;
#define _NETTLE_HMAC(name, HASH) { \
#name, \
sizeof(struct name##_ctx), \
HASH##_DIGEST_SIZE, \
HASH##_DIGEST_SIZE, \
name##_set_key_wrapper, \
(nettle_hash_update_func *) name##_update, \
(nettle_hash_digest_func *) name##_digest, \
}
/* null-terminated list of macs implemented by this
version of nettle */
const struct nettle_mac * const * _NETTLE_ATTRIBUTE_PURE
nettle_get_macs (void);
#define nettle_macs (nettle_get_macs())
extern const struct nettle_mac nettle_cmac_aes128;
extern const struct nettle_mac nettle_cmac_aes256;
extern const struct nettle_mac nettle_cmac_des3;
/* HMAC variants with key size = digest size */
extern const struct nettle_mac nettle_hmac_md5;
extern const struct nettle_mac nettle_hmac_ripemd160;
extern const struct nettle_mac nettle_hmac_sha1;
extern const struct nettle_mac nettle_hmac_sha224;
extern const struct nettle_mac nettle_hmac_sha256;
extern const struct nettle_mac nettle_hmac_sha384;
extern const struct nettle_mac nettle_hmac_sha512;
extern const struct nettle_mac nettle_hmac_streebog256;
extern const struct nettle_mac nettle_hmac_streebog512;
extern const struct nettle_mac nettle_hmac_sm3;
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_META_H_INCLUDED */

View File

@ -0,0 +1,131 @@
/* nettle-types.h
Copyright (C) 2005, 2014 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_TYPES_H
#define NETTLE_TYPES_H
/* For size_t */
#include <stddef.h>
#include <stdint.h>
/* Attributes we want to use in installed header files, and hence
can't rely on config.h. */
#ifdef __GNUC__
#define _NETTLE_ATTRIBUTE_PURE __attribute__((pure))
#ifndef _NETTLE_ATTRIBUTE_DEPRECATED
/* Variant without message is supported since gcc-3.1 or so. */
#define _NETTLE_ATTRIBUTE_DEPRECATED __attribute__((deprecated))
#endif
#else /* !__GNUC__ */
#define _NETTLE_ATTRIBUTE_PURE
#define _NETTLE_ATTRIBUTE_DEPRECATED
#endif /* !__GNUC__ */
#ifdef __cplusplus
extern "C" {
#endif
/* An aligned 16-byte block. */
union nettle_block16
{
uint8_t b[16];
unsigned long w[16 / sizeof(unsigned long)] _NETTLE_ATTRIBUTE_DEPRECATED;
uint64_t u64[2];
};
union nettle_block8
{
uint8_t b[8];
uint64_t u64;
};
/* Randomness. Used by key generation and dsa signature creation. */
typedef void nettle_random_func(void *ctx,
size_t length, uint8_t *dst);
/* Progress report function, mainly for key generation. */
typedef void nettle_progress_func(void *ctx, int c);
/* Realloc function, used by struct nettle_buffer. */
typedef void *nettle_realloc_func(void *ctx, void *p, size_t length);
/* Ciphers */
typedef void nettle_set_key_func(void *ctx, const uint8_t *key);
/* For block ciphers, const context. */
typedef void nettle_cipher_func(const void *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
/* Uses a void * for cipher contexts. Used for crypt operations where
the internal state changes during the encryption. */
typedef void nettle_crypt_func(void *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
/* Hash algorithms */
typedef void nettle_hash_init_func(void *ctx);
typedef void nettle_hash_update_func(void *ctx,
size_t length,
const uint8_t *src);
typedef void nettle_hash_digest_func(void *ctx,
size_t length, uint8_t *dst);
/* ASCII armor codecs. NOTE: Experimental and subject to change. */
typedef size_t nettle_armor_length_func(size_t length);
typedef void nettle_armor_init_func(void *ctx);
typedef size_t nettle_armor_encode_update_func(void *ctx,
char *dst,
size_t src_length,
const uint8_t *src);
typedef size_t nettle_armor_encode_final_func(void *ctx, char *dst);
typedef int nettle_armor_decode_update_func(void *ctx,
size_t *dst_length,
uint8_t *dst,
size_t src_length,
const char *src);
typedef int nettle_armor_decode_final_func(void *ctx);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_TYPES_H */

View File

@ -0,0 +1,101 @@
/* nist-keywrap.h
AES Key Wrap function.
implements RFC 3394
https://tools.ietf.org/html/rfc3394
Copyright (C) 2021 Nicolas Mora
2021 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_NIST_KEYWRAP_H_INCLUDED
#define NETTLE_NIST_KEYWRAP_H_INCLUDED
#include "nettle-types.h"
#include "aes.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define nist_keywrap16 nettle_nist_keywrap16
#define nist_keyunwrap16 nettle_nist_keyunwrap16
#define aes128_keywrap nettle_aes128_keywrap
#define aes192_keywrap nettle_aes192_keywrap
#define aes256_keywrap nettle_aes256_keywrap
#define aes128_keyunwrap nettle_aes128_keyunwrap
#define aes192_keyunwrap nettle_aes192_keyunwrap
#define aes256_keyunwrap nettle_aes256_keyunwrap
void
nist_keywrap16 (const void *ctx, nettle_cipher_func *encrypt,
const uint8_t *iv, size_t ciphertext_length,
uint8_t *ciphertext, const uint8_t *cleartext);
int
nist_keyunwrap16 (const void *ctx, nettle_cipher_func *decrypt,
const uint8_t *iv, size_t cleartext_length,
uint8_t *cleartext, const uint8_t *ciphertext);
void
aes128_keywrap (struct aes128_ctx *ctx,
const uint8_t *iv, size_t ciphertext_length,
uint8_t *ciphertext, const uint8_t *cleartext);
void
aes192_keywrap (struct aes192_ctx *ctx,
const uint8_t *iv, size_t ciphertext_length,
uint8_t *ciphertext, const uint8_t *cleartext);
void
aes256_keywrap (struct aes256_ctx *ctx,
const uint8_t *iv, size_t ciphertext_length,
uint8_t *ciphertext, const uint8_t *cleartext);
int
aes128_keyunwrap (struct aes128_ctx *ctx,
const uint8_t *iv, size_t cleartext_length,
uint8_t *cleartext, const uint8_t *ciphertext);
int
aes192_keyunwrap (struct aes192_ctx *ctx,
const uint8_t *iv, size_t cleartext_length,
uint8_t *cleartext, const uint8_t *ciphertext);
int
aes256_keyunwrap (struct aes256_ctx *ctx,
const uint8_t *iv, size_t cleartext_length,
uint8_t *cleartext, const uint8_t *ciphertext);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_NIST_KEYWRAP_H_INCLUDED */

View File

@ -0,0 +1,189 @@
/* ocb.h
OCB AEAD mode, RFC 7253
Copyright (C) 2021 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_OCB_H_INCLUDED
#define NETTLE_OCB_H_INCLUDED
#include "nettle-types.h"
#include "aes.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define ocb_set_key nettle_ocb_set_key
#define ocb_set_nonce nettle_ocb_set_nonce
#define ocb_update nettle_ocb_update
#define ocb_encrypt nettle_ocb_encrypt
#define ocb_decrypt nettle_ocb_decrypt
#define ocb_digest nettle_ocb_digest
#define ocb_encrypt_message nettle_ocb_encrypt_message
#define ocb_decrypt_message nettle_ocb_decrypt_message
#define ocb_aes128_set_encrypt_key nettle_ocb_aes128_set_encrypt_key
#define ocb_aes128_set_decrypt_key nettle_ocb_aes128_set_decrypt_key
#define ocb_aes128_set_nonce nettle_ocb_aes128_set_nonce
#define ocb_aes128_update nettle_ocb_aes128_update
#define ocb_aes128_encrypt nettle_ocb_aes128_encrypt
#define ocb_aes128_decrypt nettle_ocb_aes128_decrypt
#define ocb_aes128_digest nettle_ocb_aes128_digest
#define ocb_aes128_encrypt_message nettle_ocb_aes128_encrypt_message
#define ocb_aes128_decrypt_message nettle_ocb_aes128_decrypt_message
#define OCB_BLOCK_SIZE 16
#define OCB_DIGEST_SIZE 16
#define OCB_MAX_NONCE_SIZE 15
struct ocb_key {
/* L_*, L_$ and L_0, and one reserved entry */
union nettle_block16 L[4];
};
struct ocb_ctx {
/* Initial offset, Offset_0 in the spec. */
union nettle_block16 initial;
/* Offset, updated per block. */
union nettle_block16 offset;
/* Authentication for the associated data */
union nettle_block16 sum;
/* Authentication for the message */
union nettle_block16 checksum;
/* Count of processed blocks. */
size_t data_count;
size_t message_count;
};
void
ocb_set_key (struct ocb_key *key, const void *cipher, nettle_cipher_func *f);
void
ocb_set_nonce (struct ocb_ctx *ctx,
const void *cipher, nettle_cipher_func *f,
size_t tag_length, size_t nonce_length, const uint8_t *nonce);
void
ocb_update (struct ocb_ctx *ctx, const struct ocb_key *key,
const void *cipher, nettle_cipher_func *f,
size_t length, const uint8_t *data);
void
ocb_encrypt (struct ocb_ctx *ctx, const struct ocb_key *key,
const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *dst, const uint8_t *src);
void
ocb_decrypt (struct ocb_ctx *ctx, const struct ocb_key *key,
const void *encrypt_ctx, nettle_cipher_func *encrypt,
const void *decrypt_ctx, nettle_cipher_func *decrypt,
size_t length, uint8_t *dst, const uint8_t *src);
void
ocb_digest (const struct ocb_ctx *ctx, const struct ocb_key *key,
const void *cipher, nettle_cipher_func *f,
size_t length, uint8_t *digest);
void
ocb_encrypt_message (const struct ocb_key *ocb_key,
const void *cipher, nettle_cipher_func *f,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t tlength,
size_t clength, uint8_t *dst, const uint8_t *src);
int
ocb_decrypt_message (const struct ocb_key *ocb_key,
const void *encrypt_ctx, nettle_cipher_func *encrypt,
const void *decrypt_ctx, nettle_cipher_func *decrypt,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t tlength,
size_t mlength, uint8_t *dst, const uint8_t *src);
/* OCB-AES */
/* This struct represents an expanded key for ocb-aes encryption. For
decryption, a separate decryption context is needed as well. */
struct ocb_aes128_encrypt_key
{
struct ocb_key ocb;
struct aes128_ctx encrypt;
};
void
ocb_aes128_set_encrypt_key (struct ocb_aes128_encrypt_key *ocb, const uint8_t *key);
void
ocb_aes128_set_decrypt_key (struct ocb_aes128_encrypt_key *ocb, struct aes128_ctx *decrypt,
const uint8_t *key);
void
ocb_aes128_set_nonce (struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,
size_t tag_length, size_t nonce_length, const uint8_t *nonce);
void
ocb_aes128_update (struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,
size_t length, const uint8_t *data);
void
ocb_aes128_encrypt(struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,
size_t length, uint8_t *dst, const uint8_t *src);
void
ocb_aes128_decrypt(struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,
const struct aes128_ctx *decrypt,
size_t length, uint8_t *dst, const uint8_t *src);
void
ocb_aes128_digest(struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,
size_t length, uint8_t *digest);
void
ocb_aes128_encrypt_message (const struct ocb_aes128_encrypt_key *key,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t tlength,
size_t clength, uint8_t *dst, const uint8_t *src);
int
ocb_aes128_decrypt_message (const struct ocb_aes128_encrypt_key *key,
const struct aes128_ctx *decrypt,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t tlength,
size_t mlength, uint8_t *dst, const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_OCB_H_INCLUDED */

View File

@ -0,0 +1,106 @@
/* pbkdf2.h
PKCS #5 password-based key derivation function PBKDF2, see RFC 2898.
Copyright (C) 2012 Simon Josefsson
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_PBKDF2_H_INCLUDED
#define NETTLE_PBKDF2_H_INCLUDED
#include "nettle-meta.h"
#ifdef __cplusplus
extern "C"
{
#endif
/* Namespace mangling */
#define pbkdf2 nettle_pbkdf2
#define pbkdf2_hmac_sha1 nettle_pbkdf2_hmac_sha1
#define pbkdf2_hmac_sha256 nettle_pbkdf2_hmac_sha256
#define pbkdf2_hmac_sha384 nettle_pbkdf2_hmac_sha384
#define pbkdf2_hmac_sha512 nettle_pbkdf2_hmac_sha512
#define pbkdf2_hmac_gosthash94cp nettle_pbkdf2_hmac_gosthash94cp
void
pbkdf2 (void *mac_ctx,
nettle_hash_update_func *update,
nettle_hash_digest_func *digest,
size_t digest_size, unsigned iterations,
size_t salt_length, const uint8_t *salt,
size_t length, uint8_t *dst);
#define PBKDF2(ctx, update, digest, digest_size, \
iterations, salt_length, salt, length, dst) \
(0 ? ((update)((ctx), 0, (uint8_t *) 0), \
(digest)((ctx), 0, (uint8_t *) 0)) \
: pbkdf2 ((ctx), \
(nettle_hash_update_func *)(update), \
(nettle_hash_digest_func *)(digest), \
(digest_size), (iterations), \
(salt_length), (salt), (length), (dst)))
/* PBKDF2 with specific PRFs. */
void
pbkdf2_hmac_sha1 (size_t key_length, const uint8_t *key,
unsigned iterations,
size_t salt_length, const uint8_t *salt,
size_t length, uint8_t *dst);
void
pbkdf2_hmac_sha256 (size_t key_length, const uint8_t *key,
unsigned iterations,
size_t salt_length, const uint8_t *salt,
size_t length, uint8_t *dst);
void
pbkdf2_hmac_sha384 (size_t key_length, const uint8_t *key,
unsigned iterations,
size_t salt_length, const uint8_t *salt,
size_t length, uint8_t *dst);
void
pbkdf2_hmac_sha512 (size_t key_length, const uint8_t *key,
unsigned iterations,
size_t salt_length, const uint8_t *salt,
size_t length, uint8_t *dst);
void
pbkdf2_hmac_gosthash94cp (size_t key_length, const uint8_t *key,
unsigned iterations,
size_t salt_length, const uint8_t *salt,
size_t length, uint8_t *dst);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_PBKDF2_H_INCLUDED */

View File

@ -0,0 +1,248 @@
/* pgp.h
PGP related functions.
Copyright (C) 2001, 2002 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_PGP_H_INCLUDED
#define NETTLE_PGP_H_INCLUDED
#include <time.h>
#include "nettle-types.h"
#include "bignum.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define pgp_put_uint32 nettle_pgp_put_uint32
#define pgp_put_uint16 nettle_pgp_put_uint16
#define pgp_put_mpi nettle_pgp_put_mpi
#define pgp_put_string nettle_pgp_put_string
#define pgp_put_length nettle_pgp_put_length
#define pgp_put_header nettle_pgp_put_header
#define pgp_put_header_length nettle_pgp_put_header_length
#define pgp_sub_packet_start nettle_pgp_sub_packet_start
#define pgp_put_sub_packet nettle_pgp_put_sub_packet
#define pgp_sub_packet_end nettle_pgp_sub_packet_end
#define pgp_put_public_rsa_key nettle_pgp_put_public_rsa_key
#define pgp_put_rsa_sha1_signature nettle_pgp_put_rsa_sha1_signature
#define pgp_put_userid nettle_pgp_put_userid
#define pgp_crc24 nettle_pgp_crc24
#define pgp_armor nettle_pgp_armor
struct nettle_buffer;
struct rsa_public_key;
struct rsa_private_key;
struct sha1_ctx;
int
pgp_put_uint32(struct nettle_buffer *buffer, uint32_t i);
int
pgp_put_uint16(struct nettle_buffer *buffer, unsigned i);
int
pgp_put_mpi(struct nettle_buffer *buffer, const mpz_t x);
int
pgp_put_string(struct nettle_buffer *buffer,
unsigned length,
const uint8_t *s);
int
pgp_put_length(struct nettle_buffer *buffer,
unsigned length);
int
pgp_put_header(struct nettle_buffer *buffer,
unsigned tag, unsigned length);
void
pgp_put_header_length(struct nettle_buffer *buffer,
/* start of the header */
unsigned start,
unsigned field_size);
unsigned
pgp_sub_packet_start(struct nettle_buffer *buffer);
int
pgp_put_sub_packet(struct nettle_buffer *buffer,
unsigned type,
unsigned length,
const uint8_t *data);
void
pgp_sub_packet_end(struct nettle_buffer *buffer, unsigned start);
int
pgp_put_public_rsa_key(struct nettle_buffer *,
const struct rsa_public_key *key,
time_t timestamp);
int
pgp_put_rsa_sha1_signature(struct nettle_buffer *buffer,
const struct rsa_private_key *key,
const uint8_t *keyid,
unsigned type,
struct sha1_ctx *hash);
int
pgp_put_userid(struct nettle_buffer *buffer,
unsigned length,
const uint8_t *name);
uint32_t
pgp_crc24(unsigned length, const uint8_t *data);
int
pgp_armor(struct nettle_buffer *buffer,
const char *tag,
unsigned length,
const uint8_t *data);
/* Values that can be passed to pgp_put_header when the size of the
* length field, but not the length itself, is known. Also the minimum length
* for the given field size. */
enum pgp_lengths
{
PGP_LENGTH_ONE_OCTET = 0,
PGP_LENGTH_TWO_OCTETS = 192,
PGP_LENGTH_FOUR_OCTETS = 8384,
};
enum pgp_public_key_algorithm
{
PGP_RSA = 1,
PGP_RSA_ENCRYPT = 2,
PGP_RSA_SIGN = 3,
PGP_EL_GAMAL_ENCRYPT = 16,
PGP_DSA = 17,
PGP_EL_GAMAL = 20,
};
enum pgp_symmetric_algorithm
{
PGP_PLAINTEXT = 0,
PGP_IDEA = 1,
PGP_3DES = 2,
PGP_CAST5 = 3,
PGP_BLOWFISH = 4,
PGP_SAFER_SK = 5,
PGP_AES128 = 7,
PGP_AES192 = 8,
PGP_AES256 = 9,
};
enum pgp_compression_algorithm
{
PGP_UNCOMPRESSED = 0,
PGP_ZIP = 1,
PGP_ZLIB = 2,
};
enum pgp_hash_algorithm
{
PGP_MD5 = 1,
PGP_SHA1 = 2,
PGP_RIPEMD = 3,
PGP_MD2 = 5,
PGP_TIGER192 = 6,
PGP_HAVAL = 7,
};
enum pgp_tag
{
PGP_TAG_PUBLIC_SESSION_KEY = 1,
PGP_TAG_SIGNATURE = 2,
PGP_TAG_SYMMETRIC_SESSION_KEY = 3,
PGP_TAG_ONE_PASS_SIGNATURE = 4,
PGP_TAG_SECRET_KEY = 5,
PGP_TAG_PUBLIC_KEY = 6,
PGP_TAG_SECRET_SUBKEY = 7,
PGP_TAG_COMPRESSED = 8,
PGP_TAG_ENCRYPTED = 9,
PGP_TAG_MARKER = 10,
PGP_TAG_LITERAL = 11,
PGP_TAG_TRUST = 12,
PGP_TAG_USERID = 13,
PGP_TAG_PUBLIC_SUBKEY = 14,
};
enum pgp_signature_type
{
PGP_SIGN_BINARY = 0,
PGP_SIGN_TEXT = 1,
PGP_SIGN_STANDALONE = 2,
PGP_SIGN_CERTIFICATION = 0x10,
PGP_SIGN_CERTIFICATION_PERSONA = 0x11,
PGP_SIGN_CERTIFICATION_CASUAL = 0x12,
PGP_SIGN_CERTIFICATION_POSITIVE = 0x13,
PGP_SIGN_SUBKEY = 0x18,
PGP_SIGN_KEY = 0x1f,
PGP_SIGN_REVOCATION = 0x20,
PGP_SIGN_REVOCATION_SUBKEY = 0x28,
PGP_SIGN_REVOCATION_CERTIFICATE = 0x30,
PGP_SIGN_TIMESTAMP = 0x40,
};
enum pgp_subpacket_tag
{
PGP_SUBPACKET_CREATION_TIME = 2,
PGP_SUBPACKET_SIGNATURE_EXPIRATION_TIME = 3,
PGP_SUBPACKET_EXPORTABLE_CERTIFICATION = 4,
PGP_SUBPACKET_TRUST_SIGNATURE = 5,
PGP_SUBPACKET_REGULAR_EXPRESSION = 6,
PGP_SUBPACKET_REVOCABLE = 7,
PGP_SUBPACKET_KEY_EXPIRATION_TIME = 9,
PGP_SUBPACKET_PLACEHOLDER = 10 ,
PGP_SUBPACKET_PREFERRED_SYMMETRIC_ALGORITHMS = 11,
PGP_SUBPACKET_REVOCATION_KEY = 12,
PGP_SUBPACKET_ISSUER_KEY_ID = 16,
PGP_SUBPACKET_NOTATION_DATA = 20,
PGP_SUBPACKET_PREFERRED_HASH_ALGORITHMS = 21,
PGP_SUBPACKET_PREFERRED_COMPRESSION_ALGORITHMS = 22,
PGP_SUBPACKET_KEY_SERVER_PREFERENCES = 23,
PGP_SUBPACKET_PREFERRED_KEY_SERVER = 24,
PGP_SUBPACKET_PRIMARY_USER_ID = 25,
PGP_SUBPACKET_POLICY_URL = 26,
PGP_SUBPACKET_KEY_FLAGS = 27,
PGP_SUBPACKET_SIGNERS_USER_ID = 28,
PGP_SUBPACKET_REASON_FOR_REVOCATION = 29,
};
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_PGP_H_INCLUDED */

View File

@ -0,0 +1,106 @@
/* pkcs1.h
PKCS1 embedding.
Copyright (C) 2003 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_PKCS1_H_INCLUDED
#define NETTLE_PKCS1_H_INCLUDED
#include "nettle-types.h"
#include "bignum.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define pkcs1_rsa_digest_encode nettle_pkcs1_rsa_digest_encode
#define pkcs1_rsa_md5_encode nettle_pkcs1_rsa_md5_encode
#define pkcs1_rsa_md5_encode_digest nettle_pkcs1_rsa_md5_encode_digest
#define pkcs1_rsa_sha1_encode nettle_pkcs1_rsa_sha1_encode
#define pkcs1_rsa_sha1_encode_digest nettle_pkcs1_rsa_sha1_encode_digest
#define pkcs1_rsa_sha256_encode nettle_pkcs1_rsa_sha256_encode
#define pkcs1_rsa_sha256_encode_digest nettle_pkcs1_rsa_sha256_encode_digest
#define pkcs1_rsa_sha512_encode nettle_pkcs1_rsa_sha512_encode
#define pkcs1_rsa_sha512_encode_digest nettle_pkcs1_rsa_sha512_encode_digest
#define pkcs1_encrypt nettle_pkcs1_encrypt
#define pkcs1_decrypt nettle_pkcs1_decrypt
struct md5_ctx;
struct sha1_ctx;
struct sha256_ctx;
struct sha512_ctx;
int
pkcs1_encrypt (size_t key_size,
/* For padding */
void *random_ctx, nettle_random_func *random,
size_t length, const uint8_t *message,
mpz_t m);
int
pkcs1_decrypt (size_t key_size,
const mpz_t m,
size_t *length, uint8_t *message);
int
pkcs1_rsa_digest_encode(mpz_t m, size_t key_size,
size_t di_length, const uint8_t *digest_info);
int
pkcs1_rsa_md5_encode(mpz_t m, size_t length, struct md5_ctx *hash);
int
pkcs1_rsa_md5_encode_digest(mpz_t m, size_t length, const uint8_t *digest);
int
pkcs1_rsa_sha1_encode(mpz_t m, size_t length, struct sha1_ctx *hash);
int
pkcs1_rsa_sha1_encode_digest(mpz_t m, size_t length, const uint8_t *digest);
int
pkcs1_rsa_sha256_encode(mpz_t m, size_t length, struct sha256_ctx *hash);
int
pkcs1_rsa_sha256_encode_digest(mpz_t m, size_t length, const uint8_t *digest);
int
pkcs1_rsa_sha512_encode(mpz_t m, size_t length, struct sha512_ctx *hash);
int
pkcs1_rsa_sha512_encode_digest(mpz_t m, size_t length, const uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_PKCS1_H_INCLUDED */

View File

@ -0,0 +1,114 @@
/* poly1305.h
Poly1305 message authentication code.
Copyright (C) 2013 Nikos Mavrogiannopoulos
Copyright (C) 2013, 2014 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_POLY1305_H_INCLUDED
#define NETTLE_POLY1305_H_INCLUDED
#include "aes.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define poly1305_aes_set_key nettle_poly1305_aes_set_key
#define poly1305_aes_set_nonce nettle_poly1305_aes_set_nonce
#define poly1305_aes_update nettle_poly1305_aes_update
#define poly1305_aes_digest nettle_poly1305_aes_digest
/* Low level functions/macros for the poly1305 construction. */
#define POLY1305_BLOCK_SIZE 16
struct poly1305_ctx {
/* Key, 128-bit value and some cached multiples. */
union
{
uint32_t r32[6];
uint64_t r64[3];
} r;
uint32_t s32[3];
/* State, represented as words of 26, 32 or 64 bits, depending on
implementation. */
/* High bits first, to maintain alignment. */
uint32_t hh;
union
{
uint32_t h32[4];
uint64_t h64[2];
} h;
};
/* poly1305-aes */
#define POLY1305_AES_KEY_SIZE 32
#define POLY1305_AES_DIGEST_SIZE 16
#define POLY1305_AES_NONCE_SIZE 16
struct poly1305_aes_ctx
{
/* Keep aes context last, to make it possible to use a general
poly1305_update if other variants are added. */
struct poly1305_ctx pctx;
uint8_t block[POLY1305_BLOCK_SIZE];
unsigned index;
uint8_t nonce[POLY1305_BLOCK_SIZE];
struct aes128_ctx aes;
};
/* Also initialize the nonce to zero. */
void
poly1305_aes_set_key (struct poly1305_aes_ctx *ctx, const uint8_t *key);
/* Optional, if not used, messages get incrementing nonces starting
from zero. */
void
poly1305_aes_set_nonce (struct poly1305_aes_ctx *ctx,
const uint8_t *nonce);
/* Update is not aes-specific, but since this is the only implemented
variant, we need no more general poly1305_update. */
void
poly1305_aes_update (struct poly1305_aes_ctx *ctx, size_t length, const uint8_t *data);
/* Also increments the nonce */
void
poly1305_aes_digest (struct poly1305_aes_ctx *ctx,
size_t length, uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_POLY1305_H_INCLUDED */

View File

@ -0,0 +1,58 @@
/* pss-mgf1.h
PKCS#1 mask generation function 1, used in RSA-PSS (RFC-3447).
Copyright (C) 2017 Daiki Ueno
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_PSS_MGF1_H_INCLUDED
#define NETTLE_PSS_MGF1_H_INCLUDED
#include "nettle-meta.h"
#include "sha1.h"
#include "sha2.h"
#ifdef __cplusplus
extern "C"
{
#endif
/* Namespace mangling */
#define pss_mgf1 nettle_pss_mgf1
void
pss_mgf1(const void *seed, const struct nettle_hash *hash,
size_t length, uint8_t *mask);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_PSS_MGF1_H_INCLUDED */

View File

@ -0,0 +1,65 @@
/* pss.h
PKCS#1 RSA-PSS (RFC-3447).
Copyright (C) 2017 Daiki Ueno
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_PSS_H_INCLUDED
#define NETTLE_PSS_H_INCLUDED
#include "nettle-meta.h"
#include "bignum.h"
#ifdef __cplusplus
extern "C"
{
#endif
/* Namespace mangling */
#define pss_encode_mgf1 nettle_pss_encode_mgf1
#define pss_verify_mgf1 nettle_pss_verify_mgf1
int
pss_encode_mgf1(mpz_t m, size_t bits,
const struct nettle_hash *hash,
size_t salt_length, const uint8_t *salt,
const uint8_t *digest);
int
pss_verify_mgf1(const mpz_t m, size_t bits,
const struct nettle_hash *hash,
size_t salt_length,
const uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_PSS_H_INCLUDED */

View File

@ -0,0 +1,48 @@
/* realloc.h
Copyright (C) 2002 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_REALLOC_H_INCLUDED
#define NETTLE_REALLOC_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
nettle_realloc_func nettle_realloc;
nettle_realloc_func nettle_xrealloc;
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_REALLOC_H_INCLUDED */

View File

@ -0,0 +1,83 @@
/* ripemd160.h
RIPEMD-160 hash function.
Copyright (C) 2011 Andres Mejia
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_RIPEMD160_H_INCLUDED
#define NETTLE_RIPEMD160_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
#include "nettle-types.h"
/* Name mangling */
#define ripemd160_init nettle_ripemd160_init
#define ripemd160_update nettle_ripemd160_update
#define ripemd160_digest nettle_ripemd160_digest
/* RIPEMD160 */
#define RIPEMD160_DIGEST_SIZE 20
#define RIPEMD160_BLOCK_SIZE 64
/* For backwards compatibility */
#define RIPEMD160_DATA_SIZE RIPEMD160_BLOCK_SIZE
/* Digest is kept internally as 5 32-bit words. */
#define _RIPEMD160_DIGEST_LENGTH 5
struct ripemd160_ctx
{
uint32_t state[_RIPEMD160_DIGEST_LENGTH];
uint64_t count; /* 64-bit block count */
unsigned int index;
uint8_t block[RIPEMD160_BLOCK_SIZE];
};
void
ripemd160_init(struct ripemd160_ctx *ctx);
void
ripemd160_update(struct ripemd160_ctx *ctx,
size_t length,
const uint8_t *data);
void
ripemd160_digest(struct ripemd160_ctx *ctx,
size_t length,
uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_RIPEMD160_H_INCLUDED */

View File

@ -0,0 +1,538 @@
/* rsa.h
The RSA publickey algorithm.
Copyright (C) 2001, 2002 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_RSA_H_INCLUDED
#define NETTLE_RSA_H_INCLUDED
#include "nettle-types.h"
#include "bignum.h"
#include "md5.h"
#include "sha1.h"
#include "sha2.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define rsa_public_key_init nettle_rsa_public_key_init
#define rsa_public_key_clear nettle_rsa_public_key_clear
#define rsa_public_key_prepare nettle_rsa_public_key_prepare
#define rsa_private_key_init nettle_rsa_private_key_init
#define rsa_private_key_clear nettle_rsa_private_key_clear
#define rsa_private_key_prepare nettle_rsa_private_key_prepare
#define rsa_pkcs1_verify nettle_rsa_pkcs1_verify
#define rsa_pkcs1_sign nettle_rsa_pkcs1_sign
#define rsa_pkcs1_sign_tr nettle_rsa_pkcs1_sign_tr
#define rsa_md5_sign nettle_rsa_md5_sign
#define rsa_md5_sign_tr nettle_rsa_md5_sign_tr
#define rsa_md5_verify nettle_rsa_md5_verify
#define rsa_sha1_sign nettle_rsa_sha1_sign
#define rsa_sha1_sign_tr nettle_rsa_sha1_sign_tr
#define rsa_sha1_verify nettle_rsa_sha1_verify
#define rsa_sha256_sign nettle_rsa_sha256_sign
#define rsa_sha256_sign_tr nettle_rsa_sha256_sign_tr
#define rsa_sha256_verify nettle_rsa_sha256_verify
#define rsa_sha512_sign nettle_rsa_sha512_sign
#define rsa_sha512_sign_tr nettle_rsa_sha512_sign_tr
#define rsa_sha512_verify nettle_rsa_sha512_verify
#define rsa_md5_sign_digest nettle_rsa_md5_sign_digest
#define rsa_md5_sign_digest_tr nettle_rsa_md5_sign_digest_tr
#define rsa_md5_verify_digest nettle_rsa_md5_verify_digest
#define rsa_sha1_sign_digest nettle_rsa_sha1_sign_digest
#define rsa_sha1_sign_digest_tr nettle_rsa_sha1_sign_digest_tr
#define rsa_sha1_verify_digest nettle_rsa_sha1_verify_digest
#define rsa_sha256_sign_digest nettle_rsa_sha256_sign_digest
#define rsa_sha256_sign_digest_tr nettle_rsa_sha256_sign_digest_tr
#define rsa_sha256_verify_digest nettle_rsa_sha256_verify_digest
#define rsa_sha512_sign_digest nettle_rsa_sha512_sign_digest
#define rsa_sha512_sign_digest_tr nettle_rsa_sha512_sign_digest_tr
#define rsa_sha512_verify_digest nettle_rsa_sha512_verify_digest
#define rsa_pss_sha256_sign_digest_tr nettle_rsa_pss_sha256_sign_digest_tr
#define rsa_pss_sha256_verify_digest nettle_rsa_pss_sha256_verify_digest
#define rsa_pss_sha384_sign_digest_tr nettle_rsa_pss_sha384_sign_digest_tr
#define rsa_pss_sha384_verify_digest nettle_rsa_pss_sha384_verify_digest
#define rsa_pss_sha512_sign_digest_tr nettle_rsa_pss_sha512_sign_digest_tr
#define rsa_pss_sha512_verify_digest nettle_rsa_pss_sha512_verify_digest
#define rsa_encrypt nettle_rsa_encrypt
#define rsa_decrypt nettle_rsa_decrypt
#define rsa_decrypt_tr nettle_rsa_decrypt_tr
#define rsa_sec_decrypt nettle_rsa_sec_decrypt
#define rsa_compute_root nettle_rsa_compute_root
#define rsa_compute_root_tr nettle_rsa_compute_root_tr
#define rsa_generate_keypair nettle_rsa_generate_keypair
#define rsa_keypair_to_sexp nettle_rsa_keypair_to_sexp
#define rsa_keypair_from_sexp_alist nettle_rsa_keypair_from_sexp_alist
#define rsa_keypair_from_sexp nettle_rsa_keypair_from_sexp
#define rsa_public_key_from_der_iterator nettle_rsa_public_key_from_der_iterator
#define rsa_private_key_from_der_iterator nettle_rsa_private_key_from_der_iterator
#define rsa_keypair_from_der nettle_rsa_keypair_from_der
#define rsa_keypair_to_openpgp nettle_rsa_keypair_to_openpgp
/* This limit is somewhat arbitrary. Technically, the smallest modulo
which makes sense at all is 15 = 3*5, phi(15) = 8, size 4 bits. But
for ridiculously small keys, not all odd e are possible (e.g., for
5 bits, the only possible modulo is 3*7 = 21, phi(21) = 12, and e =
3 don't work). The smallest size that makes sense with pkcs#1, and
which allows RSA encryption of one byte messages, is 12 octets, 89
bits. */
#define RSA_MINIMUM_N_OCTETS 12
#define RSA_MINIMUM_N_BITS (8*RSA_MINIMUM_N_OCTETS - 7)
struct rsa_public_key
{
/* Size of the modulo, in octets. This is also the size of all
* signatures that are created or verified with this key. */
size_t size;
/* Modulo */
mpz_t n;
/* Public exponent */
mpz_t e;
};
struct rsa_private_key
{
size_t size;
/* d is filled in by the key generation function; otherwise it's
* completely unused. */
mpz_t d;
/* The two factors */
mpz_t p; mpz_t q;
/* d % (p-1), i.e. a e = 1 (mod (p-1)) */
mpz_t a;
/* d % (q-1), i.e. b e = 1 (mod (q-1)) */
mpz_t b;
/* modular inverse of q , i.e. c q = 1 (mod p) */
mpz_t c;
};
/* Signing a message works as follows:
*
* Store the private key in a rsa_private_key struct.
*
* Call rsa_private_key_prepare. This initializes the size attribute
* to the length of a signature.
*
* Initialize a hashing context, by callling
* md5_init
*
* Hash the message by calling
* md5_update
*
* Create the signature by calling
* rsa_md5_sign
*
* The signature is represented as a mpz_t bignum. This call also
* resets the hashing context.
*
* When done with the key and signature, don't forget to call
* mpz_clear.
*/
/* Calls mpz_init to initialize bignum storage. */
void
rsa_public_key_init(struct rsa_public_key *key);
/* Calls mpz_clear to deallocate bignum storage. */
void
rsa_public_key_clear(struct rsa_public_key *key);
int
rsa_public_key_prepare(struct rsa_public_key *key);
/* Calls mpz_init to initialize bignum storage. */
void
rsa_private_key_init(struct rsa_private_key *key);
/* Calls mpz_clear to deallocate bignum storage. */
void
rsa_private_key_clear(struct rsa_private_key *key);
int
rsa_private_key_prepare(struct rsa_private_key *key);
/* PKCS#1 style signatures */
int
rsa_pkcs1_sign(const struct rsa_private_key *key,
size_t length, const uint8_t *digest_info,
mpz_t s);
int
rsa_pkcs1_sign_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
size_t length, const uint8_t *digest_info,
mpz_t s);
int
rsa_pkcs1_verify(const struct rsa_public_key *key,
size_t length, const uint8_t *digest_info,
const mpz_t signature);
int
rsa_md5_sign(const struct rsa_private_key *key,
struct md5_ctx *hash,
mpz_t signature);
int
rsa_md5_sign_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
struct md5_ctx *hash, mpz_t s);
int
rsa_md5_verify(const struct rsa_public_key *key,
struct md5_ctx *hash,
const mpz_t signature);
int
rsa_sha1_sign(const struct rsa_private_key *key,
struct sha1_ctx *hash,
mpz_t signature);
int
rsa_sha1_sign_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
struct sha1_ctx *hash,
mpz_t s);
int
rsa_sha1_verify(const struct rsa_public_key *key,
struct sha1_ctx *hash,
const mpz_t signature);
int
rsa_sha256_sign(const struct rsa_private_key *key,
struct sha256_ctx *hash,
mpz_t signature);
int
rsa_sha256_sign_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
struct sha256_ctx *hash,
mpz_t s);
int
rsa_sha256_verify(const struct rsa_public_key *key,
struct sha256_ctx *hash,
const mpz_t signature);
int
rsa_sha512_sign(const struct rsa_private_key *key,
struct sha512_ctx *hash,
mpz_t signature);
int
rsa_sha512_sign_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
struct sha512_ctx *hash,
mpz_t s);
int
rsa_sha512_verify(const struct rsa_public_key *key,
struct sha512_ctx *hash,
const mpz_t signature);
/* Variants taking the digest as argument. */
int
rsa_md5_sign_digest(const struct rsa_private_key *key,
const uint8_t *digest,
mpz_t s);
int
rsa_md5_sign_digest_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
const uint8_t *digest, mpz_t s);
int
rsa_md5_verify_digest(const struct rsa_public_key *key,
const uint8_t *digest,
const mpz_t signature);
int
rsa_sha1_sign_digest(const struct rsa_private_key *key,
const uint8_t *digest,
mpz_t s);
int
rsa_sha1_sign_digest_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
const uint8_t *digest,
mpz_t s);
int
rsa_sha1_verify_digest(const struct rsa_public_key *key,
const uint8_t *digest,
const mpz_t signature);
int
rsa_sha256_sign_digest(const struct rsa_private_key *key,
const uint8_t *digest,
mpz_t s);
int
rsa_sha256_sign_digest_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
const uint8_t *digest,
mpz_t s);
int
rsa_sha256_verify_digest(const struct rsa_public_key *key,
const uint8_t *digest,
const mpz_t signature);
int
rsa_sha512_sign_digest(const struct rsa_private_key *key,
const uint8_t *digest,
mpz_t s);
int
rsa_sha512_sign_digest_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
const uint8_t *digest,
mpz_t s);
int
rsa_sha512_verify_digest(const struct rsa_public_key *key,
const uint8_t *digest,
const mpz_t signature);
/* PSS style signatures */
int
rsa_pss_sha256_sign_digest_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
size_t salt_length, const uint8_t *salt,
const uint8_t *digest,
mpz_t s);
int
rsa_pss_sha256_verify_digest(const struct rsa_public_key *key,
size_t salt_length,
const uint8_t *digest,
const mpz_t signature);
int
rsa_pss_sha384_sign_digest_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
size_t salt_length, const uint8_t *salt,
const uint8_t *digest,
mpz_t s);
int
rsa_pss_sha384_verify_digest(const struct rsa_public_key *key,
size_t salt_length,
const uint8_t *digest,
const mpz_t signature);
int
rsa_pss_sha512_sign_digest_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
size_t salt_length, const uint8_t *salt,
const uint8_t *digest,
mpz_t s);
int
rsa_pss_sha512_verify_digest(const struct rsa_public_key *key,
size_t salt_length,
const uint8_t *digest,
const mpz_t signature);
/* RSA encryption, using PKCS#1 */
/* These functions uses the v1.5 padding. What should the v2 (OAEP)
* functions be called? */
/* Returns 1 on success, 0 on failure, which happens if the
* message is too long for the key. */
int
rsa_encrypt(const struct rsa_public_key *key,
/* For padding */
void *random_ctx, nettle_random_func *random,
size_t length, const uint8_t *cleartext,
mpz_t cipher);
/* Message must point to a buffer of size *LENGTH. KEY->size is enough
* for all valid messages. On success, *LENGTH is updated to reflect
* the actual length of the message. Returns 1 on success, 0 on
* failure, which happens if decryption failed or if the message
* didn't fit. */
int
rsa_decrypt(const struct rsa_private_key *key,
size_t *length, uint8_t *cleartext,
const mpz_t ciphertext);
/* Timing-resistant version, using randomized RSA blinding. */
int
rsa_decrypt_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
size_t *length, uint8_t *message,
const mpz_t gibberish);
/* like rsa_decrypt_tr but with additional side-channel resistance.
* NOTE: the length of the final message must be known in advance. */
int
rsa_sec_decrypt(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
size_t length, uint8_t *message,
const mpz_t gibberish);
/* Compute x, the e:th root of m. Calling it with x == m is allowed.
It is required that 0 <= m < n. */
void
rsa_compute_root(const struct rsa_private_key *key,
mpz_t x, const mpz_t m);
/* Safer variant, using RSA blinding, and checking the result after
CRT. It is required that 0 <= m < n. */
int
rsa_compute_root_tr(const struct rsa_public_key *pub,
const struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
mpz_t x, const mpz_t m);
/* Key generation */
/* Note that the key structs must be initialized first. */
int
rsa_generate_keypair(struct rsa_public_key *pub,
struct rsa_private_key *key,
void *random_ctx, nettle_random_func *random,
void *progress_ctx, nettle_progress_func *progress,
/* Desired size of modulo, in bits */
unsigned n_size,
/* Desired size of public exponent, in bits. If
* zero, the passed in value pub->e is used. */
unsigned e_size);
#define RSA_SIGN(key, algorithm, ctx, length, data, signature) ( \
algorithm##_update(ctx, length, data), \
rsa_##algorithm##_sign(key, ctx, signature) \
)
#define RSA_VERIFY(key, algorithm, ctx, length, data, signature) ( \
algorithm##_update(ctx, length, data), \
rsa_##algorithm##_verify(key, ctx, signature) \
)
/* Keys in sexp form. */
struct nettle_buffer;
/* Generates a public-key expression if PRIV is NULL .*/
int
rsa_keypair_to_sexp(struct nettle_buffer *buffer,
const char *algorithm_name, /* NULL means "rsa" */
const struct rsa_public_key *pub,
const struct rsa_private_key *priv);
struct sexp_iterator;
int
rsa_keypair_from_sexp_alist(struct rsa_public_key *pub,
struct rsa_private_key *priv,
unsigned limit,
struct sexp_iterator *i);
/* If PRIV is NULL, expect a public-key expression. If PUB is NULL,
* expect a private key expression and ignore the parts not needed for
* the public key. */
/* Keys must be initialized before calling this function, as usual. */
int
rsa_keypair_from_sexp(struct rsa_public_key *pub,
struct rsa_private_key *priv,
unsigned limit,
size_t length, const uint8_t *expr);
/* Keys in PKCS#1 format. */
struct asn1_der_iterator;
int
rsa_public_key_from_der_iterator(struct rsa_public_key *pub,
unsigned limit,
struct asn1_der_iterator *i);
int
rsa_private_key_from_der_iterator(struct rsa_public_key *pub,
struct rsa_private_key *priv,
unsigned limit,
struct asn1_der_iterator *i);
/* For public keys, use PRIV == NULL */
int
rsa_keypair_from_der(struct rsa_public_key *pub,
struct rsa_private_key *priv,
unsigned limit,
size_t length, const uint8_t *data);
/* OpenPGP format. Experimental interface, subject to change. */
int
rsa_keypair_to_openpgp(struct nettle_buffer *buffer,
const struct rsa_public_key *pub,
const struct rsa_private_key *priv,
/* A single user id. NUL-terminated utf8. */
const char *userid);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_RSA_H_INCLUDED */

View File

@ -0,0 +1,110 @@
/* salsa20.h
The Salsa20 stream cipher.
Copyright (C) 2012 Simon Josefsson
Copyright (C) 2001 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_SALSA20_H_INCLUDED
#define NETTLE_SALSA20_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define salsa20_set_key nettle_salsa20_set_key
#define salsa20_128_set_key nettle_salsa20_128_set_key
#define salsa20_256_set_key nettle_salsa20_256_set_key
#define salsa20_set_nonce nettle_salsa20_set_nonce
#define salsa20_crypt nettle_salsa20_crypt
#define salsa20r12_crypt nettle_salsa20r12_crypt
/* Alias for backwards compatibility */
#define salsa20_set_iv nettle_salsa20_set_nonce
/* In octets.*/
#define SALSA20_128_KEY_SIZE 16
#define SALSA20_256_KEY_SIZE 32
#define SALSA20_BLOCK_SIZE 64
#define SALSA20_NONCE_SIZE 8
#define SALSA20_IV_SIZE SALSA20_NONCE_SIZE
/* Aliases */
#define SALSA20_MIN_KEY_SIZE 16
#define SALSA20_MAX_KEY_SIZE 32
#define SALSA20_KEY_SIZE 32
#define _SALSA20_INPUT_LENGTH 16
struct salsa20_ctx
{
/* Indices 1-4 and 11-14 holds the key (two identical copies for the
shorter key size), indices 0, 5, 10, 15 are constant, indices 6, 7
are the IV, and indices 8, 9 are the block counter:
C K K K
K C I I
B B C K
K K K C
*/
uint32_t input[_SALSA20_INPUT_LENGTH];
};
void
salsa20_128_set_key(struct salsa20_ctx *ctx, const uint8_t *key);
void
salsa20_256_set_key(struct salsa20_ctx *ctx, const uint8_t *key);
void
salsa20_set_key(struct salsa20_ctx *ctx,
size_t length, const uint8_t *key);
void
salsa20_set_nonce(struct salsa20_ctx *ctx, const uint8_t *nonce);
void
salsa20_crypt(struct salsa20_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
void
salsa20r12_crypt(struct salsa20_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SALSA20_H_INCLUDED */

View File

@ -0,0 +1,102 @@
/* serpent.h
The serpent block cipher.
Copyright (C) 2001 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
/* Serpent is a 128-bit block cipher that accepts a key size of 256
* bits, designed by Ross Anderson, Eli Biham, and Lars Knudsen. See
* http://www.cl.cam.ac.uk/~rja14/serpent.html for details.
*/
#ifndef NETTLE_SERPENT_H_INCLUDED
#define NETTLE_SERPENT_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define serpent_set_key nettle_serpent_set_key
#define serpent128_set_key nettle_serpent128_set_key
#define serpent192_set_key nettle_serpent192_set_key
#define serpent256_set_key nettle_serpent256_set_key
#define serpent_encrypt nettle_serpent_encrypt
#define serpent_decrypt nettle_serpent_decrypt
#define SERPENT_BLOCK_SIZE 16
/* Other key lengths are possible, but the design of Serpent makes
* smaller key lengths quite pointless; they cheated with the AES
* requirements, using a 256-bit key length exclusively and just
* padding it out if the desired key length was less, so there really
* is no advantage to using key lengths less than 256 bits. */
#define SERPENT_KEY_SIZE 32
/* Allow keys of size 128 <= bits <= 256 */
#define SERPENT_MIN_KEY_SIZE 16
#define SERPENT_MAX_KEY_SIZE 32
#define SERPENT128_KEY_SIZE 16
#define SERPENT192_KEY_SIZE 24
#define SERPENT256_KEY_SIZE 32
struct serpent_ctx
{
uint32_t keys[33][4]; /* key schedule */
};
void
serpent_set_key(struct serpent_ctx *ctx,
size_t length, const uint8_t *key);
void
serpent128_set_key(struct serpent_ctx *ctx, const uint8_t *key);
void
serpent192_set_key(struct serpent_ctx *ctx, const uint8_t *key);
void
serpent256_set_key(struct serpent_ctx *ctx, const uint8_t *key);
void
serpent_encrypt(const struct serpent_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
void
serpent_decrypt(const struct serpent_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SERPENT_H_INCLUDED */

View File

@ -0,0 +1,213 @@
/* sexp.h
Parsing s-expressions.
Copyright (C) 2002 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_SEXP_H_INCLUDED
#define NETTLE_SEXP_H_INCLUDED
#include <stdarg.h>
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define sexp_iterator_first nettle_sexp_iterator_first
#define sexp_transport_iterator_first nettle_sexp_transport_iterator_first
#define sexp_iterator_next nettle_sexp_iterator_next
#define sexp_iterator_enter_list nettle_sexp_iterator_enter_list
#define sexp_iterator_exit_list nettle_sexp_iterator_exit_list
#define sexp_iterator_subexpr nettle_sexp_iterator_subexpr
#define sexp_iterator_get_uint32 nettle_sexp_iterator_get_uint32
#define sexp_iterator_check_type nettle_sexp_iterator_check_type
#define sexp_iterator_check_types nettle_sexp_iterator_check_types
#define sexp_iterator_assoc nettle_sexp_iterator_assoc
#define sexp_format nettle_sexp_format
#define sexp_vformat nettle_sexp_vformat
#define sexp_transport_format nettle_sexp_transport_format
#define sexp_transport_vformat nettle_sexp_transport_vformat
#define sexp_token_chars nettle_sexp_token_chars
enum sexp_type
{ SEXP_ATOM, SEXP_LIST, SEXP_END };
struct sexp_iterator
{
size_t length;
const uint8_t *buffer;
/* Points at the start of the current sub expression. */
size_t start;
/* If type is SEXP_LIST, pos points at the start of the current
* element. Otherwise, it points at the end. */
size_t pos;
unsigned level;
enum sexp_type type;
size_t display_length;
const uint8_t *display;
size_t atom_length;
const uint8_t *atom;
};
/* All these functions return 1 on success, 0 on failure */
/* Initializes the iterator. */
int
sexp_iterator_first(struct sexp_iterator *iterator,
size_t length, const uint8_t *input);
/* NOTE: Decodes the input string in place */
int
sexp_transport_iterator_first(struct sexp_iterator *iterator,
size_t length, uint8_t *input);
int
sexp_iterator_next(struct sexp_iterator *iterator);
/* Current element must be a list. */
int
sexp_iterator_enter_list(struct sexp_iterator *iterator);
/* Skips the rest of the current list */
int
sexp_iterator_exit_list(struct sexp_iterator *iterator);
#if 0
/* Skips out of as many lists as necessary to get back to the given
* level. */
int
sexp_iterator_exit_lists(struct sexp_iterator *iterator,
unsigned level);
#endif
/* Gets start and length of the current subexpression. Implies
* sexp_iterator_next. */
const uint8_t *
sexp_iterator_subexpr(struct sexp_iterator *iterator,
size_t *length);
int
sexp_iterator_get_uint32(struct sexp_iterator *iterator,
uint32_t *x);
/* Checks the type of the current expression, which should be a list
*
* (<type> ...)
*/
int
sexp_iterator_check_type(struct sexp_iterator *iterator,
const char *type);
const char *
sexp_iterator_check_types(struct sexp_iterator *iterator,
unsigned ntypes,
const char * const *types);
/* Current element must be a list. Looks up element of type
*
* (key rest...)
*
* For a matching key, the corresponding iterator is initialized
* pointing at the start of REST.
*
* On success, exits the current list.
*/
int
sexp_iterator_assoc(struct sexp_iterator *iterator,
unsigned nkeys,
const char * const *keys,
struct sexp_iterator *values);
/* Output functions. What is a reasonable API for this? It seems
* ugly to have to reimplement string streams. */
/* Declared for real in buffer.h */
struct nettle_buffer;
/* Returns the number of output characters, or 0 on out of memory. If
* buffer == NULL, just compute length.
*
* Format strings can contained matched parentheses, tokens ("foo" in
* the format string is formatted as "3:foo"), whitespace (which
* separates tokens but is otherwise ignored) and the following
* formatting specifiers:
*
* %s String represented as size_t length, const uint8_t *data.
*
* %t Optional display type, represented as
* size_t display_length, const uint8_t *display,
* display == NULL means no display type.
*
* %i Non-negative small integer, uint32_t.
*
* %b Non-negative bignum, mpz_t.
*
* %l Literal string (no length added), typically a balanced
* subexpression. Represented as size_t length, const uint8_t
* *data.
*
* %(, %) Allows insertion of unbalanced parenthesis.
*
* Modifiers:
*
* %0 For %s, %t and %l, says that there's no length argument,
* instead the string is NUL-terminated, and there's only one
* const uint8_t * argument.
*/
size_t
sexp_format(struct nettle_buffer *buffer,
const char *format, ...);
size_t
sexp_vformat(struct nettle_buffer *buffer,
const char *format, va_list args);
size_t
sexp_transport_format(struct nettle_buffer *buffer,
const char *format, ...);
size_t
sexp_transport_vformat(struct nettle_buffer *buffer,
const char *format, va_list args);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SEXP_H_INCLUDED */

View File

@ -0,0 +1,42 @@
/* sha.h
This file is deprecated, and provided only for backwards
compatibility with earlier versions of Nettle. Please use sha1.h
and/or sha2.h instead.
Copyright (C) 2001 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_SHA_H_INCLUDED
#define NETTLE_SHA_H_INCLUDED
#include "sha1.h"
#include "sha2.h"
#endif /* NETTLE_SHA_H_INCLUDED */

View File

@ -0,0 +1,92 @@
/* sha1.h
The sha1 hash function.
Copyright (C) 2001, 2012 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_SHA1_H_INCLUDED
#define NETTLE_SHA1_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define sha1_init nettle_sha1_init
#define sha1_update nettle_sha1_update
#define sha1_digest nettle_sha1_digest
#define sha1_compress nettle_sha1_compress
/* SHA1 */
#define SHA1_DIGEST_SIZE 20
#define SHA1_BLOCK_SIZE 64
/* For backwards compatibility */
#define SHA1_DATA_SIZE SHA1_BLOCK_SIZE
/* Digest is kept internally as 5 32-bit words. */
#define _SHA1_DIGEST_LENGTH 5
struct sha1_ctx
{
uint32_t state[_SHA1_DIGEST_LENGTH]; /* State variables */
uint64_t count; /* 64-bit block count */
unsigned int index; /* index into buffer */
uint8_t block[SHA1_BLOCK_SIZE]; /* SHA1 data buffer */
};
void
sha1_init(struct sha1_ctx *ctx);
void
sha1_update(struct sha1_ctx *ctx,
size_t length,
const uint8_t *data);
void
sha1_digest(struct sha1_ctx *ctx,
size_t length,
uint8_t *digest);
/* SHA1 compression function. STATE points to 5 uint32_t words,
and DATA points to 64 bytes of input data, possibly unaligned. */
void
sha1_compress(uint32_t *state, const uint8_t *data);
/* Old name, for backwards compatibility. */
#define _nettle_sha1_compress nettle_sha1_compress
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SHA1_H_INCLUDED */

View File

@ -0,0 +1,200 @@
/* sha2.h
The sha2 family of hash functions.
Copyright (C) 2001, 2012 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_SHA2_H_INCLUDED
#define NETTLE_SHA2_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define sha224_init nettle_sha224_init
#define sha224_digest nettle_sha224_digest
#define sha256_init nettle_sha256_init
#define sha256_update nettle_sha256_update
#define sha256_digest nettle_sha256_digest
#define sha256_compress nettle_sha256_compress
#define sha384_init nettle_sha384_init
#define sha384_digest nettle_sha384_digest
#define sha512_init nettle_sha512_init
#define sha512_update nettle_sha512_update
#define sha512_digest nettle_sha512_digest
#define sha512_compress nettle_sha512_compress
#define sha512_224_init nettle_sha512_224_init
#define sha512_224_digest nettle_sha512_224_digest
#define sha512_256_init nettle_sha512_256_init
#define sha512_256_digest nettle_sha512_256_digest
/* For backwards compatibility */
#define SHA224_DATA_SIZE SHA256_BLOCK_SIZE
#define SHA256_DATA_SIZE SHA256_BLOCK_SIZE
#define SHA512_DATA_SIZE SHA512_BLOCK_SIZE
#define SHA384_DATA_SIZE SHA512_BLOCK_SIZE
/* SHA256 */
#define SHA256_DIGEST_SIZE 32
#define SHA256_BLOCK_SIZE 64
/* Digest is kept internally as 8 32-bit words. */
#define _SHA256_DIGEST_LENGTH 8
struct sha256_ctx
{
uint32_t state[_SHA256_DIGEST_LENGTH]; /* State variables */
uint64_t count; /* 64-bit block count */
unsigned int index; /* index into buffer */
uint8_t block[SHA256_BLOCK_SIZE]; /* SHA256 data buffer */
};
void
sha256_init(struct sha256_ctx *ctx);
void
sha256_update(struct sha256_ctx *ctx,
size_t length,
const uint8_t *data);
void
sha256_digest(struct sha256_ctx *ctx,
size_t length,
uint8_t *digest);
void
sha256_compress(uint32_t *state, const uint8_t *input);
/* SHA224, a truncated SHA256 with different initial state. */
#define SHA224_DIGEST_SIZE 28
#define SHA224_BLOCK_SIZE SHA256_BLOCK_SIZE
#define sha224_ctx sha256_ctx
void
sha224_init(struct sha256_ctx *ctx);
#define sha224_update nettle_sha256_update
void
sha224_digest(struct sha256_ctx *ctx,
size_t length,
uint8_t *digest);
/* SHA512 */
#define SHA512_DIGEST_SIZE 64
#define SHA512_BLOCK_SIZE 128
/* Digest is kept internally as 8 64-bit words. */
#define _SHA512_DIGEST_LENGTH 8
struct sha512_ctx
{
uint64_t state[_SHA512_DIGEST_LENGTH]; /* State variables */
uint64_t count_low, count_high; /* 128-bit block count */
unsigned int index; /* index into buffer */
uint8_t block[SHA512_BLOCK_SIZE]; /* SHA512 data buffer */
};
void
sha512_init(struct sha512_ctx *ctx);
void
sha512_update(struct sha512_ctx *ctx,
size_t length,
const uint8_t *data);
void
sha512_digest(struct sha512_ctx *ctx,
size_t length,
uint8_t *digest);
void
sha512_compress(uint64_t *state, const uint8_t *input);
/* SHA384, a truncated SHA512 with different initial state. */
#define SHA384_DIGEST_SIZE 48
#define SHA384_BLOCK_SIZE SHA512_BLOCK_SIZE
#define sha384_ctx sha512_ctx
void
sha384_init(struct sha512_ctx *ctx);
#define sha384_update nettle_sha512_update
void
sha384_digest(struct sha512_ctx *ctx,
size_t length,
uint8_t *digest);
/* SHA512_224 and SHA512_256, two truncated versions of SHA512
with different initial states. */
#define SHA512_224_DIGEST_SIZE 28
#define SHA512_224_BLOCK_SIZE SHA512_BLOCK_SIZE
#define sha512_224_ctx sha512_ctx
void
sha512_224_init(struct sha512_224_ctx *ctx);
#define sha512_224_update nettle_sha512_update
void
sha512_224_digest(struct sha512_224_ctx *ctx,
size_t length,
uint8_t *digest);
#define SHA512_256_DIGEST_SIZE 32
#define SHA512_256_BLOCK_SIZE SHA512_BLOCK_SIZE
#define sha512_256_ctx sha512_ctx
void
sha512_256_init(struct sha512_256_ctx *ctx);
#define sha512_256_update nettle_sha512_update
void
sha512_256_digest(struct sha512_256_ctx *ctx,
size_t length,
uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SHA2_H_INCLUDED */

View File

@ -0,0 +1,190 @@
/* sha3.h
The sha3 hash function (aka Keccak).
Copyright (C) 2012 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_SHA3_H_INCLUDED
#define NETTLE_SHA3_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define sha3_permute nettle_sha3_permute
#define sha3_224_init nettle_sha3_224_init
#define sha3_224_update nettle_sha3_224_update
#define sha3_224_digest nettle_sha3_224_digest
#define sha3_256_init nettle_sha3_256_init
#define sha3_256_update nettle_sha3_256_update
#define sha3_256_digest nettle_sha3_256_digest
#define sha3_256_shake nettle_sha3_256_shake
#define sha3_384_init nettle_sha3_384_init
#define sha3_384_update nettle_sha3_384_update
#define sha3_384_digest nettle_sha3_384_digest
#define sha3_512_init nettle_sha3_512_init
#define sha3_512_update nettle_sha3_512_update
#define sha3_512_digest nettle_sha3_512_digest
/* Indicates that SHA3 is the NIST FIPS 202 version. */
#define NETTLE_SHA3_FIPS202 1
/* The sha3 state is a 5x5 matrix of 64-bit words. In the notation of
Keccak description, S[x,y] is element x + 5*y, so if x is
interpreted as the row index and y the column index, it is stored
in column-major order. */
#define SHA3_STATE_LENGTH 25
/* The "width" is 1600 bits or 200 octets */
struct sha3_state
{
uint64_t a[SHA3_STATE_LENGTH];
};
void
sha3_permute (struct sha3_state *state);
/* The "capacity" is set to 2*(digest size), 512 bits or 64 octets.
The "rate" is the width - capacity, or width - 2 * (digest
size). */
#define SHA3_224_DIGEST_SIZE 28
#define SHA3_224_BLOCK_SIZE 144
#define SHA3_256_DIGEST_SIZE 32
#define SHA3_256_BLOCK_SIZE 136
#define SHA3_384_DIGEST_SIZE 48
#define SHA3_384_BLOCK_SIZE 104
#define SHA3_512_DIGEST_SIZE 64
#define SHA3_512_BLOCK_SIZE 72
/* For backwards compatibility */
#define SHA3_224_DATA_SIZE SHA3_224_BLOCK_SIZE
#define SHA3_256_DATA_SIZE SHA3_256_BLOCK_SIZE
#define SHA3_384_DATA_SIZE SHA3_384_BLOCK_SIZE
#define SHA3_512_DATA_SIZE SHA3_512_BLOCK_SIZE
struct sha3_224_ctx
{
struct sha3_state state;
unsigned index;
uint8_t block[SHA3_224_BLOCK_SIZE];
};
void
sha3_224_init (struct sha3_224_ctx *ctx);
void
sha3_224_update (struct sha3_224_ctx *ctx,
size_t length,
const uint8_t *data);
void
sha3_224_digest(struct sha3_224_ctx *ctx,
size_t length,
uint8_t *digest);
struct sha3_256_ctx
{
struct sha3_state state;
unsigned index;
uint8_t block[SHA3_256_BLOCK_SIZE];
};
void
sha3_256_init (struct sha3_256_ctx *ctx);
void
sha3_256_update (struct sha3_256_ctx *ctx,
size_t length,
const uint8_t *data);
void
sha3_256_digest(struct sha3_256_ctx *ctx,
size_t length,
uint8_t *digest);
/* Alternative digest function implementing shake256, with arbitrary
digest size */
void
sha3_256_shake(struct sha3_256_ctx *ctx,
size_t length,
uint8_t *digest);
struct sha3_384_ctx
{
struct sha3_state state;
unsigned index;
uint8_t block[SHA3_384_BLOCK_SIZE];
};
void
sha3_384_init (struct sha3_384_ctx *ctx);
void
sha3_384_update (struct sha3_384_ctx *ctx,
size_t length,
const uint8_t *data);
void
sha3_384_digest(struct sha3_384_ctx *ctx,
size_t length,
uint8_t *digest);
struct sha3_512_ctx
{
struct sha3_state state;
unsigned index;
uint8_t block[SHA3_512_BLOCK_SIZE];
};
void
sha3_512_init (struct sha3_512_ctx *ctx);
void
sha3_512_update (struct sha3_512_ctx *ctx,
size_t length,
const uint8_t *data);
void
sha3_512_digest(struct sha3_512_ctx *ctx,
size_t length,
uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SHA3_H_INCLUDED */

View File

@ -0,0 +1,134 @@
/* siv-cmac.h
AES-SIV, RFC5297
Copyright (C) 2017 Nikos Mavrogiannopoulos
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_SIV_H_INCLUDED
#define NETTLE_SIV_H_INCLUDED
#include "nettle-types.h"
#include "nettle-meta.h"
#include "cmac.h"
#include "aes.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define siv_cmac_set_key nettle_siv_cmac_set_key
#define siv_cmac_encrypt_message nettle_siv_cmac_encrypt_message
#define siv_cmac_decrypt_message nettle_siv_cmac_decrypt_message
#define siv_cmac_aes128_set_key nettle_siv_cmac_aes128_set_key
#define siv_cmac_aes128_encrypt_message nettle_siv_cmac_aes128_encrypt_message
#define siv_cmac_aes128_decrypt_message nettle_siv_cmac_aes128_decrypt_message
#define siv_cmac_aes256_set_key nettle_siv_cmac_aes256_set_key
#define siv_cmac_aes256_encrypt_message nettle_siv_cmac_aes256_encrypt_message
#define siv_cmac_aes256_decrypt_message nettle_siv_cmac_aes256_decrypt_message
/* For SIV, the block size of the underlying cipher shall be 128 bits. */
#define SIV_BLOCK_SIZE 16
#define SIV_DIGEST_SIZE 16
#define SIV_MIN_NONCE_SIZE 1
void
siv_cmac_set_key(struct cmac128_key *cmac_key, void *cmac_cipher, void *ctr_cipher,
const struct nettle_cipher *nc,
const uint8_t *key);
void
siv_cmac_encrypt_message(const struct cmac128_key *cmac_key, const void *cmac_cipher_ctx,
const struct nettle_cipher *nc,
const void *ctr_ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t clength, uint8_t *dst, const uint8_t *src);
int
siv_cmac_decrypt_message(const struct cmac128_key *cmac_key, const void *cmac_cipher,
const struct nettle_cipher *nc,
const void *ctr_cipher,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t mlength, uint8_t *dst, const uint8_t *src);
/*
* SIV mode requires the aad and plaintext when building the IV, which
* prevents streaming processing and it incompatible with the AEAD API.
*/
#define SIV_CMAC_CTX(type) { struct cmac128_key cmac_key; type cmac_cipher; type ctr_cipher; }
/* SIV_CMAC_AES128 */
#define SIV_CMAC_AES128_KEY_SIZE 32
struct siv_cmac_aes128_ctx SIV_CMAC_CTX(struct aes128_ctx);
void
siv_cmac_aes128_set_key(struct siv_cmac_aes128_ctx *ctx, const uint8_t *key);
void
siv_cmac_aes128_encrypt_message(const struct siv_cmac_aes128_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t clength, uint8_t *dst, const uint8_t *src);
int
siv_cmac_aes128_decrypt_message(const struct siv_cmac_aes128_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t mlength, uint8_t *dst, const uint8_t *src);
/* SIV_CMAC_AES256 */
#define SIV_CMAC_AES256_KEY_SIZE 64
struct siv_cmac_aes256_ctx SIV_CMAC_CTX(struct aes256_ctx);
void
siv_cmac_aes256_set_key(struct siv_cmac_aes256_ctx *ctx, const uint8_t *key);
void
siv_cmac_aes256_encrypt_message(const struct siv_cmac_aes256_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t clength, uint8_t *dst, const uint8_t *src);
int
siv_cmac_aes256_decrypt_message(const struct siv_cmac_aes256_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t mlength, uint8_t *dst, const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SIV_H_INCLUDED */

View File

@ -0,0 +1,107 @@
/* siv-gcm.h
AES-GCM-SIV, RFC8452
Copyright (C) 2022 Red Hat, Inc.
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_SIV_GCM_H_INCLUDED
#define NETTLE_SIV_GCM_H_INCLUDED
#include "nettle-types.h"
#include "nettle-meta.h"
#include "aes.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define siv_gcm_encrypt_message nettle_siv_gcm_encrypt_message
#define siv_gcm_decrypt_message nettle_siv_gcm_decrypt_message
#define siv_gcm_aes128_encrypt_message nettle_siv_gcm_aes128_encrypt_message
#define siv_gcm_aes128_decrypt_message nettle_siv_gcm_aes128_decrypt_message
#define siv_gcm_aes256_encrypt_message nettle_siv_gcm_aes256_encrypt_message
#define siv_gcm_aes256_decrypt_message nettle_siv_gcm_aes256_decrypt_message
/* For AES-GCM-SIV, the block size of the underlying cipher shall be 128 bits. */
#define SIV_GCM_BLOCK_SIZE 16
#define SIV_GCM_DIGEST_SIZE 16
#define SIV_GCM_NONCE_SIZE 12
/* Generic interface. NC must be a block cipher with 128-bit block
size, and keysize that is a multiple of 64 bits, such as AES-128 or
AES-256. */
void
siv_gcm_encrypt_message (const struct nettle_cipher *nc,
const void *ctx,
void *ctr_ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t clength, uint8_t *dst, const uint8_t *src);
int
siv_gcm_decrypt_message (const struct nettle_cipher *nc,
const void *ctx,
void *ctr_ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t mlength, uint8_t *dst, const uint8_t *src);
/* AEAD_AES_128_GCM_SIV */
void
siv_gcm_aes128_encrypt_message (const struct aes128_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t clength, uint8_t *dst, const uint8_t *src);
int
siv_gcm_aes128_decrypt_message (const struct aes128_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t mlength, uint8_t *dst, const uint8_t *src);
/* AEAD_AES_256_GCM_SIV */
void
siv_gcm_aes256_encrypt_message (const struct aes256_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t clength, uint8_t *dst, const uint8_t *src);
int
siv_gcm_aes256_decrypt_message (const struct aes256_ctx *ctx,
size_t nlength, const uint8_t *nonce,
size_t alength, const uint8_t *adata,
size_t mlength, uint8_t *dst, const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SIV_H_INCLUDED */

View File

@ -0,0 +1,80 @@
/* sm3.h
The SM3 hash function.
Copyright (C) 2017 Jia Zhang
Copyright (C) 2021 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_SM3_H_INCLUDED
#define NETTLE_SM3_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define sm3_init nettle_sm3_init
#define sm3_update nettle_sm3_update
#define sm3_digest nettle_sm3_digest
#define SM3_DIGEST_SIZE 32
#define SM3_BLOCK_SIZE 64
/* Digest is kept internally as 8 32-bit words. */
#define _SM3_DIGEST_LENGTH 8
struct sm3_ctx
{
uint32_t state[_SM3_DIGEST_LENGTH];
uint64_t count; /* Block count */
unsigned index; /* Into buffer */
uint8_t block[SM3_BLOCK_SIZE]; /* Block buffer */
};
void
sm3_init(struct sm3_ctx *ctx);
void
sm3_update(struct sm3_ctx *ctx,
size_t length,
const uint8_t *data);
void
sm3_digest(struct sm3_ctx *ctx,
size_t length,
uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SM3_H_INCLUDED */

View File

@ -0,0 +1,69 @@
/* sm4.h
Copyright (C) 2022 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_SM4_H_INCLUDED
#define NETTLE_SM4_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define sm4_set_encrypt_key nettle_sm4_set_encrypt_key
#define sm4_set_decrypt_key nettle_sm4_set_decrypt_key
#define sm4_crypt nettle_sm4_crypt
#define SM4_BLOCK_SIZE 16
#define SM4_KEY_SIZE 16
struct sm4_ctx
{
uint32_t rkey[32];
};
void
sm4_set_encrypt_key(struct sm4_ctx *ctx, const uint8_t *key);
void
sm4_set_decrypt_key(struct sm4_ctx *ctx, const uint8_t *key);
void
sm4_crypt(const struct sm4_ctx *context,
size_t length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_SM4_H_INCLUDED */

View File

@ -0,0 +1,99 @@
/* streebog.h
The Streebog family of hash functions.
Copyright (C) 2020 Dmitry Baryshkov
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_STREEBOG_H_INCLUDED
#define NETTLE_STREEBOG_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define streebog256_init nettle_streebog256_init
#define streebog256_digest nettle_streebog256_digest
#define streebog512_init nettle_streebog512_init
#define streebog512_update nettle_streebog512_update
#define streebog512_digest nettle_streebog512_digest
/* STREEBOG512 */
#define STREEBOG512_DIGEST_SIZE 64
#define STREEBOG512_BLOCK_SIZE 64
/* Digest is kept internally as 8 64-bit words. */
#define _STREEBOG512_DIGEST_LENGTH 8
struct streebog512_ctx
{
uint64_t state[_STREEBOG512_DIGEST_LENGTH]; /* State variables */
uint64_t count[_STREEBOG512_DIGEST_LENGTH];
uint64_t sigma[_STREEBOG512_DIGEST_LENGTH];
unsigned int index; /* index into buffer */
uint8_t block[STREEBOG512_BLOCK_SIZE]; /* STREEBOG512 data buffer */
};
void
streebog512_init(struct streebog512_ctx *ctx);
void
streebog512_update(struct streebog512_ctx *ctx,
size_t length,
const uint8_t *data);
void
streebog512_digest(struct streebog512_ctx *ctx,
size_t length,
uint8_t *digest);
#define STREEBOG256_DIGEST_SIZE 32
#define STREEBOG256_BLOCK_SIZE STREEBOG512_BLOCK_SIZE
#define streebog256_ctx streebog512_ctx
void
streebog256_init(struct streebog256_ctx *ctx);
#define streebog256_update nettle_streebog512_update
void
streebog256_digest(struct streebog256_ctx *ctx,
size_t length,
uint8_t *digest);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_STREEBOG_H_INCLUDED */

View File

@ -0,0 +1,98 @@
/* twofish.h
The twofish block cipher.
Copyright (C) 2001, 2014 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
/*
* Twofish is a 128-bit block cipher that accepts a variable-length
* key up to 256 bits, designed by Bruce Schneier and others. See
* http://www.counterpane.com/twofish.html for details.
*/
#ifndef NETTLE_TWOFISH_H_INCLUDED
#define NETTLE_TWOFISH_H_INCLUDED
#include "nettle-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define twofish_set_key nettle_twofish_set_key
#define twofish128_set_key nettle_twofish128_set_key
#define twofish192_set_key nettle_twofish192_set_key
#define twofish256_set_key nettle_twofish256_set_key
#define twofish_encrypt nettle_twofish_encrypt
#define twofish_decrypt nettle_twofish_decrypt
#define TWOFISH_BLOCK_SIZE 16
/* Variable key size between 128 and 256 bits. But the only valid
* values are 16 (128 bits), 24 (192 bits) and 32 (256 bits). */
#define TWOFISH_MIN_KEY_SIZE 16
#define TWOFISH_MAX_KEY_SIZE 32
#define TWOFISH_KEY_SIZE 32
#define TWOFISH128_KEY_SIZE 16
#define TWOFISH192_KEY_SIZE 24
#define TWOFISH256_KEY_SIZE 32
struct twofish_ctx
{
uint32_t keys[40];
uint32_t s_box[4][256];
};
void
twofish_set_key(struct twofish_ctx *ctx,
size_t length, const uint8_t *key);
void
twofish128_set_key(struct twofish_ctx *context, const uint8_t *key);
void
twofish192_set_key(struct twofish_ctx *context, const uint8_t *key);
void
twofish256_set_key(struct twofish_ctx *context, const uint8_t *key);
void
twofish_encrypt(const struct twofish_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
void
twofish_decrypt(const struct twofish_ctx *ctx,
size_t length, uint8_t *dst,
const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_TWOFISH_H_INCLUDED */

View File

@ -0,0 +1,198 @@
/* umac.h
UMAC message authentication code (RFC-4418).
Copyright (C) 2013 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_UMAC_H_INCLUDED
#define NETTLE_UMAC_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
/* Namespace mangling */
#define umac32_set_key nettle_umac32_set_key
#define umac64_set_key nettle_umac64_set_key
#define umac96_set_key nettle_umac96_set_key
#define umac128_set_key nettle_umac128_set_key
#define umac32_set_nonce nettle_umac32_set_nonce
#define umac64_set_nonce nettle_umac64_set_nonce
#define umac96_set_nonce nettle_umac96_set_nonce
#define umac128_set_nonce nettle_umac128_set_nonce
#define umac32_update nettle_umac32_update
#define umac64_update nettle_umac64_update
#define umac96_update nettle_umac96_update
#define umac128_update nettle_umac128_update
#define umac32_digest nettle_umac32_digest
#define umac64_digest nettle_umac64_digest
#define umac96_digest nettle_umac96_digest
#define umac128_digest nettle_umac128_digest
#include "nettle-types.h"
#include "aes.h"
#define UMAC_KEY_SIZE AES128_KEY_SIZE
#define UMAC32_DIGEST_SIZE 4
#define UMAC64_DIGEST_SIZE 8
#define UMAC96_DIGEST_SIZE 12
#define UMAC128_DIGEST_SIZE 16
#define UMAC_BLOCK_SIZE 1024
#define UMAC_MIN_NONCE_SIZE 1
#define UMAC_MAX_NONCE_SIZE AES_BLOCK_SIZE
/* For backwards compatibility */
#define UMAC_DATA_SIZE UMAC_BLOCK_SIZE
/* Subkeys and state for UMAC with tag size 32*n bits. */
#define _UMAC_STATE(n) \
uint32_t l1_key[UMAC_BLOCK_SIZE/4 + 4*((n)-1)]; \
/* Keys in 32-bit pieces, high first */ \
uint32_t l2_key[6*(n)]; \
uint64_t l3_key1[8*(n)]; \
uint32_t l3_key2[(n)]; \
/* AES cipher for encrypting the nonce */ \
struct aes128_ctx pdf_key; \
/* The l2_state consists of 2*n uint64_t, for poly64 \
and poly128 hashing, followed by n additional \
uint64_t used as an input buffer. */ \
uint64_t l2_state[3*(n)]; \
/* Input to the pdf_key, zero-padded and low bits \
cleared if appropriate. */ \
uint8_t nonce[AES_BLOCK_SIZE]; \
unsigned short nonce_length /* For incrementing */
/* Buffering */
#define _UMAC_BUFFER \
unsigned index; \
/* Complete blocks processed */ \
uint64_t count; \
uint8_t block[UMAC_BLOCK_SIZE]
#define _UMAC_NONCE_CACHED 0x80
struct umac32_ctx
{
_UMAC_STATE(1);
/* Low bits and cache flag. */
unsigned short nonce_low;
/* Previous padding block */
uint32_t pad_cache[AES_BLOCK_SIZE / 4];
_UMAC_BUFFER;
};
struct umac64_ctx
{
_UMAC_STATE(2);
/* Low bit and cache flag. */
unsigned short nonce_low;
/* Previous padding block */
uint32_t pad_cache[AES_BLOCK_SIZE/4];
_UMAC_BUFFER;
};
struct umac96_ctx
{
_UMAC_STATE(3);
_UMAC_BUFFER;
};
struct umac128_ctx
{
_UMAC_STATE(4);
_UMAC_BUFFER;
};
/* The _set_key function initialize the nonce to zero. */
void
umac32_set_key (struct umac32_ctx *ctx, const uint8_t *key);
void
umac64_set_key (struct umac64_ctx *ctx, const uint8_t *key);
void
umac96_set_key (struct umac96_ctx *ctx, const uint8_t *key);
void
umac128_set_key (struct umac128_ctx *ctx, const uint8_t *key);
/* Optional, if not used, messages get incrementing nonces starting from zero. */
void
umac32_set_nonce (struct umac32_ctx *ctx,
size_t nonce_length, const uint8_t *nonce);
void
umac64_set_nonce (struct umac64_ctx *ctx,
size_t nonce_length, const uint8_t *nonce);
void
umac96_set_nonce (struct umac96_ctx *ctx,
size_t nonce_length, const uint8_t *nonce);
void
umac128_set_nonce (struct umac128_ctx *ctx,
size_t nonce_length, const uint8_t *nonce);
void
umac32_update (struct umac32_ctx *ctx,
size_t length, const uint8_t *data);
void
umac64_update (struct umac64_ctx *ctx,
size_t length, const uint8_t *data);
void
umac96_update (struct umac96_ctx *ctx,
size_t length, const uint8_t *data);
void
umac128_update (struct umac128_ctx *ctx,
size_t length, const uint8_t *data);
/* The _digest functions increment the nonce */
void
umac32_digest (struct umac32_ctx *ctx,
size_t length, uint8_t *digest);
void
umac64_digest (struct umac64_ctx *ctx,
size_t length, uint8_t *digest);
void
umac96_digest (struct umac96_ctx *ctx,
size_t length, uint8_t *digest);
void
umac128_digest (struct umac128_ctx *ctx,
size_t length, uint8_t *digest);
/* Internal functions */
#define UMAC_POLY64_BLOCKS 16384
#define UMAC_P64_OFFSET 59
#define UMAC_P64 (- (uint64_t) UMAC_P64_OFFSET)
#define UMAC_P128_OFFSET 159
#define UMAC_P128_HI (~(uint64_t) 0)
#define UMAC_P128_LO (-(uint64_t) UMAC_P128_OFFSET)
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_UMAC_H_INCLUDED */

View File

@ -0,0 +1,64 @@
/* version.h
Information about library version.
Copyright (C) 2015 Red Hat, Inc.
Copyright (C) 2015 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_VERSION_H_INCLUDED
#define NETTLE_VERSION_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
/* Individual version numbers in decimal */
#define NETTLE_VERSION_MAJOR 3
#define NETTLE_VERSION_MINOR 9
#define NETTLE_USE_MINI_GMP 0
/* We need a preprocessor constant for GMP_NUMB_BITS, simply using
sizeof(mp_limb_t) * CHAR_BIT is not good enough. */
#if NETTLE_USE_MINI_GMP
# define GMP_NUMB_BITS n/a
#endif
int
nettle_version_major (void);
int
nettle_version_minor (void);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_VERSION_H_INCLUDED */

View File

@ -0,0 +1,123 @@
/* xts.h
XEX-based tweaked-codebook mode with ciphertext stealing (XTS)
Copyright (C) 2005 Niels Möller
Copyright (C) 2018 Red Hat, Inc.
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_XTS_H_INCLUDED
#define NETTLE_XTS_H_INCLUDED
#include "nettle-types.h"
#include "aes.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define xts_encrypt_message nettle_xts_encrypt_message
#define xts_decrypt_message nettle_xts_decrypt_message
#define xts_aes128_set_encrypt_key nettle_xts_aes128_set_encrypt_key
#define xts_aes128_set_decrypt_key nettle_xts_aes128_set_decrypt_key
#define xts_aes128_encrypt_message nettle_xts_aes128_encrypt_message
#define xts_aes128_decrypt_message nettle_xts_aes128_decrypt_message
#define xts_aes256_set_encrypt_key nettle_xts_aes256_set_encrypt_key
#define xts_aes256_set_decrypt_key nettle_xts_aes256_set_decrypt_key
#define xts_aes256_encrypt_message nettle_xts_aes256_encrypt_message
#define xts_aes256_decrypt_message nettle_xts_aes256_decrypt_message
#define XTS_BLOCK_SIZE 16
void
xts_encrypt_message(const void *enc_ctx, const void *twk_ctx,
nettle_cipher_func *encf,
const uint8_t *tweak, size_t length,
uint8_t *dst, const uint8_t *src);
void
xts_decrypt_message(const void *dec_ctx, const void *twk_ctx,
nettle_cipher_func *decf, nettle_cipher_func *encf,
const uint8_t *tweak, size_t length,
uint8_t *dst, const uint8_t *src);
/* XTS Mode with AES-128 */
struct xts_aes128_key {
struct aes128_ctx cipher;
struct aes128_ctx tweak_cipher;
};
void
xts_aes128_set_encrypt_key(struct xts_aes128_key *xts_key,
const uint8_t *key);
void
xts_aes128_set_decrypt_key(struct xts_aes128_key *xts_key,
const uint8_t *key);
void
xts_aes128_encrypt_message(const struct xts_aes128_key *xtskey,
const uint8_t *tweak, size_t length,
uint8_t *dst, const uint8_t *src);
void
xts_aes128_decrypt_message(const struct xts_aes128_key *xts_key,
const uint8_t *tweak, size_t length,
uint8_t *dst, const uint8_t *src);
/* XTS Mode with AES-256 */
struct xts_aes256_key {
struct aes256_ctx cipher;
struct aes256_ctx tweak_cipher;
};
void
xts_aes256_set_encrypt_key(struct xts_aes256_key *xts_key,
const uint8_t *key);
void
xts_aes256_set_decrypt_key(struct xts_aes256_key *xts_key,
const uint8_t *key);
void
xts_aes256_encrypt_message(const struct xts_aes256_key *xts_key,
const uint8_t *tweak, size_t length,
uint8_t *dst, const uint8_t *src);
void
xts_aes256_decrypt_message(const struct xts_aes256_key *xts_key,
const uint8_t *tweak, size_t length,
uint8_t *dst, const uint8_t *src);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_XTS_H_INCLUDED */

View File

@ -0,0 +1,145 @@
/* yarrow.h
The yarrow pseudo-randomness generator.
Copyright (C) 2001 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#ifndef NETTLE_YARROW_H_INCLUDED
#define NETTLE_YARROW_H_INCLUDED
#include "aes.h"
#include "sha2.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Name mangling */
#define yarrow256_init nettle_yarrow256_init
#define yarrow256_seed nettle_yarrow256_seed
#define yarrow256_update nettle_yarrow256_update
#define yarrow256_random nettle_yarrow256_random
#define yarrow256_is_seeded nettle_yarrow256_is_seeded
#define yarrow256_needed_sources nettle_yarrow256_needed_sources
#define yarrow256_fast_reseed nettle_yarrow256_fast_reseed
#define yarrow256_slow_reseed nettle_yarrow256_slow_reseed
#define yarrow_key_event_init nettle_yarrow_key_event_init
#define yarrow_key_event_estimate nettle_yarrow_key_event_estimate
/* Obsolete alias for backwards compatibility. Will be deleted in some
later version. */
#define yarrow256_force_reseed yarrow256_slow_reseed
enum yarrow_pool_id { YARROW_FAST = 0, YARROW_SLOW = 1 };
struct yarrow_source
{
/* Indexed by yarrow_pool_id */
uint32_t estimate[2];
/* The pool next sample should go to. */
enum yarrow_pool_id next;
};
#define YARROW256_SEED_FILE_SIZE (2 * AES_BLOCK_SIZE)
/* Yarrow-256, based on SHA-256 and AES-256 */
struct yarrow256_ctx
{
/* Indexed by yarrow_pool_id */
struct sha256_ctx pools[2];
int seeded;
/* The current key and counter block */
struct aes256_ctx key;
uint8_t counter[AES_BLOCK_SIZE];
/* The entropy sources */
unsigned nsources;
struct yarrow_source *sources;
};
void
yarrow256_init(struct yarrow256_ctx *ctx,
unsigned nsources,
struct yarrow_source *sources);
void
yarrow256_seed(struct yarrow256_ctx *ctx,
size_t length,
const uint8_t *seed_file);
/* Returns 1 on reseed */
int
yarrow256_update(struct yarrow256_ctx *ctx,
unsigned source, unsigned entropy,
size_t length, const uint8_t *data);
void
yarrow256_random(struct yarrow256_ctx *ctx, size_t length, uint8_t *dst);
int
yarrow256_is_seeded(struct yarrow256_ctx *ctx);
unsigned
yarrow256_needed_sources(struct yarrow256_ctx *ctx);
void
yarrow256_fast_reseed(struct yarrow256_ctx *ctx);
void
yarrow256_slow_reseed(struct yarrow256_ctx *ctx);
/* Key event estimator */
#define YARROW_KEY_EVENT_BUFFER 16
struct yarrow_key_event_ctx
{
/* Counter for initial priming of the state */
unsigned index;
unsigned chars[YARROW_KEY_EVENT_BUFFER];
unsigned previous;
};
void
yarrow_key_event_init(struct yarrow_key_event_ctx *ctx);
unsigned
yarrow_key_event_estimate(struct yarrow_key_event_ctx *ctx,
unsigned key, unsigned time);
#ifdef __cplusplus
}
#endif
#endif /* NETTLE_YARROW_H_INCLUDED */

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>nettle</string>
<key>CFBundleIdentifier</key>
<string>com.kintan.ksplayer.nettle</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>nettle</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>87.88.520</string>
<key>CFBundleVersion</key>
<string>87.88.520</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>MinimumOSVersion</key>
<string>14.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@ -0,0 +1,4 @@
framework module nettle [system] {
umbrella "."
export *
}