Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sha512
- import strutils
- const sourcePath = currentSourcePath().split({'\\', '/'})[0..^2].join("/")
- {.passC: "-I\"" & sourcePath & "/src\"".}
- {.passC: "-I\"" & sourcePath & "/src/optional\"".}
- const headermonocypher = sourcePath & "/src/monocypher.h"
- {.passC: "-DED25519_SHA512".}
- {.compile: "nimmonocypher/src/monocypher.c".}
- type
- crypto_chacha_ctx* {.importc: "crypto_chacha_ctx", header: headermonocypher, bycopy.} = object
- input* {.importc: "input".}: array[16, uint32]
- pool* {.importc: "pool".}: array[16, uint32]
- pool_idx* {.importc: "pool_idx".}: csize
- crypto_poly1305_ctx* {.importc: "crypto_poly1305_ctx", header: headermonocypher,
- bycopy.} = object
- r* {.importc: "r".}: array[4, uint32]
- h* {.importc: "h".}: array[5, uint32]
- c* {.importc: "c".}: array[5, uint32]
- pad* {.importc: "pad".}: array[4, uint32]
- c_idx* {.importc: "c_idx".}: csize
- crypto_lock_ctx* {.importc: "crypto_lock_ctx", header: headermonocypher, bycopy.} = object
- chacha* {.importc: "chacha".}: crypto_chacha_ctx
- poly* {.importc: "poly".}: crypto_poly1305_ctx
- ad_size* {.importc: "ad_size".}: uint64
- message_size* {.importc: "message_size".}: uint64
- ad_phase* {.importc: "ad_phase".}: cint
- crypto_blake2b_ctx* {.importc: "crypto_blake2b_ctx", header: headermonocypher,
- bycopy.} = object
- hash* {.importc: "hash".}: array[8, uint64]
- input_offset* {.importc: "input_offset".}: array[2, uint64]
- input* {.importc: "input".}: array[16, uint64]
- input_idx* {.importc: "input_idx".}: csize
- hash_size* {.importc: "hash_size".}: csize
- crypto_hash_ctx* = crypto_sha512_ctx
- crypto_sign_ctx* {.importc: "crypto_sign_ctx", header: headermonocypher, bycopy.} = object
- hash* {.importc: "hash".}: crypto_hash_ctx
- buf* {.importc: "buf".}: array[96, uint8]
- pk* {.importc: "pk".}: array[32, uint8]
- crypto_check_ctx* {.importc: "crypto_check_ctx", header: headermonocypher, bycopy.} = object
- hash* {.importc: "hash".}: crypto_hash_ctx
- sig* {.importc: "sig".}: array[64, uint8]
- pk* {.importc: "pk".}: array[32, uint8]
- proc crypto_verify16*(a: array[16, uint8]; b: array[16, uint8]): cint {.stdcall,
- importc: "crypto_verify16", header: headermonocypher.}
- proc crypto_verify32*(a: array[32, uint8]; b: array[32, uint8]): cint {.stdcall,
- importc: "crypto_verify32", header: headermonocypher.}
- proc crypto_verify64*(a: array[64, uint8]; b: array[64, uint8]): cint {.stdcall,
- importc: "crypto_verify64", header: headermonocypher.}
- proc crypto_wipe*(secret: pointer; size: csize) {.stdcall, importc: "crypto_wipe",
- header: headermonocypher.}
- proc crypto_lock*(mac: array[16, uint8]; cipher_text: ptr uint8;
- key: array[32, uint8]; nonce: array[24, uint8];
- plain_text: ptr uint8; text_size: csize) {.stdcall,
- importc: "crypto_lock", header: headermonocypher.}
- proc crypto_unlock*(plain_text: ptr uint8; key: array[32, uint8];
- nonce: array[24, uint8]; mac: array[16, uint8];
- cipher_text: ptr uint8; text_size: csize): cint {.stdcall,
- importc: "crypto_unlock", header: headermonocypher.}
- proc crypto_lock_aead*(mac: array[16, uint8]; cipher_text: ptr uint8;
- key: array[32, uint8]; nonce: array[24, uint8];
- ad: ptr uint8; ad_size: csize; plain_text: ptr uint8;
- text_size: csize) {.stdcall, importc: "crypto_lock_aead",
- header: headermonocypher.}
- proc crypto_unlock_aead*(plain_text: ptr uint8; key: array[32, uint8];
- nonce: array[24, uint8]; mac: array[16, uint8];
- ad: ptr uint8; ad_size: csize; cipher_text: ptr uint8;
- text_size: csize): cint {.stdcall,
- importc: "crypto_unlock_aead", header: headermonocypher.}
- proc crypto_lock_init*(ctx: ptr crypto_lock_ctx; key: array[32, uint8];
- nonce: array[24, uint8]) {.stdcall,
- importc: "crypto_lock_init", header: headermonocypher.}
- proc crypto_lock_auth_ad*(ctx: ptr crypto_lock_ctx; message: ptr uint8;
- message_size: csize) {.stdcall,
- importc: "crypto_lock_auth_ad", header: headermonocypher.}
- proc crypto_lock_auth_message*(ctx: ptr crypto_lock_ctx; cipher_text: ptr uint8;
- text_size: csize) {.stdcall,
- importc: "crypto_lock_auth_message", header: headermonocypher.}
- proc crypto_lock_update*(ctx: ptr crypto_lock_ctx; cipher_text: ptr uint8;
- plain_text: ptr uint8; text_size: csize) {.stdcall,
- importc: "crypto_lock_update", header: headermonocypher.}
- proc crypto_lock_final*(ctx: ptr crypto_lock_ctx; mac: array[16, uint8]) {.stdcall,
- importc: "crypto_lock_final", header: headermonocypher.}
- proc crypto_unlock_update*(ctx: ptr crypto_lock_ctx; plain_text: ptr uint8;
- cipher_text: ptr uint8; text_size: csize) {.stdcall,
- importc: "crypto_unlock_update", header: headermonocypher.}
- proc crypto_unlock_final*(ctx: ptr crypto_lock_ctx; mac: array[16, uint8]): cint {.
- stdcall, importc: "crypto_unlock_final", header: headermonocypher.}
- proc crypto_blake2b*(hash: array[64, uint8]; message: ptr uint8;
- message_size: csize) {.stdcall, importc: "crypto_blake2b",
- header: headermonocypher.}
- proc crypto_blake2b_general*(hash: ptr uint8; hash_size: csize; key: ptr uint8;
- key_size: csize; message: ptr uint8;
- message_size: csize) {.stdcall,
- importc: "crypto_blake2b_general", header: headermonocypher.}
- proc crypto_blake2b_init*(ctx: ptr crypto_blake2b_ctx) {.stdcall,
- importc: "crypto_blake2b_init", header: headermonocypher.}
- proc crypto_blake2b_update*(ctx: ptr crypto_blake2b_ctx; message: ptr uint8;
- message_size: csize) {.stdcall,
- importc: "crypto_blake2b_update", header: headermonocypher.}
- proc crypto_blake2b_final*(ctx: ptr crypto_blake2b_ctx; hash: ptr uint8) {.stdcall,
- importc: "crypto_blake2b_final", header: headermonocypher.}
- proc crypto_blake2b_general_init*(ctx: ptr crypto_blake2b_ctx; hash_size: csize;
- key: ptr uint8; key_size: csize) {.stdcall,
- importc: "crypto_blake2b_general_init", header: headermonocypher.}
- proc crypto_argon2i*(hash: ptr uint8; hash_size: uint32; work_area: pointer;
- nb_blocks: uint32; nb_iterations: uint32;
- password: ptr uint8; password_size: uint32;
- salt: ptr uint8; salt_size: uint32) {.stdcall,
- importc: "crypto_argon2i", header: headermonocypher.}
- proc crypto_argon2i_general*(hash: ptr uint8; hash_size: uint32;
- work_area: pointer; nb_blocks: uint32;
- nb_iterations: uint32; password: ptr uint8;
- password_size: uint32; salt: ptr uint8;
- salt_size: uint32; key: ptr uint8;
- key_size: uint32; ad: ptr uint8; ad_size: uint32) {.
- stdcall, importc: "crypto_argon2i_general", header: headermonocypher.}
- proc crypto_key_exchange*(shared_key: array[32, uint8];
- your_secret_key: array[32, uint8];
- their_public_key: array[32, uint8]): cint {.stdcall,
- importc: "crypto_key_exchange", header: headermonocypher.}
- proc crypto_sign_public_key*(public_key: array[32, uint8];
- secret_key: array[32, uint8]) {.stdcall,
- importc: "crypto_sign_public_key", header: headermonocypher.}
- proc crypto_sign*(signature: array[64, uint8]; secret_key: array[32, uint8];
- public_key: array[32, uint8]; message: ptr uint8;
- message_size: csize) {.stdcall, importc: "crypto_sign",
- header: headermonocypher.}
- proc crypto_check*(signature: array[64, uint8]; public_key: array[32, uint8];
- message: ptr uint8; message_size: csize): cint {.stdcall,
- importc: "crypto_check", header: headermonocypher.}
- proc crypto_sign_init_first_pass*(ctx: ptr crypto_sign_ctx;
- secret_key: array[32, uint8];
- public_key: array[32, uint8]) {.stdcall,
- importc: "crypto_sign_init_first_pass", header: headermonocypher.}
- proc crypto_sign_update*(ctx: ptr crypto_sign_ctx; message: ptr uint8;
- message_size: csize) {.stdcall,
- importc: "crypto_sign_update", header: headermonocypher.}
- proc crypto_sign_init_second_pass*(ctx: ptr crypto_sign_ctx) {.stdcall,
- importc: "crypto_sign_init_second_pass", header: headermonocypher.}
- proc crypto_sign_final*(ctx: ptr crypto_sign_ctx; signature: array[64, uint8]) {.
- stdcall, importc: "crypto_sign_final", header: headermonocypher.}
- proc crypto_check_init*(ctx: ptr crypto_check_ctx; signature: array[64, uint8];
- public_key: array[32, uint8]) {.stdcall,
- importc: "crypto_check_init", header: headermonocypher.}
- proc crypto_check_update*(ctx: ptr crypto_check_ctx; message: ptr uint8;
- message_size: csize) {.stdcall,
- importc: "crypto_check_update", header: headermonocypher.}
- proc crypto_check_final*(ctx: ptr crypto_check_ctx): cint {.stdcall,
- importc: "crypto_check_final", header: headermonocypher.}
- proc crypto_chacha20_H*(`out`: array[32, uint8]; key: array[32, uint8];
- `in`: array[16, uint8]) {.stdcall,
- importc: "crypto_chacha20_H", header: headermonocypher.}
- proc crypto_chacha20_init*(ctx: ptr crypto_chacha_ctx; key: array[32, uint8];
- nonce: array[8, uint8]) {.stdcall,
- importc: "crypto_chacha20_init", header: headermonocypher.}
- proc crypto_chacha20_x_init*(ctx: ptr crypto_chacha_ctx; key: array[32, uint8];
- nonce: array[24, uint8]) {.stdcall,
- importc: "crypto_chacha20_x_init", header: headermonocypher.}
- proc crypto_chacha20_set_ctr*(ctx: ptr crypto_chacha_ctx; ctr: uint64) {.stdcall,
- importc: "crypto_chacha20_set_ctr", header: headermonocypher.}
- proc crypto_chacha20_encrypt*(ctx: ptr crypto_chacha_ctx; cipher_text: ptr uint8;
- plain_text: ptr uint8; text_size: csize) {.stdcall,
- importc: "crypto_chacha20_encrypt", header: headermonocypher.}
- proc crypto_chacha20_stream*(ctx: ptr crypto_chacha_ctx; stream: ptr uint8;
- size: csize) {.stdcall,
- importc: "crypto_chacha20_stream", header: headermonocypher.}
- proc crypto_poly1305*(mac: array[16, uint8]; message: ptr uint8;
- message_size: csize; key: array[32, uint8]) {.stdcall,
- importc: "crypto_poly1305", header: headermonocypher.}
- proc crypto_poly1305_init*(ctx: ptr crypto_poly1305_ctx; key: array[32, uint8]) {.
- stdcall, importc: "crypto_poly1305_init", header: headermonocypher.}
- proc crypto_poly1305_update*(ctx: ptr crypto_poly1305_ctx; message: ptr uint8;
- message_size: csize) {.stdcall,
- importc: "crypto_poly1305_update", header: headermonocypher.}
- proc crypto_poly1305_final*(ctx: ptr crypto_poly1305_ctx; mac: array[16, uint8]) {.
- stdcall, importc: "crypto_poly1305_final", header: headermonocypher.}
- proc crypto_x25519_public_key*(public_key: array[32, uint8];
- secret_key: array[32, uint8]) {.stdcall,
- importc: "crypto_x25519_public_key", header: headermonocypher.}
- proc crypto_x25519*(raw_shared_secret: array[32, uint8];
- your_secret_key: array[32, uint8];
- their_public_key: array[32, uint8]): cint {.stdcall,
- importc: "crypto_x25519", header: headermonocypher.}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement