yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /* dsa.h |
| 2 | * |
| 3 | * Copyright (C) 2006-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/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/integer.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 | DSA_HALF_SIZE = 20, /* r and s size */ |
| 57 | DSA_SIG_SIZE = 40 /* signature size */ |
| 58 | }; |
| 59 | |
| 60 | /* DSA */ |
| 61 | typedef struct DsaKey { |
| 62 | mp_int p, q, g, y, x; |
| 63 | int type; /* public or private */ |
| 64 | void* heap; /* memory hint */ |
| 65 | } DsaKey; |
| 66 | |
| 67 | WOLFSSL_API int wc_InitDsaKey(DsaKey* key); |
| 68 | WOLFSSL_API int wc_InitDsaKey_h(DsaKey* key, void* h); |
| 69 | WOLFSSL_API void wc_FreeDsaKey(DsaKey* key); |
| 70 | WOLFSSL_API int wc_DsaSign(const byte* digest, byte* out, |
| 71 | DsaKey* key, WC_RNG* rng); |
| 72 | WOLFSSL_API int wc_DsaVerify(const byte* digest, const byte* sig, |
| 73 | DsaKey* key, int* answer); |
| 74 | WOLFSSL_API int wc_DsaPublicKeyDecode(const byte* input, word32* inOutIdx, |
| 75 | DsaKey*, word32); |
| 76 | WOLFSSL_API int wc_DsaPrivateKeyDecode(const byte* input, word32* inOutIdx, |
| 77 | DsaKey*, word32); |
| 78 | WOLFSSL_API int wc_DsaKeyToDer(DsaKey* key, byte* output, word32 inLen); |
| 79 | WOLFSSL_API int wc_SetDsaPublicKey(byte* output, DsaKey* key, |
| 80 | int outLen, int with_header); |
| 81 | WOLFSSL_API int wc_DsaKeyToPublicDer(DsaKey* key, byte* output, word32 inLen); |
| 82 | |
| 83 | #ifdef WOLFSSL_KEY_GEN |
| 84 | WOLFSSL_API int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa); |
| 85 | WOLFSSL_API int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa); |
| 86 | #endif |
| 87 | |
| 88 | /* raw export functions */ |
| 89 | WOLFSSL_API int wc_DsaImportParamsRaw(DsaKey* dsa, const char* p, |
| 90 | const char* q, const char* g); |
| 91 | WOLFSSL_API int wc_DsaImportParamsRawCheck(DsaKey* dsa, const char* p, |
| 92 | const char* q, const char* g, |
| 93 | int trusted, WC_RNG* rng); |
| 94 | WOLFSSL_API int wc_DsaExportParamsRaw(DsaKey* dsa, byte* p, word32* pSz, |
| 95 | byte* q, word32* qSz, byte* g, |
| 96 | word32* gSz); |
| 97 | WOLFSSL_API int wc_DsaExportKeyRaw(DsaKey* dsa, byte* x, word32* xSz, byte* y, |
| 98 | word32* ySz); |
| 99 | #ifdef __cplusplus |
| 100 | } /* extern "C" */ |
| 101 | #endif |
| 102 | |
| 103 | #endif /* NO_DSA */ |
| 104 | #endif /* WOLF_CRYPT_DSA_H */ |
| 105 | |