blake2s.odin 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. package blake2s implements the BLAKE2s hash algorithm.
  3. See:
  4. - https://datatracker.ietf.org/doc/html/rfc7693
  5. - https://www.blake2.net/
  6. */
  7. package blake2s
  8. /*
  9. Copyright 2021 zhibog
  10. Made available under the BSD-3 license.
  11. List of contributors:
  12. zhibog, dotbmp: Initial implementation.
  13. */
  14. import "../_blake2"
  15. // DIGEST_SIZE is the BLAKE2s digest size.
  16. DIGEST_SIZE :: 32
  17. // Context is a BLAKE2s instance.
  18. Context :: _blake2.Blake2s_Context
  19. // init initializes a Context with the default BLAKE2s config.
  20. init :: proc(ctx: ^Context) {
  21. cfg: _blake2.Blake2_Config
  22. cfg.size = _blake2.BLAKE2S_SIZE
  23. _blake2.init(ctx, &cfg)
  24. }
  25. // update adds more data to the Context.
  26. update :: proc(ctx: ^Context, data: []byte) {
  27. _blake2.update(ctx, data)
  28. }
  29. // final finalizes the Context, writes the digest to hash, and calls
  30. // reset on the Context.
  31. //
  32. // Iff finalize_clone is set, final will work on a copy of the Context,
  33. // which is useful for for calculating rolling digests.
  34. final :: proc(ctx: ^Context, hash: []byte, finalize_clone: bool = false) {
  35. _blake2.final(ctx, hash, finalize_clone)
  36. }
  37. // clone clones the Context other into ctx.
  38. clone :: proc(ctx, other: ^Context) {
  39. _blake2.clone(ctx, other)
  40. }
  41. // reset sanitizes the Context. The Context must be re-initialized to
  42. // be used again.
  43. reset :: proc(ctx: ^Context) {
  44. _blake2.reset(ctx)
  45. }