Skip to content

Sarkoxed/Crypto-Library

Repository files navigation

My crypto library contents

Based

  • Bacon cipher

Block Ciphers

  • AES
    • CBC Mode

      • Padding Oracle attack implementation
    • GCM

      • Ghash implementation in python
      • oracle_access.py - GHASH without knowledge of key
    • linear_analysis

      • Example of Linear sbox usage in aes
    • other_implementations

      • open source implementations of aes
    • Ordinary AES implementation in python

    • Sbox gen implementation in c

  • DES
    • des.py python implementation.
    • weak and semi-weak keys for des
    • cool property with bitwise flip

DLP

  • Collision Algos
    • Baby-Step-Giant-Step implementation in python
    • Birthday Paradox based collision algorithm implementation in python
  • Pollard Rho
    • Pollard Rho algorithm implementation in python(Including Field extensions)
  • Auxialry Inputs
    • attack todo
  • prime_power
    • Discrete log in the rings $\frac{ZZ}{p^sZZ}$ up to the power $p^{s-1}, s \ge 2$
  • Pohlig-Hellman
    • based

Elliptic Curve Cryptography

  • hash_to_curve.py - map the arbitrary message to the point on Weierstrass curve

  • lift_p2.py - lift the points from E(F_p) to E(Zp^2) and find the amount of solutions "fast". Read comments inside.

  • curves

    • elliptic_curves.py - python implementation of an arbitrary elliptic curve
      • including constant time multiplication
    • edwards_curve.py - python implmentation of Edwards curves
    • montgomery_curve.py - python implementation of Montgomery curves
    • equivalence.py - translation between curves
    • kind.sage - script that kinda automates curve analysis
    • kinds.md - Writeup on Elliptic Curve kinds
    • get_curves_of_specific_order.py - just elliptic curves order properties
    • multiplication - implmentations of several techniques to boost multiplication
  • montgomery_curves

    • montgomery.py
      • Montgomery curves Affine implementation
      • Montgomery diffrential scalar implementation
      • Various optimizations for scalarmul
  • order

    • curve_order.py - computation of elliptic curve order over finite field using bsgs

    • division_polynomial.py - computation of division_polynomials and rational functions for elliptic curves

      • including computation with unknown y
    • schoofs_algorithm.py - Schoof's algorithm to compute elliptic curve order over finite field

  • Supersingular Curves

    • Supersingularity tests
    • Fast multiplication using supersingular curves
  • Singular Curves

    • DLP on singular curves
  • Anomalous Curves

    • Smart attack
    • Smart attack but mod p^2
    • Augmented addition attack
    • Fast multiplication using anomalous curves
  • Isogenies

    • isogeny_evaluation.py
      • get_velu_isogeny - get an isogeny based on kernel, using Velu' isogeny
      • get_isogeny_of_smooth_order and evaluate_isogeny_of_smooth_order - fast isogeny computation
    • isogenies.py
      • get_all_isogenous_curves of degree l function
      • get_all_isognies of degree l function
    • isogeny_graph.py
      • brute_graph - Get a complete isogny graph. DFS
      • successive_graph - Compute an isogeny graph up to some depth and draw them
  • MOV

    • weil_pairing.py - weil pairing python implementation
    • MOV algorithm implementation in python using weil pairing
  • ecdsa

    • ecdsa.py - Elliptic Curve DSA implementation in python
    • attacks.py:
      • Linear Congruece attack
      • Polynomial Congruence attack
      • Repeated Nonce attack
      • Lattice Based attack(lower bits) ecdh:
    • tripartite Diffie-Hellman
    • SIDH - supersingular isogeny Diffie-Hellman
  • encryption schemes

    • Massey-Omura cs
    • Elgamal cs
    • ECIES
    • KMOV - RSA like encryption
    • ID based encryption
    • malware one-sided DH
  • common curves

HASH Functions

  • sha1

    • sha1 implentation in python(stolen)
    • length_extension.py - le attack on sha1
  • murmurhash3

    • murmurhash3_128.py

    • murmurhash3_128_x64.cpp

    • reverse_murmurhash.py - zero finder/collision finder

  • md5

    • md5.py + tests
    • length_extension attack
    • collision - fast collision for md5(single block + two blocks)
      • diff.py + tests - diffrential analysis
      • verify_paper - tried to verify not very trustworthy facts from paper
      • fastcoll.py - attack implementation
  • blake2b

    • blake2b.py + tests
  • crc32

    • crc32.py CRC32 implementation
    • crc32_attack.py - mitm+algebraic+linear

