Giter Site home page Giter Site logo

zcrypto's Introduction

zcrypto

English | 中文

a minimal crypto lib for limited environment like MCU.

features

  • base64
  • hash
    • SM3
    • MD5
    • SHA1
    • SHA256
  • block cipher algorithm
    • AES(128, 192, 256)
    • SM4
  • block cipher mode
    • ECB
    • CBC
    • CFB
    • OFB
  • asymmetric key encryption
    • RSA(2048)
    • RSA-OAEP(2048)

block cipher

do encryption or decryption in once function call.

  • aes_{keylen}_{mode}_{en/de}crypt
  • sm4_{mode}_{en/de}crypt

or use context:

  • aes_{en/de}crypt(aes_ctx_t*, ...)
  • sm4_{en/de}crypt(sm4_ctx_t*, ...)

you can call {aes/sm4}_{en/de}crypt multiple times to encrypt or decrypt for stream data.

for both two style apis, you should do the padding yourself, and make sure the input data length exactly multiple of the block size (aka 16bytes).

see test/test_{aes/sm4}.c for details.

hash

  • SM3
  • MD5
  • SHA1
  • SHA256
  • HMAC(TODO)

how to use:

  • use {alg}_init to initialize context.
  • use {alg}_update to feed data.
  • use {alg}_[hex]digest to get hash output.

you can call {alg}_[hex]digest whenever you like to get the hash of current feeded data, then feed more data. but you should make sure the output has enough size for the hash result.

see test/test_hash.c for details.

asymmetric key encryption

  • RSA (2048)

Do NOT support private key. it's designed to keep key just in the code or somewhere easy to read, so you should NOT use private key there.

use rsa_pub_naive for RSA pulic key enrypt/decrypt. see test/test_rsa.c for how to use. use rsa_pub_naive./test/rsa_naive_test.py | ./build/test_rsa.elf for test.

use rsa_pub_oaep_encrypt for RSAES-OAEP operation,see RFC8017 for reference. see test/test_oaep.c for how to use. use ./test/rsa_oaep_test.py gen | ./build/test_oaep.elf | ./test/rsa_oaep_test.py verify for test.

zcrypto's People

Contributors

exiledkingcc avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

energy0077

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.