Skip to content

Instantly share code, notes, and snippets.

@exarkun
Created January 18, 2021 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exarkun/cb9281127eadae6875c24933c9c4c976 to your computer and use it in GitHub Desktop.
Save exarkun/cb9281127eadae6875c24933c9c4c976 to your computer and use it in GitHub Desktop.
chk_encrypt :: AESKey128 -> (Integer -> IO B.ByteString) -> IO (Integer -> IO B.ByteString)
chk_encrypt key read_cleartext = do
ivref <- newIORef zeroIV
return $ \len -> do
cleartext <- read_cleartext len
iv <- readIORef ivref
let (ciphertext, new_iv) = ctr key iv cleartext
writeIORef ivref new_iv
return ciphertext
@exarkun
Copy link
Author

exarkun commented Jan 18, 2021

def chk_encrypt(key, read_cleartext):
    iv = ["\x00" * 16]
    def read(len):
        cleartext = read_plaintext(len)
        ciphertext, iv[0] = ctr(key, iv[0], cleartext)
        return ciphertext
    return read

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment