diff --git a/libs/main/crypt/picrypt.h b/libs/main/crypt/picrypt.h index acb20697..79a319c5 100644 --- a/libs/main/crypt/picrypt.h +++ b/libs/main/crypt/picrypt.h @@ -5,22 +5,22 @@ * \~russian Шифрование с помощью libsodium */ /* - PIP - Platform Independent Primitives - Cryptographic class using lib Sodium - Andrey Bychkov work.a.b@yandex.ru + PIP - Platform Independent Primitives + Cryptographic class using lib Sodium + Andrey Bychkov work.a.b@yandex.ru - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ #ifndef PICRYPT_H @@ -29,90 +29,152 @@ #include "pip_crypt_export.h" #include "pistring.h" +//! \ingroup Crypt +//! \~\brief +//! \~english Class for encrypting and decrypting data. +//! \~russian Класс для шифрования и дешифрования данных. class PIP_CRYPT_EXPORT PICrypt { public: - //! Construct and generate random key + //! \~\brief + //! \~english Constructor that generates a random key + //! \~russian Конструктор, генерирующий случайный ключ PICrypt(); - //! Set key to "key", key size must be a \a sizeKey() + //! \~\brief + //! \~english Set key to "key", key size must be a \a sizeKey() + //! \~russian Установить ключ "key", размер ключа должен быть равен \a sizeKey() bool setKey(const PIByteArray & key); - //! Generate and set key from keyphrase "secret" + //! \~\brief + //! \~english Generate and set key from keyphrase "secret" + //! \~russian Генерировать и установить ключ из ключевой фразы "secret" PIByteArray setKey(const PIString & secret); - //! Returns current key + //! \~\brief + //! \~english Returns current key + //! \~russian Возвращает текущий ключ PIByteArray key() { return key_; } - //! Encrypt given data "data", result size will be increased by \a sizeCrypt() + //! \~\brief + //! \~english Encrypt given data "data", result size will be increased by \a sizeCrypt() + //! \~russian Зашифровать данные "data", размер результата увеличится на \a sizeCrypt() PIByteArray crypt(const PIByteArray & data); - //! Decrypt given data "crypt_data" + //! \~\brief + //! \~english Decrypt given data "crypt_data" + //! \~russian Расшифровать данные "crypt_data" PIByteArray decrypt(const PIByteArray & crypt_data, bool * ok = 0); - //! Encrypt given data "data" with key "key", result size will be increased by \a sizeCrypt() + //! \~\brief + //! \~english Encrypt given data "data" with key "key", result size will be increased by \a sizeCrypt() + //! \~russian Зашифровать данные "data" ключом "key", размер результата увеличится на \a sizeCrypt() static PIByteArray crypt(const PIByteArray & data, PIByteArray key); - //! Decrypt given data "crypt_data" with key "key" + //! \~\brief + //! \~english Decrypt given data "crypt_data" with key "key" + //! \~russian Расшифровать данные "crypt_data" ключом "key" static PIByteArray decrypt(const PIByteArray & crypt_data, PIByteArray key, bool * ok = 0); - //! Generate hash from keyphrase "secret", may be used as a key for encryption + //! \~\brief + //! \~english Generate hash from keyphrase "secret", may be used as a key for encryption + //! \~russian Генерировать хэш из ключевой фразы "secret", может использоваться в качестве ключа для шифрования static PIByteArray hash(const PIString & secret); - //! Generate hash from bytearray + //! \~\brief + //! \~english Generate hash from bytearray + //! \~russian Генерировать хэш из массива байт static PIByteArray hash(const PIByteArray & data); - //! Generate hash from bytearray + //! \~\brief + //! \~english Generate hash from bytearray + //! \~russian Генерировать хэш из массива байт static PIByteArray hash(const PIByteArray & data, const unsigned char * key, size_t keylen); - //! Returns hash size + //! \~\brief + //! \~english Returns hash size + //! \~russian Возвращает размер хэша static size_t sizeHash(); - //! Generate short hash from string "s", may be used for hash table + //! \~\brief + //! \~english Generate short hash from string "s", may be used for hash table + //! \~russian Генерировать короткий хэш из строки "s", может использоваться для хэш-таблиц static ullong shorthash(const PIString & s, PIByteArray key = PIByteArray()); - //! Generate random key + //! \~\brief + //! \~english Generate random key + //! \~russian Генерировать случайный ключ static PIByteArray generateKey(); - //! Generate random buffer + //! \~\brief + //! \~english Generate random buffer + //! \~russian Генерировать случайный буфер static PIByteArray generateRandomBuff(int size); - //! Returns key size + //! \~\brief + //! \~english Returns key size + //! \~russian Возвращает размер ключа static size_t sizeKey(); - //! Returns size which be added to data size in encryption process + //! \~\brief + //! \~english Returns size which be added to data size in encryption process + //! \~russian Возвращает размер, который будет добавлен к размеру данных в процессе шифрования static size_t sizeCrypt(); - //! Function randomly generates a secret key and a corresponding public key for digital signature + //! \~\brief + //! \~english Function randomly generates a secret key and a corresponding public key for digital signature + //! \~russian Функция случайным образом генерирует секретный ключ и соответствующий ему открытый ключ для цифровой подписи static void generateSignKeys(PIByteArray & public_key, PIByteArray & secret_key); - //! Function generates a secret key from input data and a corresponding public key for digital signature + //! \~\brief + //! \~english Function generates a secret key from input data and a corresponding public key for digital signature + //! \~russian Функция генерирует секретный ключ из входных данных и соответствующий ему открытый ключ для цифровой подписи static void generateSignKeys(PIByteArray & public_key, PIByteArray & secret_key, const PIByteArray & seed); - //! Function extract sign public key from sing secret key + //! \~\brief + //! \~english Function extract sign public key from sing secret key + //! \~russian Функция извлекает открытый ключ для подписи из секретного ключа для подписи static PIByteArray extractSignPublicKey(const PIByteArray & secret_key); - //! Calculate digital signature for data + //! \~\brief + //! \~english Calculate digital signature for data + //! \~russian Вычислить цифровую подпись для данных PIByteArray signMessage(const PIByteArray & data, PIByteArray secret_key); - //! Verify digital signature of signed message + //! \~\brief + //! \~english Verify digital signature of signed message + //! \~russian Проверить цифровую подпись подписанного сообщения bool verifySign(const PIByteArray & data, const PIByteArray & signature, PIByteArray public_key); - //! Function randomly generates a secret key and a corresponding public key for authenticated encryption + //! \~\brief + //! \~english Function randomly generates a secret key and a corresponding public key for authenticated encryption + //! \~russian Функция случайным образом генерирует секретный ключ и соответствующий ему открытый ключ для аутентифицированного + //! шифрования static void generateKeypair(PIByteArray & public_key, PIByteArray & secret_key); - //! Function generates a secret key from input data and a corresponding public key for authenticated encryption + //! \~\brief + //! \~english Function generates a secret key from input data and a corresponding public key for authenticated encryption + //! \~russian Функция генерирует секретный ключ из входных данных и соответствующий ему открытый ключ для аутентифицированного + //! шифрования static void generateKeypair(PIByteArray & public_key, PIByteArray & secret_key, const PIByteArray & seed); - //! Encrypt given data "data" + //! \~\brief + //! \~english Encrypt given data "data" + //! \~russian Зашифровать данные "data" PIByteArray crypt(const PIByteArray & data, const PIByteArray & public_key, const PIByteArray & secret_key); - //! Decrypt given data "crypt_data" + //! \~\brief + //! \~english Decrypt given data "crypt_data" + //! \~russian Расшифровать данные "crypt_data" PIByteArray decrypt(const PIByteArray & crypt_data, const PIByteArray & public_key, const PIByteArray & secret_key, bool * ok = 0); - //! Generate password hash from "password" + //! \~\brief + //! \~english Generate password hash from "password" + //! \~russian Генерировать хэш пароля из "password" static PIByteArray passwordHash(const PIString & password, const PIByteArray & seed); - //! Returns libsodium version + //! \~\brief + //! \~english Returns libsodium version + //! \~russian Возвращает версию libsodium static PIString version();