gnunet-android

GNUnet for Android
Log | Files | Refs | README

curve448.h (4606B)


      1 /* curve448.h
      2  *
      3  * Copyright (C) 2006-2025 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 3 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 /* Implemented to: RFC 7748 */
     23 
     24 
     25 #ifndef WOLF_CRYPT_CURVE448_H
     26 #define WOLF_CRYPT_CURVE448_H
     27 
     28 #include <wolfssl/wolfcrypt/types.h>
     29 
     30 #ifdef HAVE_CURVE448
     31 
     32 #include <wolfssl/wolfcrypt/fe_448.h>
     33 #include <wolfssl/wolfcrypt/random.h>
     34 
     35 #ifdef WOLFSSL_ASYNC_CRYPT
     36     #include <wolfssl/wolfcrypt/async.h>
     37 #endif
     38 
     39 #ifdef __cplusplus
     40     extern "C" {
     41 #endif
     42 
     43 #define CURVE448_KEY_SIZE        56
     44 #define CURVE448_PUB_KEY_SIZE    56
     45 
     46 #ifndef WC_CURVE448KEY_TYPE_DEFINED
     47     typedef struct curve448_key curve448_key;
     48     #define WC_CURVE448KEY_TYPE_DEFINED
     49 #endif
     50 
     51 /* A CURVE448 Key */
     52 struct curve448_key {
     53     byte p[CURVE448_PUB_KEY_SIZE];  /* public key  */
     54     byte k[CURVE448_KEY_SIZE];      /* private key */
     55 
     56 #ifdef WOLFSSL_ASYNC_CRYPT
     57     WC_ASYNC_DEV asyncDev;
     58 #endif
     59 
     60     /* bit fields */
     61     WC_BITFIELD pubSet:1;
     62     WC_BITFIELD privSet:1;
     63 };
     64 
     65 enum {
     66     EC448_LITTLE_ENDIAN = 0,
     67     EC448_BIG_ENDIAN    = 1
     68 };
     69 
     70 WOLFSSL_API
     71 int wc_curve448_make_key(WC_RNG* rng, int keysize, curve448_key* key);
     72 
     73 WOLFSSL_API
     74 int wc_curve448_make_pub(int public_size, byte* pub, int private_size,
     75                            const byte* priv);
     76 
     77 WOLFSSL_API
     78 int wc_curve448_shared_secret(curve448_key* private_key,
     79                               curve448_key* public_key,
     80                               byte* out, word32* outlen);
     81 
     82 WOLFSSL_API
     83 int wc_curve448_shared_secret_ex(curve448_key* private_key,
     84                                  curve448_key* public_key,
     85                                  byte* out, word32* outlen, int endian);
     86 
     87 WOLFSSL_API
     88 int wc_curve448_init(curve448_key* key);
     89 
     90 WOLFSSL_API
     91 void wc_curve448_free(curve448_key* key);
     92 
     93 
     94 /* raw key helpers */
     95 WOLFSSL_API
     96 int wc_curve448_import_private(const byte* priv, word32 privSz,
     97                                curve448_key* key);
     98 WOLFSSL_API
     99 int wc_curve448_import_private_ex(const byte* priv, word32 privSz,
    100                                   curve448_key* key, int endian);
    101 
    102 WOLFSSL_API
    103 int wc_curve448_import_private_raw(const byte* priv, word32 privSz,
    104                                    const byte* pub, word32 pubSz,
    105                                    curve448_key* key);
    106 WOLFSSL_API
    107 int wc_curve448_import_private_raw_ex(const byte* priv, word32 privSz,
    108                                       const byte* pub, word32 pubSz,
    109                                       curve448_key* key, int endian);
    110 WOLFSSL_API
    111 int wc_curve448_export_private_raw(curve448_key* key, byte* out,
    112                                    word32* outLen);
    113 WOLFSSL_API
    114 int wc_curve448_export_private_raw_ex(curve448_key* key, byte* out,
    115                                       word32* outLen, int endian);
    116 
    117 WOLFSSL_API
    118 int wc_curve448_import_public(const byte* in, word32 inLen,
    119                               curve448_key* key);
    120 WOLFSSL_API
    121 int wc_curve448_import_public_ex(const byte* in, word32 inLen,
    122                                  curve448_key* key, int endian);
    123 WOLFSSL_API
    124 int wc_curve448_check_public(const byte* pub, word32 pubSz, int endian);
    125 
    126 WOLFSSL_API
    127 int wc_curve448_export_public(curve448_key* key, byte* out, word32* outLen);
    128 WOLFSSL_API
    129 int wc_curve448_export_public_ex(curve448_key* key, byte* out,
    130                                  word32* outLen, int endian);
    131 
    132 WOLFSSL_API
    133 int wc_curve448_export_key_raw(curve448_key* key,
    134                                byte* priv, word32 *privSz,
    135                                byte* pub, word32 *pubSz);
    136 WOLFSSL_API
    137 int wc_curve448_export_key_raw_ex(curve448_key* key,
    138                                   byte* priv, word32 *privSz,
    139                                   byte* pub, word32 *pubSz,
    140                                   int endian);
    141 /* size helper */
    142 WOLFSSL_API
    143 int wc_curve448_size(curve448_key* key);
    144 
    145 #ifdef __cplusplus
    146     }    /* extern "C" */
    147 #endif
    148 
    149 #endif /* HAVE_CURVE448 */
    150 #endif /* WOLF_CRYPT_CURVE448_H */
    151