Giter VIP home page Giter VIP logo

cairo-rsa's Introduction

cairo-rsa

RSA verification according to the RSA Sha256 Pkcs1.5 signature standard in Cairo.

About

This library makes use of the biguint Cairo library (GitHub), which allows for integers of arbitrary size. With felts having a max size of 251 bits, the biguint library supports storing numbers up to base 125. We use base 120 as it is the largest multiple of 8 supported (and this allows us to more easily compare chunks of 8 bit words with the 120 bit limbs). We use thebiguint library to store an unbounded unsigned integer in base 120 as a list of felts with least significant digits first and terminated with EON (-1).

Note: to convert an integer into its biguint base 120 representation, use the num_to_int function from biguint_tools.py.

Usage

func rsaVerify{range_check_ptr, bitwise_ptr : BitwiseBuiltin*}(n: felt*, s: felt*, message: felt*, message_len: felt, e: felt, key_size: felt)

Parameters:

  • n -- RSA modulus as a felt* for a biguint in base 120
  • s -- RSA signature to be verified as a felt* for a biguint in base 120
  • message -- the signed message, split into (up to) 14 words of 32 bits (big endian)
  • message_len -- the byte length of the message
  • e -- RSA exponent as a felt
  • key_size -- the size of the modulus and signature in bits

For example (with n, s, and e stored in input.json):

let (local hello_world) = alloc()
assert hello_world[0] = 'hell'
assert hello_world[1] = 'o wo'
assert hello_world[2] = 'rld\x00' # Note the '\x00' padding.

%{
	import sys, os
	cwd = os.getcwd()
	sys.path.append(cwd)
	from biguint_tools import int_to_num
	n =  int(program_input['modulus'], 16)
	e =  int(program_input['exponent'], 16)
	s =  int(program_input['signature'], 16)
	ids.e = e
	ids.s = segments.gen_arg(int_to_num(s))
	ids.n = segments.gen_arg(int_to_num(n))
}%

rsaVerify(n = n, s = s, message = hello_world, message_len = 11, e = e, key_size = 1024)

Testing

As the biguint library is in Cairo 0.8, this library is also in Cairo 0.8 for now.

To compile the test, run:

cairo-compile rsaTest.cairo --output rsa_compiled.json

To execute the test, run:

cairo-run --program=rsa_compiled.json --print_output  --program_input=input.json --print_info --layout=all 

cairo-rsa's People

Contributors

rpalakkal avatar

Watchers

James Cloos avatar  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.