💾 Archived View for gmi.noulin.net › gitRepositories › sodiumTest › file › sel.h.gmi captured on 2024-07-09 at 02:45:37. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
sel.h (1670B)
1 #pragma once 2 3 #include "sodium.h" 4 5 #ifndef u8 6 #define u8 uint8_t 7 #endif 8 9 typedef struct { 10 u8 publicKey[crypto_box_PUBLICKEYBYTES]; 11 u8 secretKey[crypto_box_SECRETKEYBYTES]; 12 u8 remotePublicKey[crypto_box_PUBLICKEYBYTES]; 13 u8 nonce[crypto_box_NONCEBYTES]; 14 } keyst; 15 16 typedef struct { 17 u8 rx[crypto_kx_SESSIONKEYBYTES]; 18 u8 tx[crypto_kx_SESSIONKEYBYTES]; 19 u8 nonce[crypto_box_NONCEBYTES]; 20 } sessionKeyst; 21 22 #define CLIENT_SESSION_KEYS 0 23 #define SERVER_SESSION_KEYS 1 24 25 typedef struct { 26 u8 publicKey[crypto_sign_PUBLICKEYBYTES]; 27 u8 secretKey[crypto_sign_SECRETKEYBYTES]; 28 } signKeyst; 29 30 extern signKeyst identityKeys; 31 extern u8 remoteId[crypto_sign_PUBLICKEYBYTES]; 32 extern sessionKeyst sessionKeys; 33 extern keyst keys; 34 /* 35 These functions return 0 when they fail. 36 */ 37 38 int selInit(void); 39 void newKeys(void); 40 void newKeysBuf(keyst *keys); 41 void newSignKeys(void); 42 void newSignKeysBuf(signKeyst *keys); 43 int selPublicEncrypt(u8 *ciphertext/*result*/, size_t csize, const u8 *msg, size_t mlen, keyst *keys); 44 int selPublicDecrypt(u8 *msg/*result*/, size_t msize, const u8 *ciphertext, size_t clen, keyst *keys); 45 int computeSharedKeys(int clientOrServer); 46 int computeSharedKeysBuf(int clientOrServer, sessionKeyst *sessionKeys, keyst *clientKeys); 47 // secret/symetric key encryption 48 int selEncrypt(u8 *ciphertext/*result*/, size_t csize, const u8 *msg, size_t mlen); 49 int selEncryptBuf(u8 *ciphertext/*result*/, size_t csize, const u8 *msg, size_t mlen, const u8 *nonce, const u8 *k); 50 int selDecrypt(u8 *msg/*result*/, size_t msize, const u8 *ciphertext, size_t clen); 51 int selDecryptBuf(u8 *msg/*result*/, size_t msize, const u8 *ciphertext, size_t clen, const u8 *nonce, const u8 *k);