|
Packit Service |
4684c1 |
/* drbg-aes.h
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The CTR-AES-256-based random-number generator from SP800-90A.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* Copyright (C) 2013 Red Hat
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The nettle library is free software; you can redistribute it and/or modify
|
|
Packit Service |
4684c1 |
* it under the terms of the GNU Lesser General Public License as published by
|
|
Packit Service |
4684c1 |
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
|
Packit Service |
4684c1 |
* option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* The nettle library is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
Packit Service |
4684c1 |
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
Packit Service |
4684c1 |
* License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* along with the nettle library; see the file COPYING.LIB. If not, write to
|
|
Packit Service |
4684c1 |
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
Packit Service |
4684c1 |
* MA 02111-1301, USA.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifndef GNUTLS_LIB_NETTLE_INT_DRBG_AES_H
|
|
Packit Service |
4684c1 |
#define GNUTLS_LIB_NETTLE_INT_DRBG_AES_H
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include <config.h>
|
|
Packit Service |
4684c1 |
#include <nettle/aes.h>
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* This is nettle's increment macro */
|
|
Packit Service |
4684c1 |
/* Requires that size > 0 */
|
|
Packit Service |
4684c1 |
#define INCREMENT(size, ctr) \
|
|
Packit Service |
4684c1 |
do { \
|
|
Packit Service |
4684c1 |
unsigned increment_i = (size) - 1; \
|
|
Packit Service |
4684c1 |
if (++(ctr)[increment_i] == 0) \
|
|
Packit Service |
4684c1 |
while (increment_i > 0 \
|
|
Packit Service |
4684c1 |
&& ++(ctr)[--increment_i] == 0 ) \
|
|
Packit Service |
4684c1 |
; \
|
|
Packit Service |
4684c1 |
} while (0)
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#define DRBG_AES_KEY_SIZE AES256_KEY_SIZE
|
|
Packit Service |
4684c1 |
#define DRBG_AES_SEED_SIZE (AES_BLOCK_SIZE+DRBG_AES_KEY_SIZE)
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* This is the CTR-AES-256-based random-number generator from SP800-90A.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
struct drbg_aes_ctx {
|
|
Packit Service |
4684c1 |
unsigned seeded;
|
|
Packit Service |
4684c1 |
/* The current key */
|
|
Packit Service |
4684c1 |
struct aes256_ctx key;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
uint8_t v[AES_BLOCK_SIZE];
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
unsigned reseed_counter;
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* max_number_of_bits_per_request */
|
|
Packit Service |
4684c1 |
#define MAX_DRBG_AES_GENERATE_SIZE 65536 /* 2^19 */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* This DRBG should be reseeded if reseed_counter exceeds
|
|
Packit Service |
4684c1 |
* that number. Otherwise drbg_aes_random() will fail.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
#define DRBG_AES_RESEED_TIME 16777216
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* The entropy provided in these functions should be of
|
|
Packit Service |
4684c1 |
* size DRBG_AES_SEED_SIZE. Additional data and pers.
|
|
Packit Service |
4684c1 |
* string may be <= DRBG_AES_SEED_SIZE.
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
int
|
|
Packit Service |
4684c1 |
drbg_aes_init(struct drbg_aes_ctx *ctx,
|
|
Packit Service |
4684c1 |
unsigned entropy_size, const uint8_t *entropy,
|
|
Packit Service |
4684c1 |
unsigned pstring_size, const uint8_t* pstring);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int
|
|
Packit Service |
4684c1 |
drbg_aes_reseed(struct drbg_aes_ctx *ctx,
|
|
Packit Service |
4684c1 |
unsigned entropy_size, const uint8_t *entropy,
|
|
Packit Service |
4684c1 |
unsigned add_size, const uint8_t* add);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* our wrapper for the low-level drbg_aes_generate */
|
|
Packit Service |
4684c1 |
int
|
|
Packit Service |
4684c1 |
drbg_aes_random(struct drbg_aes_ctx *ctx, unsigned length,
|
|
Packit Service |
4684c1 |
uint8_t * dst);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int
|
|
Packit Service |
4684c1 |
drbg_aes_generate(struct drbg_aes_ctx *ctx, unsigned length,
|
|
Packit Service |
4684c1 |
uint8_t * dst, unsigned add_size, const uint8_t* add);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
/* For deinitialization use zeroize_key() on the context */
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int drbg_aes_is_seeded(struct drbg_aes_ctx *ctx);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
int drbg_aes_self_test(void);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#endif /* GNUTLS_LIB_NETTLE_INT_DRBG_AES_H */
|