drbg.h
1 /* 2 * (c) 2015-2017 Marcos Del Sol Vives 3 * (c) 2016 javiMaD 4 * 5 * SPDX-License-Identifier: MIT 6 */ 7 8 #ifndef HAVE_NFC3D_DRBG_H 9 #define HAVE_NFC3D_DRBG_H 10 11 #include "nfc3d/crypto.h" 12 #include <stdbool.h> 13 #include <stdint.h> 14 15 #define NFC3D_DRBG_MAX_SEED_SIZE 480 /* Hardcoded max size in 3DS NFC module */ 16 #define NFC3D_DRBG_OUTPUT_SIZE 32 /* Every iteration generates 32 bytes */ 17 18 typedef struct 19 { 20 nrf_crypto_hmac_context_t hmacCtx; 21 bool used; 22 uint16_t iteration; 23 24 uint8_t buffer[sizeof(uint16_t) + NFC3D_DRBG_MAX_SEED_SIZE]; 25 size_t bufferSize; 26 27 const uint8_t* hmacKey; 28 size_t hmacKeySize; 29 } nfc3d_drbg_ctx; 30 31 void nfc3d_drbg_init(nfc3d_drbg_ctx* ctx, const uint8_t* hmacKey, size_t hmacKeySize, const uint8_t* seed, size_t seedSize); 32 void nfc3d_drbg_step(nfc3d_drbg_ctx* ctx, uint8_t* output); 33 void nfc3d_drbg_cleanup(nfc3d_drbg_ctx* ctx); 34 void nfc3d_drbg_generate_bytes(const uint8_t* hmacKey, size_t hmacKeySize, const uint8_t* seed, size_t seedSize, uint8_t* output, size_t outputSize); 35 36 #endif