dsa.h (4414B)
1 /* dsa.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 /*! 23 \file wolfssl/wolfcrypt/dsa.h 24 */ 25 26 #ifndef WOLF_CRYPT_DSA_H 27 #define WOLF_CRYPT_DSA_H 28 29 #include <wolfssl/wolfcrypt/types.h> 30 31 #ifndef NO_DSA 32 33 #include <wolfssl/wolfcrypt/wolfmath.h> 34 #include <wolfssl/wolfcrypt/random.h> 35 36 /* for DSA reverse compatibility */ 37 #define InitDsaKey wc_InitDsaKey 38 #define FreeDsaKey wc_FreeDsaKey 39 #define DsaSign wc_DsaSign 40 #define DsaVerify wc_DsaVerify 41 #define DsaPublicKeyDecode wc_DsaPublicKeyDecode 42 #define DsaPrivateKeyDecode wc_DsaPrivateKeyDecode 43 #define DsaKeyToDer wc_DsaKeyToDer 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 50 enum { 51 DSA_PUBLIC = 0, 52 DSA_PRIVATE = 1 53 }; 54 55 enum { 56 /* 160 bit q length */ 57 DSA_160_HALF_SIZE = 20, /* r and s size */ 58 DSA_160_SIG_SIZE = 40, /* signature size */ 59 DSA_HALF_SIZE = DSA_160_HALF_SIZE, /* kept for compatibility */ 60 DSA_SIG_SIZE = DSA_160_SIG_SIZE, /* kept for compatibility */ 61 /* 256 bit q length */ 62 DSA_256_HALF_SIZE = 32, /* r and s size */ 63 DSA_256_SIG_SIZE = 64, /* signature size */ 64 65 DSA_MIN_HALF_SIZE = DSA_160_HALF_SIZE, 66 DSA_MIN_SIG_SIZE = DSA_160_SIG_SIZE, 67 68 DSA_MAX_HALF_SIZE = DSA_256_HALF_SIZE, 69 DSA_MAX_SIG_SIZE = DSA_256_SIG_SIZE 70 }; 71 72 /* DSA */ 73 typedef struct DsaKey { 74 mp_int p, q, g, y, x; 75 int type; /* public or private */ 76 void* heap; /* memory hint */ 77 } DsaKey; 78 79 WOLFSSL_API int wc_InitDsaKey(DsaKey* key); 80 WOLFSSL_API int wc_InitDsaKey_h(DsaKey* key, void* h); 81 WOLFSSL_API void wc_FreeDsaKey(DsaKey* key); 82 WOLFSSL_API int wc_DsaSign(const byte* digest, byte* out, 83 DsaKey* key, WC_RNG* rng); 84 WOLFSSL_API int wc_DsaSign_ex(const byte* digest, word32 digestSz, byte* out, 85 DsaKey* key, WC_RNG* rng); 86 WOLFSSL_API int wc_DsaVerify(const byte* digest, const byte* sig, 87 DsaKey* key, int* answer); 88 WOLFSSL_API int wc_DsaVerify_ex(const byte* digest, word32 digestSz, 89 const byte* sig, DsaKey* key, int* answer); 90 WOLFSSL_API int wc_DsaPublicKeyDecode(const byte* input, word32* inOutIdx, 91 DsaKey* key, word32 inSz); 92 WOLFSSL_API int wc_DsaPrivateKeyDecode(const byte* input, word32* inOutIdx, 93 DsaKey* key, word32 inSz); 94 WOLFSSL_API int wc_DsaKeyToDer(DsaKey* key, byte* output, word32 inLen); 95 WOLFSSL_API int wc_SetDsaPublicKey(byte* output, DsaKey* key, 96 int outLen, int with_header); 97 WOLFSSL_API int wc_DsaKeyToPublicDer(DsaKey* key, byte* output, word32 inLen); 98 99 #ifdef WOLFSSL_KEY_GEN 100 WOLFSSL_API int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa); 101 WOLFSSL_API int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa); 102 #endif 103 104 /* raw export functions */ 105 WOLFSSL_API int wc_DsaImportParamsRaw(DsaKey* dsa, const char* p, 106 const char* q, const char* g); 107 WOLFSSL_API int wc_DsaImportParamsRawCheck(DsaKey* dsa, const char* p, 108 const char* q, const char* g, 109 int trusted, WC_RNG* rng); 110 WOLFSSL_API int wc_DsaExportParamsRaw(DsaKey* dsa, byte* p, word32* pSz, 111 byte* q, word32* qSz, byte* g, 112 word32* gSz); 113 WOLFSSL_API int wc_DsaExportKeyRaw(DsaKey* dsa, byte* x, word32* xSz, byte* y, 114 word32* ySz); 115 #ifdef __cplusplus 116 } /* extern "C" */ 117 #endif 118 119 #endif /* NO_DSA */ 120 #endif /* WOLF_CRYPT_DSA_H */ 121