pbkdf2.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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(PBKDF2_HMAC_SHA256_CTX *pctx, const uint8_t *pass,
  42. int passlen, const uint8_t *salt, int saltlen,
  43. uint32_t blocknr);
  44. void pbkdf2_hmac_sha256_Update(PBKDF2_HMAC_SHA256_CTX *pctx,
  45. uint32_t iterations);
  46. void pbkdf2_hmac_sha256_Final(PBKDF2_HMAC_SHA256_CTX *pctx, uint8_t *key);
  47. void pbkdf2_hmac_sha256(const uint8_t *pass, int passlen, const uint8_t *salt,
  48. int saltlen, uint32_t iterations, uint8_t *key,
  49. int keylen);
  50. void pbkdf2_hmac_sha512_Init(PBKDF2_HMAC_SHA512_CTX *pctx, const uint8_t *pass,
  51. int passlen, const uint8_t *salt, int saltlen,
  52. uint32_t blocknr);
  53. void pbkdf2_hmac_sha512_Update(PBKDF2_HMAC_SHA512_CTX *pctx,
  54. uint32_t iterations);
  55. void pbkdf2_hmac_sha512_Final(PBKDF2_HMAC_SHA512_CTX *pctx, uint8_t *key);
  56. void pbkdf2_hmac_sha512(const uint8_t *pass, int passlen, const uint8_t *salt,
  57. int saltlen, uint32_t iterations, uint8_t *key,
  58. int keylen);
  59. #endif