tidentconcatenations.nim 989 B

1234567891011121314151617181920212223242526272829303132
  1. type
  2. Hash*[bits: static[int]] = object
  3. data*: array[bits div 8, uint8]
  4. {.emit: """
  5. void sha_256(void* input, int input_len, void* output, int output_len) {}
  6. void sha_512(void* input, int input_len, void* output, int output_len) {}
  7. void keccak_256(void* input, int input_len, void* output, int output_len) {}
  8. void keccak_512(void* input, int input_len, void* output, int output_len) {}
  9. """.}
  10. template defineKeccak(bits: untyped) =
  11. proc `extKeccak bits`(output: pointer, outSize: csize_t, input: pointer, inputSize: csize_t) {.nodecl, importc: "keccak_" & astToStr(bits).}
  12. template defineSha(bits: static[int]) =
  13. proc `extSha bits`(output: pointer, outSize: csize_t, input: pointer, inputSize: csize_t) {.nodecl, importc: "sha_" & astToStr(bits).}
  14. template defineHashProcs(bits) =
  15. defineSha(bits)
  16. defineKeccak(bits)
  17. defineHashProcs(256)
  18. defineHashProcs(512)
  19. extSha256(nil, 0, nil, 0)
  20. extSha512(nil, 0, nil, 0)
  21. extKeccak256(nil, 0, nil, 0)
  22. extKeccak512(nil, 0, nil, 0)