Code Monkey home page Code Monkey logo

nim-libcrypto's Introduction

Wrapper and high-level API for libcrypto

Currently broken - waiting on a couple of PRs into nim-lang

There already exist thin libcrypt owrappers for nim, so the idea of this one is to have a more ergonomic experience, with less of a C feel. Currently this is done with annotation-style generics, destructors and integration with faststreams

I've only wrapped AES-ECB and various SHA implementations for now because that was all I needed as my motivating reason for making this. Ciphers and message digest have a skeleton that can be added on to. Assemetric encrpytion is not something that I have looked at yet.

import faststreams/[inputs, outputs]
import libcrypto/[support, aes]

# for ciphers procs like `new` and `basicEncrypt` accept a variety of inputs

# the key will adjust to the correct size, unless using pointer style procs or
# `danger` is defined and using the `openArray` style procs
let key = "verysecure"
var encCipher = Aes128Ecb.new(Encrypt, key)
echo encCipher.basicEncrypt("hello world").toHex
encCipher.rinse(key) # loads a new context

# integration with faststreams
let outp = memoryOutput(pageSize = 256)
encCipher.pipe(memoryInput("hello world"), outp)
echo outp.getOutput(string).toHex

# move semantics on cipher duplicates context if used
# after a finalizing operation
echo encCipher.basicEncrypt("hello world").toHex

# simple SHA digest
import libcrypto/sha
echo sha256.digest("foo")

# similar move semantics to ciphers
var messageDigest = newDigest(Sha512)
messageDigest.update("foo")
echo messageDigest.digest().toHex
var mdCopy = messageDigest
messageDigest.update("bar")
echo messageDigest.digest().toHex
mdCopy.update("bar")
echo mdCopy.digest().toHex

nim-libcrypto's People

Contributors

graveflo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.