Code Monkey home page Code Monkey logo

cairo-sha256's Introduction

cairo-sha256

Computes SHA256 of 'input'. Inputs of arbitrary length are supported.

Usage

To use this function, split the input into (up to) 14 words of 32 bits (big endian).

To compute sha256('Hello world'), use:

input = [1214606444, 1864398703, 1919706112]

where:

1214606444 == int.from_bytes(b'Hell', 'big')
1864398703 == int.from_bytes(b'o wo', 'big')
1919706112 == int.from_bytes(b'rld\x00', 'big')  # Note the '\x00' padding.

For example:

let (hello_world) = alloc()
assert hello_world[0] = 'hell'
assert hello_world[1] = 'o wo'
assert hello_world[2] = 'rld\x00'

let (local sha256_ptr_start : felt*) = alloc()
let sha256_ptr = sha256_ptr_start
let sha256_ptr_end = sha256_ptr_start
let (hash) = sha256{sha256_ptr=sha256_ptr, sha256_ptr_end=sha256_ptr_end}(hello_world, 11)
finalize_sha256(sha256_ptr_start=sha256_ptr_start, sha256_ptr_end=sha256_ptr_end)

Output is an array of 8 32-bit words (big endian).

Note: You must call finalize_sha2() at the end of the program. Otherwise, this function is not sound and a malicious prover may return a wrong result. Note: the interface of this function may change in the future.

Development

The library uses Protostar for development.

Run tests with:

protostar test

Extension of the starkware implementation at: https://github.com/starkware-libs/cairo-examples/blob/master/sha256/sha256.cairo

cairo-sha256's People

Contributors

tarrencev avatar lucidluckylee 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.