Giter Club home page Giter Club logo

crypto.jl's Introduction

Crypto.jl

Build Status Coverage Status Crypto

A package that wraps OpenSSL (libcrypto), but also has pure Julia implementations for reference. Contributions welcome.

Check out @staticfloat's pure Julia SHA package. We may simply require that package in this one rather than keep separate SHA implementations.

WARNING: This package experimental and is not ready for production use. The pure Julia implementations are not complete. Use at your own risk.

Prior to next release

  • Update documentation to reflect new signatures and functions
  • Clean up tests
  • Fix RIPEMD160
  • Swap input/output order for func params in c functions

Usage

This package will likely be updated frequently and may break with previous versions. If you use the code, we recommend using

# Prevent Pkg.update from updating Crypto
Pkg.pin("Crypto")

# If used in a package's REQUIRE file
Crypto 0.0.1

when installing or requiring the package. Installing the package this way might be annoying, but will likely save trouble.

Getting started

using Crypto

# Add open OpenSSL algorithms to look-up table
# Required for using digests
Crypto.init()

Creating digests

# Digests are available for MD2, MD5, SHA, SHA1, SHA224, SHA256, SHA384,
# SHA512, DSS, DSS1, MDC2, RIPEMD160
Crypto.digest("SHA256", "test")
# 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08

# If provided string is hex
Crypto.digest("SHA256", "12eba", is_hex=true)
# 0c58bf613f25d049c7355f7e334866bd6ba8b13ab7c06fc79cf607a57116174b

Using elliptic curve cryptography

So far, the package only generates public keys from private keys. We plan to add more functionality.

# Generate public key from private key
secret_key = "18e14a7b6a307f426a94f8114701e7c8e774e7f9a47e2c2035db29a206321725"
Crypto.ec_public_key_create(secret_key)
# "0450863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b23522cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6"

# Use curve secp256k1 (e.g., for Bitcoin) and generate uncompressed private key
# For more curves, see https://github.com/openssl/openssl/blob/master/crypto/objects/obj_mac.h
const NID_secp256k1 = 714
const COMPRESSED = 2
Crypto.ec_public_key_create(secret_key, curve_id = NID_secp256k1, form = COMPRESSED)
# 0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352

Generating random numbers

# Returns array of 32 Uint8
Crypto.random(256)

TODO

Detailed todos are noted in "TODO" sections found in the source code. Major todos:

  • Review for cryptographic security (e.g., CSPRNG, memory cleanup)
  • Add more Julia implementations
  • Add more OpenSSL Libcrypto functions
  • Implement ECDSA signing / authentication

How to contribute

Let's figure that out together! Generally, testing and documentation are good. The TODOs list at the top of source files are one place to start. To help others review pull requests, please follow these guidelines:

  • Add a summary of your changes to CHANGELOG.md in the 'Work in progress' section
  • Make sure new code is tested and all tests pass
# Navigate to package directory
julia --code-coverage test/runtests.jl

Thank you for your help!

Thanks

Shout out to @dirk, @amitmurthy, @j2kun, @wwilson, and @staticfloat for OpenSSL, Julia, and theory references.

crypto.jl's People

Contributors

danielsuo avatar tanmaykm 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.