1 /* falcon.h 2 * 3 * Copyright (C) 2021 wolfSSL Inc. 4 * 5 * This file is part of wolfSSL. 6 * 7 * wolfSSL is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * wolfSSL is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 20 */ 21 22 /*! 23 \file wolfssl/wolfcrypt/falcon.h 24 */ 25 26 /* Interfaces for Falcon NIST Level 1 (Falcon512) and Falcon NIST Level 5 27 * (Falcon1024). */ 28 29 #ifndef WOLF_CRYPT_FALCON_H 30 #define WOLF_CRYPT_FALCON_H 31 32 #include <wolfssl/wolfcrypt/types.h> 33 34 #ifdef HAVE_PQC 35 36 #ifdef HAVE_LIBOQS 37 #include <oqs/oqs.h> 38 #endif 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /* Macros Definitions */ 45 46 #ifdef HAVE_LIBOQS 47 #define FALCON_LEVEL1_KEY_SIZE OQS_SIG_falcon_512_length_secret_key 48 #define FALCON_LEVEL1_SIG_SIZE OQS_SIG_falcon_512_length_signature 49 #define FALCON_LEVEL1_PUB_KEY_SIZE OQS_SIG_falcon_512_length_public_key 50 #define FALCON_LEVEL1_PRV_KEY_SIZE (FALCON_LEVEL1_PUB_KEY_SIZE+FALCON_LEVEL1_KEY_SIZE) 51 52 #define FALCON_LEVEL5_KEY_SIZE OQS_SIG_falcon_1024_length_secret_key 53 #define FALCON_LEVEL5_SIG_SIZE OQS_SIG_falcon_1024_length_signature 54 #define FALCON_LEVEL5_PUB_KEY_SIZE OQS_SIG_falcon_1024_length_public_key 55 #define FALCON_LEVEL5_PRV_KEY_SIZE (FALCON_LEVEL5_PUB_KEY_SIZE+FALCON_LEVEL5_KEY_SIZE) 56 #endif 57 58 #define FALCON_MAX_KEY_SIZE FALCON_LEVEL5_PRV_KEY_SIZE 59 #define FALCON_MAX_SIG_SIZE FALCON_LEVEL5_SIG_SIZE 60 #define FALCON_MAX_PUB_KEY_SIZE FALCON_LEVEL5_PUB_KEY_SIZE 61 #define FALCON_MAX_PRV_KEY_SIZE FALCON_LEVEL5_PRV_KEY_SIZE 62 63 /* Structs */ 64 65 struct falcon_key { 66 bool pubKeySet; 67 bool prvKeySet; 68 byte level; 69 byte p[FALCON_MAX_PUB_KEY_SIZE]; 70 byte k[FALCON_MAX_PRV_KEY_SIZE]; 71 }; 72 73 #ifndef WC_FALCONKEY_TYPE_DEFINED 74 typedef struct falcon_key falcon_key; 75 #define WC_FALCONKEY_TYPE_DEFINED 76 #endif 77 78 /* Functions */ 79 80 WOLFSSL_API 81 int wc_falcon_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen, 82 falcon_key* key); 83 WOLFSSL_API 84 int wc_falcon_verify_msg(const byte* sig, word32 sigLen, const byte* msg, 85 word32 msgLen, int* res, falcon_key* key); 86 87 WOLFSSL_API 88 int wc_falcon_init(falcon_key* key); 89 WOLFSSL_API 90 int wc_falcon_set_level(falcon_key* key, byte level); 91 WOLFSSL_API 92 int wc_falcon_get_level(falcon_key* key, byte* level); 93 WOLFSSL_API 94 void wc_falcon_free(falcon_key* key); 95 96 WOLFSSL_API 97 int wc_falcon_import_public(const byte* in, word32 inLen, falcon_key* key); 98 WOLFSSL_API 99 int wc_falcon_import_private_only(const byte* priv, word32 privSz, 100 falcon_key* key); 101 WOLFSSL_API 102 int wc_falcon_import_private_key(const byte* priv, word32 privSz, 103 const byte* pub, word32 pubSz, 104 falcon_key* key); 105 106 WOLFSSL_API 107 int wc_falcon_export_public(falcon_key*, byte* out, word32* outLen); 108 WOLFSSL_API 109 int wc_falcon_export_private_only(falcon_key* key, byte* out, word32* outLen); 110 WOLFSSL_API 111 int wc_falcon_export_private(falcon_key* key, byte* out, word32* outLen); 112 WOLFSSL_API 113 int wc_falcon_export_key(falcon_key* key, byte* priv, word32 *privSz, 114 byte* pub, word32 *pubSz); 115 116 WOLFSSL_API 117 int wc_falcon_check_key(falcon_key* key); 118 119 WOLFSSL_API 120 int wc_falcon_size(falcon_key* key); 121 WOLFSSL_API 122 int wc_falcon_priv_size(falcon_key* key); 123 WOLFSSL_API 124 int wc_falcon_pub_size(falcon_key* key); 125 WOLFSSL_API 126 int wc_falcon_sig_size(falcon_key* key); 127 128 #ifdef __cplusplus 129 } /* extern "C" */ 130 #endif 131 132 #endif /* HAVE_PQC */ 133 #endif /* WOLF_CRYPT_FALCON_H */ 134