luajitos

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

Kyber.h (3341B)


      1 /*
      2  * Kyber.h - CRYSTALS-Kyber Post-Quantum Key Encapsulation Mechanism
      3  *
      4  * NIST PQC Standard (FIPS 203)
      5  * Security levels: Kyber512, Kyber768, Kyber1024
      6  */
      7 
      8 #ifndef KYBER_H
      9 #define KYBER_H
     10 
     11 #include <stdint.h>
     12 #include <stddef.h>
     13 
     14 /* Kyber512 (Level 1 - equivalent to AES-128) */
     15 #define KYBER512_PUBLIC_KEY_BYTES   800
     16 #define KYBER512_SECRET_KEY_BYTES   1632
     17 #define KYBER512_CIPHERTEXT_BYTES   768
     18 #define KYBER512_SHARED_SECRET_BYTES 32
     19 
     20 /* Kyber768 (Level 3 - equivalent to AES-192) */
     21 #define KYBER768_PUBLIC_KEY_BYTES   1184
     22 #define KYBER768_SECRET_KEY_BYTES   2400
     23 #define KYBER768_CIPHERTEXT_BYTES   1088
     24 #define KYBER768_SHARED_SECRET_BYTES 32
     25 
     26 /* Kyber1024 (Level 5 - equivalent to AES-256) */
     27 #define KYBER1024_PUBLIC_KEY_BYTES  1568
     28 #define KYBER1024_SECRET_KEY_BYTES  3168
     29 #define KYBER1024_CIPHERTEXT_BYTES  1568
     30 #define KYBER1024_SHARED_SECRET_BYTES 32
     31 
     32 /* Security level enumeration */
     33 typedef enum {
     34     KYBER_512 = 2,   /* k=2, security level 1 */
     35     KYBER_768 = 3,   /* k=3, security level 3 */
     36     KYBER_1024 = 4   /* k=4, security level 5 */
     37 } kyber_level_t;
     38 
     39 /* ============================================================================
     40  * Kyber512 API
     41  * ========================================================================= */
     42 
     43 /**
     44  * Generate Kyber512 keypair
     45  * @param public_key  Output buffer (800 bytes)
     46  * @param secret_key  Output buffer (1632 bytes)
     47  * @return 0 on success, -1 on failure
     48  */
     49 int kyber512_keypair(uint8_t *public_key, uint8_t *secret_key);
     50 
     51 /**
     52  * Encapsulate - Generate shared secret and ciphertext
     53  * @param ciphertext      Output buffer (768 bytes)
     54  * @param shared_secret   Output buffer (32 bytes)
     55  * @param public_key      Public key (800 bytes)
     56  * @return 0 on success, -1 on failure
     57  */
     58 int kyber512_encapsulate(uint8_t *ciphertext, uint8_t *shared_secret,
     59                           const uint8_t *public_key);
     60 
     61 /**
     62  * Decapsulate - Recover shared secret from ciphertext
     63  * @param shared_secret   Output buffer (32 bytes)
     64  * @param ciphertext      Ciphertext (768 bytes)
     65  * @param secret_key      Secret key (1632 bytes)
     66  * @return 0 on success, -1 on failure
     67  */
     68 int kyber512_decapsulate(uint8_t *shared_secret, const uint8_t *ciphertext,
     69                           const uint8_t *secret_key);
     70 
     71 /* ============================================================================
     72  * Kyber768 API (RECOMMENDED - Best balance of security and performance)
     73  * ========================================================================= */
     74 
     75 int kyber768_keypair(uint8_t *public_key, uint8_t *secret_key);
     76 int kyber768_encapsulate(uint8_t *ciphertext, uint8_t *shared_secret,
     77                           const uint8_t *public_key);
     78 int kyber768_decapsulate(uint8_t *shared_secret, const uint8_t *ciphertext,
     79                           const uint8_t *secret_key);
     80 
     81 /* ============================================================================
     82  * Kyber1024 API
     83  * ========================================================================= */
     84 
     85 int kyber1024_keypair(uint8_t *public_key, uint8_t *secret_key);
     86 int kyber1024_encapsulate(uint8_t *ciphertext, uint8_t *shared_secret,
     87                            const uint8_t *public_key);
     88 int kyber1024_decapsulate(uint8_t *shared_secret, const uint8_t *ciphertext,
     89                            const uint8_t *secret_key);
     90 
     91 #endif /* KYBER_H */