tidentconcatenations.nim 982 B

123456789101112131415161718192021222324252627282930313233
  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, input: pointer, inputSize: csize) {.nodecl, importc: "keccak_" & astToStr(bits).}
  12. template defineSha(bits: static[int]) =
  13. proc `extSha bits`(output: pointer, outSize: csize, input: pointer, inputSize: csize) {.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)