2024-02-23 09:38:38 +01:00
/*
This is part of WHY2
Copyright ( C ) 2022 Václav Š mejkal
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU 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 General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < https : //www.gnu.org/licenses/>.
*/
# ifndef WHY2_CHAT_CRYPTO_H
# define WHY2_CHAT_CRYPTO_H
# ifdef __cplusplus
extern " C " {
# endif
2025-01-30 20:06:15 +01:00
# include <openssl/types.h>
2025-01-30 19:38:02 +01:00
# include <why2/flags.h>
2024-02-23 10:50:28 +01:00
# include <why2/chat/config.h>
2024-02-23 10:14:50 +01:00
//MACROS
2025-01-29 16:33:57 +01:00
# define WHY2_CHAT_ECC NID_secp521r1 //CURVE NAME
2024-02-23 10:14:50 +01:00
2024-08-30 00:54:17 +02:00
# define WHY2_CHAT_KEY_LOCATION WHY2_CONFIG_DIR " / keys" //KEYS LOCATION
2025-01-29 20:50:54 +01:00
# define WHY2_CHAT_KEY "secp521r1.pem"
2024-02-23 10:50:28 +01:00
2025-01-30 19:37:49 +01:00
# define WHY2_CHAT_BASE64_LENGTH_DELIMITER ':' //SEPARATES BASE64 FROM LENGTH (YnJhbWJvcmFrCg==:9)
2025-02-01 14:53:05 +01:00
# define WHY2_CHAT_PADDING(input_len) ((unsigned long) input_len / 2)
//FUNCTIONS
2025-01-29 16:33:57 +01:00
void why2_chat_init_keys ( void ) ; //INIT (POSSIBLY GENERATE) ECC KEYS
2024-04-13 12:26:47 +02:00
void why2_chat_deallocate_keys ( void ) ; //DEALLOCATE :) (NO SLUR HERE)
2024-02-23 09:38:38 +01:00
2025-02-02 15:01:20 +01:00
char * why2_chat_base64_encode ( char * message , size_t * length ) ; //ENCODE message OF length INTO BASE64 WITH LENGTH DELIMITER (WHY2_CHAT_BASE64_LENGTH_DELIMITER)
2025-02-02 14:53:13 +01:00
char * why2_chat_base64_decode ( char * encoded_message , size_t * length ) ; //DECODE encoded_message AND SET length TO OUTPUT LENGTH
2025-01-29 21:13:59 +01:00
char * why2_chat_ecc_sign ( char * message ) ; //SIGN message WITH ECC KEY
2025-01-30 20:06:15 +01:00
why2_bool why2_chat_ecc_verify_signature ( char * message , char * signature , EVP_PKEY * key ) ;
2025-01-29 21:13:59 +01:00
2025-02-01 12:55:39 +01:00
char * why2_chat_ecc_serialize_public_key ( ) ; //GET PUBLIC ECC KEY IN BASE64
2025-02-01 13:03:03 +01:00
EVP_PKEY * why2_chat_ecc_deserialize_public_key ( char * pubkey ) ; //GET EVP_PKEY FROM BASE64 PUBLIC ECC KEY
2025-02-01 12:55:39 +01:00
2025-02-01 21:54:43 +01:00
char * why2_chat_ecc_shared_key ( char * ecc_key ) ; //ENCRYPT message WITH ECC key
2025-02-01 14:54:11 +01:00
2025-02-01 14:37:53 +01:00
char * why2_sha256 ( char * input , size_t length ) ; //HASH input USING SHA256 AND RETURN IN STRING
2024-09-01 20:39:36 +02:00
2024-02-23 09:38:38 +01:00
# ifdef __cplusplus
}
# endif
# endif