encoding.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Argon2 reference source code package - reference C implementations
  3. *
  4. * Copyright 2015
  5. * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
  6. *
  7. * You may use this work under the terms of a Creative Commons CC0 1.0
  8. * License/Waiver or the Apache Public License 2.0, at your option. The terms of
  9. * these licenses can be found at:
  10. *
  11. * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
  12. * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * You should have received a copy of both of these licenses along with this
  15. * software. If not, they may be obtained at the above URLs.
  16. */
  17. #ifndef ENCODING_H
  18. #define ENCODING_H
  19. #include "argon2.h"
  20. #define ARGON2_MAX_DECODED_LANES UINT32_C(255)
  21. #define ARGON2_MIN_DECODED_SALT_LEN UINT32_C(8)
  22. #define ARGON2_MIN_DECODED_OUT_LEN UINT32_C(12)
  23. /*
  24. * encode an Argon2 hash string into the provided buffer. 'dst_len'
  25. * contains the size, in characters, of the 'dst' buffer; if 'dst_len'
  26. * is less than the number of required characters (including the
  27. * terminating 0), then this function returns ARGON2_ENCODING_ERROR.
  28. *
  29. * on success, ARGON2_OK is returned.
  30. */
  31. int encode_string(char *dst, size_t dst_len, argon2_context *ctx,
  32. argon2_type type);
  33. /*
  34. * Decodes an Argon2 hash string into the provided structure 'ctx'.
  35. * The only fields that must be set prior to this call are ctx.saltlen and
  36. * ctx.outlen (which must be the maximal salt and out length values that are
  37. * allowed), ctx.salt and ctx.out (which must be buffers of the specified
  38. * length), and ctx.pwd and ctx.pwdlen which must hold a valid password.
  39. *
  40. * Invalid input string causes an error. On success, the ctx is valid and all
  41. * fields have been initialized.
  42. *
  43. * Returned value is ARGON2_OK on success, other ARGON2_ codes on error.
  44. */
  45. int decode_string(argon2_context *ctx, const char *str, argon2_type type);
  46. /* Returns the length of the encoded byte stream with length len */
  47. size_t b64len(uint32_t len);
  48. /* Returns the length of the encoded number num */
  49. size_t numlen(uint32_t num);
  50. #endif