crypto_scrypt.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*-
  2. * Copyright 2009 Colin Percival
  3. * Copyright 2013 Alexander Peslyak
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. *
  27. * This file was originally written by Colin Percival as part of the Tarsnap
  28. * online backup system.
  29. */
  30. #ifndef crypto_scrypt_H
  31. #define crypto_scrypt_H
  32. #include <limits.h>
  33. #include <stddef.h>
  34. #include <stdint.h>
  35. #if SIZE_MAX > 0xffffffffULL
  36. #define ARCH_BITS 64
  37. #else
  38. #define ARCH_BITS 32
  39. #endif
  40. #define crypto_pwhash_scryptsalsa208sha256_STRPREFIXBYTES 14
  41. #define crypto_pwhash_scryptsalsa208sha256_STRSETTINGBYTES 57
  42. #define crypto_pwhash_scryptsalsa208sha256_STRSALTBYTES 32
  43. #define crypto_pwhash_scryptsalsa208sha256_STRSALTBYTES_ENCODED 43
  44. #define crypto_pwhash_scryptsalsa208sha256_STRHASHBYTES 32
  45. #define crypto_pwhash_scryptsalsa208sha256_STRHASHBYTES_ENCODED 43
  46. #define BYTES2CHARS(bytes) ((((bytes) *8) + 5) / 6)
  47. typedef struct {
  48. void * base, *aligned;
  49. size_t size;
  50. } escrypt_region_t;
  51. typedef union {
  52. uint64_t d[8];
  53. uint32_t w[16];
  54. } escrypt_block_t;
  55. typedef escrypt_region_t escrypt_local_t;
  56. extern int escrypt_init_local(escrypt_local_t *__local);
  57. extern int escrypt_free_local(escrypt_local_t *__local);
  58. extern void *alloc_region(escrypt_region_t *region, size_t size);
  59. extern int free_region(escrypt_region_t *region);
  60. typedef int (*escrypt_kdf_t)(escrypt_local_t *__local, const uint8_t *__passwd,
  61. size_t __passwdlen, const uint8_t *__salt,
  62. size_t __saltlen, uint64_t __N, uint32_t __r,
  63. uint32_t __p, uint8_t *__buf, size_t __buflen);
  64. extern int escrypt_kdf_nosse(escrypt_local_t *__local, const uint8_t *__passwd,
  65. size_t __passwdlen, const uint8_t *__salt,
  66. size_t __saltlen, uint64_t __N, uint32_t __r,
  67. uint32_t __p, uint8_t *__buf, size_t __buflen);
  68. extern int escrypt_kdf_sse(escrypt_local_t *__local, const uint8_t *__passwd,
  69. size_t __passwdlen, const uint8_t *__salt,
  70. size_t __saltlen, uint64_t __N, uint32_t __r,
  71. uint32_t __p, uint8_t *__buf, size_t __buflen);
  72. extern uint8_t *escrypt_r(escrypt_local_t *__local, const uint8_t *__passwd,
  73. size_t __passwdlen, const uint8_t *__setting,
  74. uint8_t *__buf, size_t __buflen);
  75. extern uint8_t *escrypt_gensalt_r(uint32_t __N_log2, uint32_t __r, uint32_t __p,
  76. const uint8_t *__src, size_t __srclen,
  77. uint8_t *__buf, size_t __buflen);
  78. extern const uint8_t *escrypt_parse_setting(const uint8_t *setting,
  79. uint32_t *N_log2_p, uint32_t *r_p,
  80. uint32_t *p_p);
  81. #endif /* !_CRYPTO_SCRYPT_H_ */