pbkdf2.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Copyright (c) 2013-2014 Tomas Dzetkulic
  3. * Copyright (c) 2013-2014 Pavol Rusnak
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included
  13. * in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
  19. * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #ifndef __PBKDF2_H__
  24. #define __PBKDF2_H__
  25. #include <stdint.h>
  26. #include "sha2.h"
  27. typedef struct _PBKDF2_HMAC_SHA256_CTX {
  28. uint32_t odig[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
  29. uint32_t idig[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
  30. uint32_t f[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
  31. uint32_t g[SHA256_BLOCK_LENGTH / sizeof(uint32_t)];
  32. char first;
  33. } PBKDF2_HMAC_SHA256_CTX;
  34. typedef struct _PBKDF2_HMAC_SHA512_CTX {
  35. uint64_t odig[SHA512_DIGEST_LENGTH / sizeof(uint64_t)];
  36. uint64_t idig[SHA512_DIGEST_LENGTH / sizeof(uint64_t)];
  37. uint64_t f[SHA512_DIGEST_LENGTH / sizeof(uint64_t)];
  38. uint64_t g[SHA512_BLOCK_LENGTH / sizeof(uint64_t)];
  39. char first;
  40. } PBKDF2_HMAC_SHA512_CTX;
  41. void pbkdf2_hmac_sha256_Init(
  42. PBKDF2_HMAC_SHA256_CTX* pctx,
  43. const uint8_t* pass,
  44. int passlen,
  45. const uint8_t* salt,
  46. int saltlen,
  47. uint32_t blocknr);
  48. void pbkdf2_hmac_sha256_Update(PBKDF2_HMAC_SHA256_CTX* pctx, uint32_t iterations);
  49. void pbkdf2_hmac_sha256_Final(PBKDF2_HMAC_SHA256_CTX* pctx, uint8_t* key);
  50. void pbkdf2_hmac_sha256(
  51. const uint8_t* pass,
  52. int passlen,
  53. const uint8_t* salt,
  54. int saltlen,
  55. uint32_t iterations,
  56. uint8_t* key,
  57. int keylen);
  58. void pbkdf2_hmac_sha512_Init(
  59. PBKDF2_HMAC_SHA512_CTX* pctx,
  60. const uint8_t* pass,
  61. int passlen,
  62. const uint8_t* salt,
  63. int saltlen,
  64. uint32_t blocknr);
  65. void pbkdf2_hmac_sha512_Update(PBKDF2_HMAC_SHA512_CTX* pctx, uint32_t iterations);
  66. void pbkdf2_hmac_sha512_Final(PBKDF2_HMAC_SHA512_CTX* pctx, uint8_t* key);
  67. void pbkdf2_hmac_sha512(
  68. const uint8_t* pass,
  69. int passlen,
  70. const uint8_t* salt,
  71. int saltlen,
  72. uint32_t iterations,
  73. uint8_t* key,
  74. int keylen);
  75. #endif