Last active
June 4, 2022 19:02
-
-
Save Bannerets/b0ac104f205ea40562288bc25f7569ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use @pony_ctx[Pointer[None] iso]() | |
use @AES_init_ctx[None]( | |
ctx: _AESCTX, | |
key: Pointer[U8 val] tag) | |
use @AES_init_ctx_iv[None]( | |
ctx: _AESCTX, | |
key: Pointer[U8 val] tag, | |
iv: Pointer[U8 val] tag) | |
use @AES_ctx_set_iv[None]( | |
ctx: _AESCTX, | |
iv: Pointer[U8 val] tag) | |
use @AES_CTR_xcrypt_buffer[None]( | |
ctx: _AESCTX, | |
buf: Pointer[U8 val] tag, | |
length: USize) | |
type _AESCTX is Pointer[U8] tag | |
// builtin | |
// type ByteSeq is (String | Array[U8] val) | |
class AES | |
let _ctx: _AESCTX = @pony_alloc[_AESCTX](@pony_ctx(), | |
USize(256)) // round_key[240] + iv[16] | |
new create(key: ByteSeq box, iv: ByteSeq box) => | |
@AES_init_ctx_iv( | |
_ctx, | |
key.cpointer(), | |
iv.cpointer()) | |
// Mutates buf | |
fun ctr_xcrypt(buf: Array[U8] ref) => | |
@AES_CTR_xcrypt_buffer( | |
_ctx, | |
buf.cpointer(), | |
buf.size()) | |
fun set_iv(iv: ByteSeq box) => | |
@AES_ctx_set_iv( | |
_ctx, | |
iv.cpointer()) | |
// gcc -DCBC=0 DECB=0 -DCTR=1 -DAES256=1 -Wall -Os -Wextra -fPIC -g -c -o aes.o aes.c | |
// gcc -shared -lm -o ../aes.dylib aes.o |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment