Skip to content

Latest commit

 

History

History
179 lines (138 loc) · 4.49 KB

DOCS.md

File metadata and controls

179 lines (138 loc) · 4.49 KB

Всем привет это документация

извините

Cтруктура

~$ tree ./cryptolib
├── encoding
│   ├── base32.h
│   └── base64.h
├── hash
│   ├── crc32.h
│   ├── hash_base.h
│   ├── hmac.h
│   ├── sha256.cpp
│   ├── sha256.h
│   ├── sha512.cpp
│   ├── sha512.h
│   ├── streebog.cpp
│   └── streebog.h
├── public_key
│   ├── elgamal.h
│   ├── elgamalkey.cpp
│   ├── elgamalkey.h
│   ├── fiatshamir.h
│   ├── fiatshamirkey.cpp
│   ├── fiatshamirkey.h
│   ├── rsa.cpp
│   ├── rsa.h
│   ├── rsakey.cpp
│   └── rsakey.h
├── symmetric_key
│   ├── key.h
│   ├── rc4.h
│   └── symmetric_cipher_base.h
├── exceptions.h
└── utils.h

Содержание

  • Encoding
    • Base64
    • Base32
  • Hash
    • SHA256
    • SHA512
    • Streebog (GOST 34.11-2012)
    • HMAC
  • Public Key
    • RSA (Ciper + sign)
      • RSAKey
    • ElGamal (Sign)
      • ElGamalKey
    • FiatShamir (Sign)
      • FiatShamirKey
  • Symmetric Key
    • Key
    • RC4
  • other
    • Exceptions
    • Utils

Encoding

D35Crypto::Base64

Encode:

  • static std::string encode(const std::string &data);
  • static std::string encode(const std::vector<uint8_t> &data);

Decode:

  • static std::vector<uint8_t> decode(const std::string &data);

D35Crypto::Base32

Encode:

  • static std::string encode(const std::string &data);
  • static std::string encode(const std::vector<uint8_t> &data);

Decode:

  • static std::vector<uint8_t> decode(const std::string &data);

Some usage:

std::string b64result = D35Crypto::Base64::encode(inputStr);
std::string b32result = D35Crypto::Base32::encode(inputStr);
std::cout << "Base64(" << inputStr << ") = " << b64result << std::endl;
std::cout << "Base32(" << inputStr << ") = " << b32result << std::endl;
std::vector<uint8_t> tmpBuffer;
tmpBuffer = D35Crypto::Base64::decode(b64result);
b64result = std::string(tmpBuffer.begin(), tmpBuffer.end());
tmpBuffer = D35Crypto::Base32::decode(b32result);
b32result = std::string(tmpBuffer.begin(), tmpBuffer.end());

Hash

D35Crypto::HashBase

This paragraph needs rework
Basic abstract class for all hash functions.
Requires redefinition of methods:

  • virtual void update(const std::string &data) = 0;
  • virtual void update(const std::vector<uint8_t> &data) = 0;
  • virtual void update(std::ifstream& file) = 0;
  • virtual size_t blockSize() = 0; // Add descriptions

It also provides the results of the functions:

  • std::vector<uint8_t> digest() - Returns raw-bytes digest
  • std::string hexDigest() - Returns hex-encoded digest

For normal operation of all methods, it is necessary to put the digest in D35Crypto::HashBase::_digest (this->_digest):
Definition:

protected:
    std::vector<uint8_t> _digest;

Usage:

void update(const std::vector<uint8_t> &data)
{
    std::vector<uint8_t> digest;
    /* Calculating */
    this->_digest = digest;
}

D35Crypto::SHA256: public HashBase

Calculating digest according to D35Crypto::HashBase
Output of the result according to D35Crypto::HashBase

D35Crypto::SHA512: public HashBase

Calculating digest according to D35Crypto::HashBase
Output of the result according to D35Crypto::HashBase

D35Crypto::Streebog: public HashBase

Calculating digest according to D35Crypto::HashBase
Output of the result according to D35Crypto::HashBase

Setup digest size:
Always initialized with digest size = 64 bytes (512 bits). For change 'work mode' u need use void setMode(int digestSize);. That method manually set required digest size. Takes values 256 and 512.

D35Crypto::HMAC<HashBase>

Init:
D35Crypto::HMAC<D35Crypto::SHA256> hmac;

Calculating:

  • void create(const std::string&, const Key&);
  • void create(const std::vector<uint8_t>&, const Key&);

Output:

  • std::vector<uint8_t> raw(); - raw-bytes hmac
  • std::string hex(); - hex-encoded hmac

Some usages:

D35Crypto::SHA512 sha512;
sha512.update("AMOGUS");
std::cout << "SHA256(\"AMOGUS\") = " << sha512.hexDigest() << std::endl;

D35Crypto::Key k = D35Crypto::Key::generate(128);
std::cout << "HMACKING with key: " << k.hex() << std::endl;
D35Crypto::HMAC<D35Crypto::SHA256> hmac;
hmac.create("Som estring", k);
std::cout << hmac.name() << ' ' << hmac.hex() << std::endl;

Public key

MyCryptoLib::RSA

// TODO

MyCryptoLib::ElGamal

// TODO

MyCryptoLib::RSAKey

// TODO

MyCryptoLib::ElGamalKey

// TODO

Symmetric key

MyCryptoLib::Key

По факту это обертка над вектором байт :trollface:
// TODO