Code Monkey home page Code Monkey logo

toyecc's Introduction

toyecc

Build Status

toyecc is a playground for Elliptic Curve Cryptography in FP. It is written in pure Python and aims to explain ECC in easy terms. It is neither written to be performant, nor side-channel resistant nor in any way suited for productive use at all. Please use it for its intended purpose and for it only.

The rationale behind toyecc is to show a clear and mathematically clean presentation of the underlying mathematical problems. Most code that is written arund ECC -- especially code that revolves around Ed25519 and/or Curve25519 is heavily optimized and in many cases hard to understand. toyecc tries to present the problems with a high level of abstraction in order to serve as yet another (different) reference to compare implementations against and in order to aid understanding of heavily optimized code. All curve arithmetic is therefore performed in affine space; performance in affine space is lowest, but having values that directly can be checked against the curve equation makes understanding everything extremely easy.

Installation

toyecc is available on PyPi. You can install it by:

$ pip3 install toyecc

Tutorial

There's a ECC tutorial that I've written which accompanies the pure code. It can be found at http://johannes-bauer.com/compsci/ecc/

Features

  • ECDSA demonstration
  • ECIES demonstration
  • ECDH demonstration
  • Elgamal demonstration
  • Dual_EC_DBRG backdoor demonstration
  • Demonstration how a private key can be recovered from two ECDSA signatures which reused the same nonce (ECDSA nonce exploit)
  • Support for short-formed Weierstrass curves, Montgomery curves and twisted Edwards curves
  • Conversion of domain parameters of twisted Edwards to Montgomery form and back, conversion of points between Montgomery representation and its birationally equivalent twisted Edwards counterpart
  • Ed25519 and Curve25519 support and support to convert keys between each other (Curve25519 and Ed25519 are birationally equivalent curves)
  • Many testcases to try out your own implementation
  • Example of OpenBSD's signify application (generates and verifies Ed25519 signatures, but doesn't support key encryption)
  • X-coordinate-only scalar multiplication on Short Weierstrass curves
  • Clean, well-documented Python3 code
  • Sage scripts that perform an invalid point attack using a vulnerable X-only-ladder implementation of toyecc

License

GNU GPL-3.

toyecc's People

Contributors

bastiengi avatar johndoe31415 avatar mdxs avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

toyecc's Issues

Problem with Pubkey "y" coordinates recalculation

Trying to recalculate "y" coordinates of public key, based on "x" coordinate.

#!/usr/bin/python3

from ecc import getcurvebyname, FieldElement, ECPrivateKey

curve = getcurvebyname("curve25519")
privatekey = ECPrivateKey(0x123456, curve)

print ('pubkey x: ', hex(int(privatekey.pubkey.point.x)))
print ('pubkey y: ', hex(int(privatekey.pubkey.point.y)))

x=int(privatekey.pubkey.point.x)

#  curve25519:  y^2 = x^3 + 486662*x^2 + x
y=hex(int(FieldElement(x**3+int(curve.a)*x**2+x, curve.p).sqrt()[0]))

print ('Recalculated y: ', y)

Obtain wrong result

pubkey x:  0x3a1754b57f5b66eaca28bf5d006f93eb287ba3f9535827ce318170c5394ffdc4
pubkey y:  0x6f7d0cc67331d815d0c8e05299ddab3afa0ba248048ccd3b37a66e5c6a2a32fb
Recalculated y:  0x1082f3398cce27ea2f371fad662254c505f45db7fb7332c4c85991a395d5ccf2

Any sample of EC-KCDSA

Hello!
Can provide any working samples of ec-kcdsa using joeecc
eckcdsa_sign
eckcdsa_sign_hash
eckcdsa_verify
eckcdsa_verify_hash

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.