Code Monkey home page Code Monkey logo

crystal-ecdsa's Introduction

Crystal-ECDSA

A Crystal C binding for the ECDSA functionality of OpenSSL that focuses specifically on secp256k1. This library requires you to have OpenSSL installed.

Thanks to Eric Davis for his ecies library and to John Feras for his adaptation of Eric's code for this library.

Build Status

Installation

  1. Add the dependency to your shard.yml:
dependencies:
  crystal-ecdsa:
    github: sushichain/crystal-ecdsa
  1. Run shards install

Usage

require "crystal-ecdsa"

# generate a keypair
key_pair = ECCrypto.create_key_pair
private_key = key_pair[:hex_private_key]
public_key = key_pair[:hex_public_key]

# hash a text message
message = ECCrypto.sha256("this message is being signed")

# sign the message with a private key
sig = ECCrypto.sign(private_key, message)

# verify the signature with the public key and the signature
ECCrypto.verify(public_key, message, sig["r"], sig["s"])

# get the public key from a private key
public_key = ECCrypto.get_public_key_from_private(private_key)

# encrypt a message using a given receiver's public key
encrypted_message = ECCrypto.encrypt(receiver_public_key, "This is a secret message")

# decrypt a received message using known private key
decrypted_message = ECCrypto.decrypt(private_key, encrypted_message)

You can create a keypair which returns the public and private keys. The private key will always be of length 64 and the public key of length 130

Using the keypair you can sign a message and then verify it

Developement

You must generate the encryption.o before the library is usable and before the specs will run.

cd encryption && make

Contributing

  1. Fork it (https://github.com/sushichain/crystal-ecdsa/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

crystal-ecdsa's People

Contributors

jferas avatar kingsleyh avatar q9f avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

crystal-ecdsa's Issues

clang make issues on *nix

running make in the encryption folder doesn't work on *nix - only on mac

Failed cd encryption && make:
clang -Wall -I/usr/local/opt/openssl/include  -o encryption.o  -c encryption.c
make: clang: Command not found
Makefile:9: recipe for target 'all' failed
make: *** [all] Error 127

CircleCi fails with c compilation for encryption

cc -Wall -I/usr/local/opt/openssl/include  -o encryption.o  -c encryption.c
encryption.c:35:28: error: unknown type name 'uint8_t'
 void dump_hex(char *label, uint8_t *buf, int len)
                            ^
encryption.c:45:30: error: unknown type name 'uint8_t'
                              uint8_t      **pubk,     // out (must free)
                              ^
encryption.c:97:39: error: unknown type name 'uint8_t'
                                       uint8_t       **epubk,         // out (must free)
                                       ^
encryption.c:99:39: error: unknown type name 'uint8_t'
                                       uint8_t       **skey,          // out (must free)
                                       ^
encryption.c:132:42: error: unknown type name 'uint8_t'
                                    const uint8_t   *pubk,
                                          ^
encryption.c: In function 'ec_key_public_key_bin_to_point':
encryption.c:141:29: warning: passing argument 1 of 'BN_bin2bn' from incompatible pointer type [-Wincompatible-pointer-types]
         pubk_bn = BN_bin2bn(pubk, pubk_len, NULL);
                             ^
In file included from encryption.c:10:0:
/usr/include/openssl/bn.h:442:9: note: expected 'const unsigned char *' but argument is of type 'const int *'
 BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret);```

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.