drbg.h 964 B

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