Lattice Cryptography

  • LLL

    • python
      • LLL algorithm implementation in python
      • Improved spped LLL algorithm
      • LLL sage? why
    • cpp
      • lattice_attacks.cpp
        • LLL
        • HadamardRatio
        • Gram-Schmidt
        • LLL_check reduced basis
        • Babai Closest Plain
        • Babai Closest Vertex
        • Gaussian Expected Length
  • cryptosystems

    • Congruential Public Key CS
    • GGH Public Key CS
      • ggh implementation in python
      • gghdsa implementation in python
    • KnapSack like CS
      • subset sum
      • superincreasing knapsack
    • NTRU Public Key CS
      • NTRU implemntation in python
      • NTRUMLS implementation in python
  • Integer Relation

    • Algebraic Roots recovery using LLL(square and cubic)
    • Coppersmith attacks
    • Finding an Algebraic relation using sage
  • LWE

    • not so much yet

Linear Cryptoanalisys

  • TODO

Permutation Ciphers

  • Rail Fence cipher
  • Symmetric_Group
    • Sqrt in S(n)

Post Quantum

  • UoV - signature scheme

PRNG

  • xorshift128p - truncated xorshift128p analysis

    • TODO
  • xoshiro128++, 256++

RSA

  • Full/Partial(brutable) knowledge of d

    • python + cpp implementation
  • PKCS1 padding oracle attack

    • python + cpp implementation
  • Notes on RSA key creation using python/openssl - todo

  • wiener - Wiener attack on RSA with small private exponent

    • wiener.py
  • Known bits of p

Simple substitution

  • Shift cipher + analysis
  • Vigenere Cipher + analysis
  • frequencies
    • bigrams
    • singles

Stream Ciphers

  • RC4

    • oracle implemenation in python
    • RC4 cipher implementation in python
    • 1st Round Attack on RC4
      • 1st round attack on rc4 IV||main_key
      • 1st round attack on rc4 main_key||IV
      • Chosen IV attack on rc4
    • 2nd Round Attack on RC4
      • 2nd round attack on rc4 IV||main_key
    • FMS attack on RC4
    • Special IV generation
  • LFSR

    • lfsr decomposition
  • ChaCha20

    • ChaCha20 implementation in python

ZKP

  • KZG
    • KZG implementation from RealWorldCTF2023
  • coolstuff
    • emulated_field.py - prove a * b = c(mod q)
    • discrete_log.py - prove bunch of facts about dl)
    • range_constraint.py - prove that a is less than 2^n
  • PLONK
    • plonk todo
  • sumcheck
    • sumcheck protocol implementation TODO improve....
  • protostar/
  • zcash_bug
    • zcash_protocol implementation
    • bug implmentation

ALGEBRAIC TOOLS

Polynomials

  • polynomial_ring_analysis.py - Ring structure of polynomial quotient ring
    • Order of a multplicative subgroup
    • All the possible orders in this group
    • Ring factorization
    • TODO: find the number of elements in the group s.t. their order is K | minimal_power
  • Groebner basis implentation
  • symmetric_polynomials
    • symmetric_polynomial_decomposition.py - decompose any multivariate symmetric polynomial using symmetric_polynomial basis.
  • hensels_lifting
    • univariate_lifting.py - Lift the root mod $p^e$ to $p^{e + 1}$
    • find_roots_mod_prime_power.py - Find all the polynomial roots mod $p^e$

Matrices

- Get Jordan General Decomposition of a matrix over a finite field
- Find the matrix order with help of previous thing
- LFSR analysis with help of matrix order

Boolean

  • annihilators.py - Find annihilators of a boolean function

Varieties

Probablity Theory Tools

Distributions

Collection of some interesting probability distributions

  • any_distribution.py - Produce an arbitrary distribution out of a uniform one

Statistics

UNDER CONSTRUCTION

TOOLS

  • Factorization methods
    • 4p1factorization

      • Cheng's method - TODO
      • Simplified Cheng's method
    • EC(Lenstra) factorization

    • Fermatt Factorization

    • Naive Factorization

    • Pollard P Factorization

    • Pollard Rho Factorization

    • Stackoverflow

  • Tonelli
    • tonelli algorithm to find square roots
  • Inverse modulo
  • Primeness check + gen
    • is_prime
    • Atkin
    • Simple Prime in range finder
    • Euler's pattern to find primes
    • Brute
    • Sundaram
  • Carmichael Numbers
    • Generating Carmichael Numbers
    • Testing for Charmichaelness
  • Strong PseudoPrimes
    • Generating Strong Pseudoprimes using Arnault algorithm!!!
  • cvc5
    • cvc5 ff use case
    • ecc solver(lol)
  • encoders
    • base64
    • circom witness
    • circom r1cs
    • openssh private key
    • pkcs1.5
  • pade_approximation.py - Pade' M/N approximation of a function
  • binary_search.py - Binary Search
  • create_smooth_prime.py - Smooth Primes Creation
  • Interval Union -
  • Legendre symbol -
  • rebase.py - Base n function
  • use of gmp example
  • use of z3 example
  • use of cado-nfs example
  • use of pari library
  • x509cert_help.py - cert generation in python
  • Other - some thoughts, theories and algorithms of my own implementation
    • Combinatorics
    • Math