GithubHelp home page GithubHelp logo

mrdcvlsc / chacha20-poly1305 Goto Github PK

View Code? Open in Web Editor NEW
12.0 1.0 1.0 292 KB

A C++ implementation of ChaCha20 & Poly1305 stream cipher described in RFC - 8439.

License: MIT License

C++ 98.86% Makefile 1.14%
chacha20-poly1305 chacha20 poly1305 uint512 cpp aead aead-authenticated-cryptography-mac rfc-8439 stream-cipher scratch-implementation

chacha20-poly1305's Introduction

Hi, I'm Jubal Mordecai Velasco!

Exploring the vast branches of computer science, searching for my place within it, and striving to add a leaf of knowledge to its ever-growing tree.

Welcome to my GitHub profile

I'm still currently a student ๐Ÿง‘โ€๐ŸŽ“ taking up a degree in computer science.

At the same time, I'm also growing ๐ŸŒฑ my knowledge ๐Ÿง  and mostly learning ๐Ÿ“š new things little-by-little ๐Ÿพ on my own during my free time, in the following concepts :

Linear Algebra, BLAS Libraries & Matrix Libraries, x86 & x86-64 Assembly, SIMD Assembly Instructions & Intrinsic, Arbitrary-Precision Arithmetic, Machine Learning, Neural Networks like FFNN, CNN, GAN & transformers models, Full-stack development, Cryptography, Web Security, Compilers, Automata Theory.


Dashboard


I Have Experience With the Following Frameworks, Tools, Environments, etc.

Git ghactions Shell Script Windows Terminal Markdown LaTeX .Net node CMake npm yarn PNPM ESLint fastify express react Github Pages Vercel heroku Render Arduino opencv numpy pandas Matplotlib pytorch MySQL mariadb sqlite3 windows ubuntu Kubuntu Lubuntu NetBeans IDE Sublime Text Visual Studio Code Android Studio Stack Overflow Top Coder

chacha20-poly1305's People

Contributors

mrdcvlsc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

apkc

chacha20-poly1305's Issues

32 bit mul on uint512/uint320

Currently this repo is taking advantage of the assembly instruction mulq and the rdx:rax registers to get the product of two 64 bit unsigned integers.

This arises to the problem of propagating the carry to the most significant limbs.

If the next limb where the rdx is added using adc %%rdx, %[i] overflows, that would mean we need to add the carry again to the second next limb and then if that second next limb also overflows after adding the carry using adc $0, %[i+1] then we need to add the carry again to the third next limbadc $0, %[i+2], and this can go on until we reach the last limb or the most significant limb.

In short, In order to get the result correctly we need to call the adc sequentially from where we perform the first add operation with the rax, to the adc operation with the rdx, up until to the most significant limb.

Meaning we repeatedly use adc just to propagate the carry until to the most significant limb which I think is expensive?

I wonder if we can avoid this (maybe) expensive(?) carry overflow solution by using only 32 bits of integers in the multiplication operations when getting the product so that the sequential use of adc can be avoided(?).

(or maybe it's not needed because it's just operating on a uint512?, maybe it's only expensive for dynamically big integers?).

implementation of uint320 to replace uint512

currently this repo is using uint512 for the Poly1305 mac/tag generation.

But since the multiplication of (acc+block) and r inside the Poly1305 does not exceed 2^288, a uint320 would be enough, It will use less operations and gain faster performance.

I can't compile this file in MSVC

Hello, when I was searching for chacha20-ploy305 encryption, I saw your code on GitHub and thought it was great, but I couldn't compile this file in my own VS2022 MSVC environment.

known timing attack vulnerabilities

These are known timing attack vulnerabilities in the code that should be addressed/fix in the future.

  • uint320 uint320::% - returns the quotient right away if it detects that the dividen is equal to the divisor, or if the dividen is less than the divisor.
  • uint320 uint320::compare() - returns the boolean right away if it detects less than or greater than cases early. (due to being the backend function for the operators ==, !=, and <=, they are also adds up to the vulnerability on each use cases).
  • There is no constant time comparison function for authenticating the Poly1305 tags.

A more C++ friendly api

Implementation of a more C++ api

  • implement a much easier api like maybe an encryption or decryption that returns a vector<unsigned char> results?

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.