Hannes Tschofenig
/
aes-gcm-test-program
Example program to test AES-GCM functionality. Used for a workshop
SSL/include/polarssl/dhm.h@0:796d0f61a05b, 2018-09-27 (annotated)
- Committer:
- HannesTschofenig
- Date:
- Thu Sep 27 06:34:22 2018 +0000
- Revision:
- 0:796d0f61a05b
Example AES-GCM test program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
HannesTschofenig | 0:796d0f61a05b | 1 | /** |
HannesTschofenig | 0:796d0f61a05b | 2 | * \file dhm.h |
HannesTschofenig | 0:796d0f61a05b | 3 | * |
HannesTschofenig | 0:796d0f61a05b | 4 | * \brief Diffie-Hellman-Merkle key exchange |
HannesTschofenig | 0:796d0f61a05b | 5 | * |
HannesTschofenig | 0:796d0f61a05b | 6 | * Copyright (C) 2006-2013, Brainspark B.V. |
HannesTschofenig | 0:796d0f61a05b | 7 | * |
HannesTschofenig | 0:796d0f61a05b | 8 | * This file is part of PolarSSL (http://www.polarssl.org) |
HannesTschofenig | 0:796d0f61a05b | 9 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
HannesTschofenig | 0:796d0f61a05b | 10 | * |
HannesTschofenig | 0:796d0f61a05b | 11 | * All rights reserved. |
HannesTschofenig | 0:796d0f61a05b | 12 | * |
HannesTschofenig | 0:796d0f61a05b | 13 | * This program is free software; you can redistribute it and/or modify |
HannesTschofenig | 0:796d0f61a05b | 14 | * it under the terms of the GNU General Public License as published by |
HannesTschofenig | 0:796d0f61a05b | 15 | * the Free Software Foundation; either version 2 of the License, or |
HannesTschofenig | 0:796d0f61a05b | 16 | * (at your option) any later version. |
HannesTschofenig | 0:796d0f61a05b | 17 | * |
HannesTschofenig | 0:796d0f61a05b | 18 | * This program is distributed in the hope that it will be useful, |
HannesTschofenig | 0:796d0f61a05b | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
HannesTschofenig | 0:796d0f61a05b | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
HannesTschofenig | 0:796d0f61a05b | 21 | * GNU General Public License for more details. |
HannesTschofenig | 0:796d0f61a05b | 22 | * |
HannesTschofenig | 0:796d0f61a05b | 23 | * You should have received a copy of the GNU General Public License along |
HannesTschofenig | 0:796d0f61a05b | 24 | * with this program; if not, write to the Free Software Foundation, Inc., |
HannesTschofenig | 0:796d0f61a05b | 25 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
HannesTschofenig | 0:796d0f61a05b | 26 | */ |
HannesTschofenig | 0:796d0f61a05b | 27 | #ifndef POLARSSL_DHM_H |
HannesTschofenig | 0:796d0f61a05b | 28 | #define POLARSSL_DHM_H |
HannesTschofenig | 0:796d0f61a05b | 29 | |
HannesTschofenig | 0:796d0f61a05b | 30 | #include "bignum.h" |
HannesTschofenig | 0:796d0f61a05b | 31 | |
HannesTschofenig | 0:796d0f61a05b | 32 | /* |
HannesTschofenig | 0:796d0f61a05b | 33 | * DHM Error codes |
HannesTschofenig | 0:796d0f61a05b | 34 | */ |
HannesTschofenig | 0:796d0f61a05b | 35 | #define POLARSSL_ERR_DHM_BAD_INPUT_DATA -0x3080 /**< Bad input parameters to function. */ |
HannesTschofenig | 0:796d0f61a05b | 36 | #define POLARSSL_ERR_DHM_READ_PARAMS_FAILED -0x3100 /**< Reading of the DHM parameters failed. */ |
HannesTschofenig | 0:796d0f61a05b | 37 | #define POLARSSL_ERR_DHM_MAKE_PARAMS_FAILED -0x3180 /**< Making of the DHM parameters failed. */ |
HannesTschofenig | 0:796d0f61a05b | 38 | #define POLARSSL_ERR_DHM_READ_PUBLIC_FAILED -0x3200 /**< Reading of the public values failed. */ |
HannesTschofenig | 0:796d0f61a05b | 39 | #define POLARSSL_ERR_DHM_MAKE_PUBLIC_FAILED -0x3280 /**< Making of the public value failed. */ |
HannesTschofenig | 0:796d0f61a05b | 40 | #define POLARSSL_ERR_DHM_CALC_SECRET_FAILED -0x3300 /**< Calculation of the DHM secret failed. */ |
HannesTschofenig | 0:796d0f61a05b | 41 | #define POLARSSL_ERR_DHM_INVALID_FORMAT -0x3380 /**< The ASN.1 data is not formatted correctly. */ |
HannesTschofenig | 0:796d0f61a05b | 42 | #define POLARSSL_ERR_DHM_MALLOC_FAILED -0x3400 /**< Allocation of memory failed. */ |
HannesTschofenig | 0:796d0f61a05b | 43 | #define POLARSSL_ERR_DHM_FILE_IO_ERROR -0x3480 /**< Read/write of file failed. */ |
HannesTschofenig | 0:796d0f61a05b | 44 | |
HannesTschofenig | 0:796d0f61a05b | 45 | /** |
HannesTschofenig | 0:796d0f61a05b | 46 | * RFC 3526 defines a number of standardized Diffie-Hellman groups |
HannesTschofenig | 0:796d0f61a05b | 47 | * for IKE. |
HannesTschofenig | 0:796d0f61a05b | 48 | * RFC 5114 defines a number of standardized Diffie-Hellman groups |
HannesTschofenig | 0:796d0f61a05b | 49 | * that can be used. |
HannesTschofenig | 0:796d0f61a05b | 50 | * |
HannesTschofenig | 0:796d0f61a05b | 51 | * Some are included here for convenience. |
HannesTschofenig | 0:796d0f61a05b | 52 | * |
HannesTschofenig | 0:796d0f61a05b | 53 | * Included are: |
HannesTschofenig | 0:796d0f61a05b | 54 | * RFC 3526 3. 2048-bit MODP Group |
HannesTschofenig | 0:796d0f61a05b | 55 | * RFC 3526 4. 3072-bit MODP Group |
HannesTschofenig | 0:796d0f61a05b | 56 | * RFC 5114 2.1. 1024-bit MODP Group with 160-bit Prime Order Subgroup |
HannesTschofenig | 0:796d0f61a05b | 57 | * RFC 5114 2.2. 2048-bit MODP Group with 224-bit Prime Order Subgroup |
HannesTschofenig | 0:796d0f61a05b | 58 | */ |
HannesTschofenig | 0:796d0f61a05b | 59 | #define POLARSSL_DHM_RFC3526_MODP_2048_P \ |
HannesTschofenig | 0:796d0f61a05b | 60 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ |
HannesTschofenig | 0:796d0f61a05b | 61 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ |
HannesTschofenig | 0:796d0f61a05b | 62 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ |
HannesTschofenig | 0:796d0f61a05b | 63 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \ |
HannesTschofenig | 0:796d0f61a05b | 64 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \ |
HannesTschofenig | 0:796d0f61a05b | 65 | "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \ |
HannesTschofenig | 0:796d0f61a05b | 66 | "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \ |
HannesTschofenig | 0:796d0f61a05b | 67 | "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \ |
HannesTschofenig | 0:796d0f61a05b | 68 | "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \ |
HannesTschofenig | 0:796d0f61a05b | 69 | "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \ |
HannesTschofenig | 0:796d0f61a05b | 70 | "15728E5A8AACAA68FFFFFFFFFFFFFFFF" |
HannesTschofenig | 0:796d0f61a05b | 71 | |
HannesTschofenig | 0:796d0f61a05b | 72 | #define POLARSSL_DHM_RFC3526_MODP_2048_G "02" |
HannesTschofenig | 0:796d0f61a05b | 73 | |
HannesTschofenig | 0:796d0f61a05b | 74 | #define POLARSSL_DHM_RFC3526_MODP_3072_P \ |
HannesTschofenig | 0:796d0f61a05b | 75 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ |
HannesTschofenig | 0:796d0f61a05b | 76 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ |
HannesTschofenig | 0:796d0f61a05b | 77 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ |
HannesTschofenig | 0:796d0f61a05b | 78 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \ |
HannesTschofenig | 0:796d0f61a05b | 79 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \ |
HannesTschofenig | 0:796d0f61a05b | 80 | "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \ |
HannesTschofenig | 0:796d0f61a05b | 81 | "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \ |
HannesTschofenig | 0:796d0f61a05b | 82 | "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \ |
HannesTschofenig | 0:796d0f61a05b | 83 | "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \ |
HannesTschofenig | 0:796d0f61a05b | 84 | "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \ |
HannesTschofenig | 0:796d0f61a05b | 85 | "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \ |
HannesTschofenig | 0:796d0f61a05b | 86 | "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \ |
HannesTschofenig | 0:796d0f61a05b | 87 | "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \ |
HannesTschofenig | 0:796d0f61a05b | 88 | "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \ |
HannesTschofenig | 0:796d0f61a05b | 89 | "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \ |
HannesTschofenig | 0:796d0f61a05b | 90 | "43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF" |
HannesTschofenig | 0:796d0f61a05b | 91 | |
HannesTschofenig | 0:796d0f61a05b | 92 | #define POLARSSL_DHM_RFC3526_MODP_3072_G "02" |
HannesTschofenig | 0:796d0f61a05b | 93 | |
HannesTschofenig | 0:796d0f61a05b | 94 | #define POLARSSL_DHM_RFC5114_MODP_1024_P \ |
HannesTschofenig | 0:796d0f61a05b | 95 | "B10B8F96A080E01DDE92DE5EAE5D54EC52C99FBCFB06A3C6" \ |
HannesTschofenig | 0:796d0f61a05b | 96 | "9A6A9DCA52D23B616073E28675A23D189838EF1E2EE652C0" \ |
HannesTschofenig | 0:796d0f61a05b | 97 | "13ECB4AEA906112324975C3CD49B83BFACCBDD7D90C4BD70" \ |
HannesTschofenig | 0:796d0f61a05b | 98 | "98488E9C219A73724EFFD6FAE5644738FAA31A4FF55BCCC0" \ |
HannesTschofenig | 0:796d0f61a05b | 99 | "A151AF5F0DC8B4BD45BF37DF365C1A65E68CFDA76D4DA708" \ |
HannesTschofenig | 0:796d0f61a05b | 100 | "DF1FB2BC2E4A4371" |
HannesTschofenig | 0:796d0f61a05b | 101 | |
HannesTschofenig | 0:796d0f61a05b | 102 | #define POLARSSL_DHM_RFC5114_MODP_1024_G \ |
HannesTschofenig | 0:796d0f61a05b | 103 | "A4D1CBD5C3FD34126765A442EFB99905F8104DD258AC507F" \ |
HannesTschofenig | 0:796d0f61a05b | 104 | "D6406CFF14266D31266FEA1E5C41564B777E690F5504F213" \ |
HannesTschofenig | 0:796d0f61a05b | 105 | "160217B4B01B886A5E91547F9E2749F4D7FBD7D3B9A92EE1" \ |
HannesTschofenig | 0:796d0f61a05b | 106 | "909D0D2263F80A76A6A24C087A091F531DBF0A0169B6A28A" \ |
HannesTschofenig | 0:796d0f61a05b | 107 | "D662A4D18E73AFA32D779D5918D08BC8858F4DCEF97C2A24" \ |
HannesTschofenig | 0:796d0f61a05b | 108 | "855E6EEB22B3B2E5" |
HannesTschofenig | 0:796d0f61a05b | 109 | |
HannesTschofenig | 0:796d0f61a05b | 110 | #define POLARSSL_DHM_RFC5114_MODP_2048_P \ |
HannesTschofenig | 0:796d0f61a05b | 111 | "AD107E1E9123A9D0D660FAA79559C51FA20D64E5683B9FD1" \ |
HannesTschofenig | 0:796d0f61a05b | 112 | "B54B1597B61D0A75E6FA141DF95A56DBAF9A3C407BA1DF15" \ |
HannesTschofenig | 0:796d0f61a05b | 113 | "EB3D688A309C180E1DE6B85A1274A0A66D3F8152AD6AC212" \ |
HannesTschofenig | 0:796d0f61a05b | 114 | "9037C9EDEFDA4DF8D91E8FEF55B7394B7AD5B7D0B6C12207" \ |
HannesTschofenig | 0:796d0f61a05b | 115 | "C9F98D11ED34DBF6C6BA0B2C8BBC27BE6A00E0A0B9C49708" \ |
HannesTschofenig | 0:796d0f61a05b | 116 | "B3BF8A317091883681286130BC8985DB1602E714415D9330" \ |
HannesTschofenig | 0:796d0f61a05b | 117 | "278273C7DE31EFDC7310F7121FD5A07415987D9ADC0A486D" \ |
HannesTschofenig | 0:796d0f61a05b | 118 | "CDF93ACC44328387315D75E198C641A480CD86A1B9E587E8" \ |
HannesTschofenig | 0:796d0f61a05b | 119 | "BE60E69CC928B2B9C52172E413042E9B23F10B0E16E79763" \ |
HannesTschofenig | 0:796d0f61a05b | 120 | "C9B53DCF4BA80A29E3FB73C16B8E75B97EF363E2FFA31F71" \ |
HannesTschofenig | 0:796d0f61a05b | 121 | "CF9DE5384E71B81C0AC4DFFE0C10E64F" |
HannesTschofenig | 0:796d0f61a05b | 122 | |
HannesTschofenig | 0:796d0f61a05b | 123 | #define POLARSSL_DHM_RFC5114_MODP_2048_G \ |
HannesTschofenig | 0:796d0f61a05b | 124 | "AC4032EF4F2D9AE39DF30B5C8FFDAC506CDEBE7B89998CAF"\ |
HannesTschofenig | 0:796d0f61a05b | 125 | "74866A08CFE4FFE3A6824A4E10B9A6F0DD921F01A70C4AFA"\ |
HannesTschofenig | 0:796d0f61a05b | 126 | "AB739D7700C29F52C57DB17C620A8652BE5E9001A8D66AD7"\ |
HannesTschofenig | 0:796d0f61a05b | 127 | "C17669101999024AF4D027275AC1348BB8A762D0521BC98A"\ |
HannesTschofenig | 0:796d0f61a05b | 128 | "E247150422EA1ED409939D54DA7460CDB5F6C6B250717CBE"\ |
HannesTschofenig | 0:796d0f61a05b | 129 | "F180EB34118E98D119529A45D6F834566E3025E316A330EF"\ |
HannesTschofenig | 0:796d0f61a05b | 130 | "BB77A86F0C1AB15B051AE3D428C8F8ACB70A8137150B8EEB"\ |
HannesTschofenig | 0:796d0f61a05b | 131 | "10E183EDD19963DDD9E263E4770589EF6AA21E7F5F2FF381"\ |
HannesTschofenig | 0:796d0f61a05b | 132 | "B539CCE3409D13CD566AFBB48D6C019181E1BCFE94B30269"\ |
HannesTschofenig | 0:796d0f61a05b | 133 | "EDFE72FE9B6AA4BD7B5A0F1C71CFFF4C19C418E1F6EC0179"\ |
HannesTschofenig | 0:796d0f61a05b | 134 | "81BC087F2A7065B384B890D3191F2BFA" |
HannesTschofenig | 0:796d0f61a05b | 135 | |
HannesTschofenig | 0:796d0f61a05b | 136 | #ifdef __cplusplus |
HannesTschofenig | 0:796d0f61a05b | 137 | extern "C" { |
HannesTschofenig | 0:796d0f61a05b | 138 | #endif |
HannesTschofenig | 0:796d0f61a05b | 139 | |
HannesTschofenig | 0:796d0f61a05b | 140 | /** |
HannesTschofenig | 0:796d0f61a05b | 141 | * \brief DHM context structure |
HannesTschofenig | 0:796d0f61a05b | 142 | */ |
HannesTschofenig | 0:796d0f61a05b | 143 | typedef struct |
HannesTschofenig | 0:796d0f61a05b | 144 | { |
HannesTschofenig | 0:796d0f61a05b | 145 | size_t len; /*!< size(P) in chars */ |
HannesTschofenig | 0:796d0f61a05b | 146 | mpi P; /*!< prime modulus */ |
HannesTschofenig | 0:796d0f61a05b | 147 | mpi G; /*!< generator */ |
HannesTschofenig | 0:796d0f61a05b | 148 | mpi X; /*!< secret value */ |
HannesTschofenig | 0:796d0f61a05b | 149 | mpi GX; /*!< self = G^X mod P */ |
HannesTschofenig | 0:796d0f61a05b | 150 | mpi GY; /*!< peer = G^Y mod P */ |
HannesTschofenig | 0:796d0f61a05b | 151 | mpi K; /*!< key = GY^X mod P */ |
HannesTschofenig | 0:796d0f61a05b | 152 | mpi RP; /*!< cached R^2 mod P */ |
HannesTschofenig | 0:796d0f61a05b | 153 | mpi Vi; /*!< blinding value */ |
HannesTschofenig | 0:796d0f61a05b | 154 | mpi Vf; /*!< un-blinding value */ |
HannesTschofenig | 0:796d0f61a05b | 155 | mpi pX; /*!< previous X */ |
HannesTschofenig | 0:796d0f61a05b | 156 | } |
HannesTschofenig | 0:796d0f61a05b | 157 | dhm_context; |
HannesTschofenig | 0:796d0f61a05b | 158 | |
HannesTschofenig | 0:796d0f61a05b | 159 | /** |
HannesTschofenig | 0:796d0f61a05b | 160 | * \brief Parse the ServerKeyExchange parameters |
HannesTschofenig | 0:796d0f61a05b | 161 | * |
HannesTschofenig | 0:796d0f61a05b | 162 | * \param ctx DHM context |
HannesTschofenig | 0:796d0f61a05b | 163 | * \param p &(start of input buffer) |
HannesTschofenig | 0:796d0f61a05b | 164 | * \param end end of buffer |
HannesTschofenig | 0:796d0f61a05b | 165 | * |
HannesTschofenig | 0:796d0f61a05b | 166 | * \return 0 if successful, or an POLARSSL_ERR_DHM_XXX error code |
HannesTschofenig | 0:796d0f61a05b | 167 | */ |
HannesTschofenig | 0:796d0f61a05b | 168 | int dhm_read_params( dhm_context *ctx, |
HannesTschofenig | 0:796d0f61a05b | 169 | unsigned char **p, |
HannesTschofenig | 0:796d0f61a05b | 170 | const unsigned char *end ); |
HannesTschofenig | 0:796d0f61a05b | 171 | |
HannesTschofenig | 0:796d0f61a05b | 172 | /** |
HannesTschofenig | 0:796d0f61a05b | 173 | * \brief Setup and write the ServerKeyExchange parameters |
HannesTschofenig | 0:796d0f61a05b | 174 | * |
HannesTschofenig | 0:796d0f61a05b | 175 | * \param ctx DHM context |
HannesTschofenig | 0:796d0f61a05b | 176 | * \param x_size private value size in bytes |
HannesTschofenig | 0:796d0f61a05b | 177 | * \param output destination buffer |
HannesTschofenig | 0:796d0f61a05b | 178 | * \param olen number of chars written |
HannesTschofenig | 0:796d0f61a05b | 179 | * \param f_rng RNG function |
HannesTschofenig | 0:796d0f61a05b | 180 | * \param p_rng RNG parameter |
HannesTschofenig | 0:796d0f61a05b | 181 | * |
HannesTschofenig | 0:796d0f61a05b | 182 | * \note This function assumes that ctx->P and ctx->G |
HannesTschofenig | 0:796d0f61a05b | 183 | * have already been properly set (for example |
HannesTschofenig | 0:796d0f61a05b | 184 | * using mpi_read_string or mpi_read_binary). |
HannesTschofenig | 0:796d0f61a05b | 185 | * |
HannesTschofenig | 0:796d0f61a05b | 186 | * \return 0 if successful, or an POLARSSL_ERR_DHM_XXX error code |
HannesTschofenig | 0:796d0f61a05b | 187 | */ |
HannesTschofenig | 0:796d0f61a05b | 188 | int dhm_make_params( dhm_context *ctx, int x_size, |
HannesTschofenig | 0:796d0f61a05b | 189 | unsigned char *output, size_t *olen, |
HannesTschofenig | 0:796d0f61a05b | 190 | int (*f_rng)(void *, unsigned char *, size_t), |
HannesTschofenig | 0:796d0f61a05b | 191 | void *p_rng ); |
HannesTschofenig | 0:796d0f61a05b | 192 | |
HannesTschofenig | 0:796d0f61a05b | 193 | /** |
HannesTschofenig | 0:796d0f61a05b | 194 | * \brief Import the peer's public value G^Y |
HannesTschofenig | 0:796d0f61a05b | 195 | * |
HannesTschofenig | 0:796d0f61a05b | 196 | * \param ctx DHM context |
HannesTschofenig | 0:796d0f61a05b | 197 | * \param input input buffer |
HannesTschofenig | 0:796d0f61a05b | 198 | * \param ilen size of buffer |
HannesTschofenig | 0:796d0f61a05b | 199 | * |
HannesTschofenig | 0:796d0f61a05b | 200 | * \return 0 if successful, or an POLARSSL_ERR_DHM_XXX error code |
HannesTschofenig | 0:796d0f61a05b | 201 | */ |
HannesTschofenig | 0:796d0f61a05b | 202 | int dhm_read_public( dhm_context *ctx, |
HannesTschofenig | 0:796d0f61a05b | 203 | const unsigned char *input, size_t ilen ); |
HannesTschofenig | 0:796d0f61a05b | 204 | |
HannesTschofenig | 0:796d0f61a05b | 205 | /** |
HannesTschofenig | 0:796d0f61a05b | 206 | * \brief Create own private value X and export G^X |
HannesTschofenig | 0:796d0f61a05b | 207 | * |
HannesTschofenig | 0:796d0f61a05b | 208 | * \param ctx DHM context |
HannesTschofenig | 0:796d0f61a05b | 209 | * \param x_size private value size in bytes |
HannesTschofenig | 0:796d0f61a05b | 210 | * \param output destination buffer |
HannesTschofenig | 0:796d0f61a05b | 211 | * \param olen must be equal to ctx->P.len |
HannesTschofenig | 0:796d0f61a05b | 212 | * \param f_rng RNG function |
HannesTschofenig | 0:796d0f61a05b | 213 | * \param p_rng RNG parameter |
HannesTschofenig | 0:796d0f61a05b | 214 | * |
HannesTschofenig | 0:796d0f61a05b | 215 | * \return 0 if successful, or an POLARSSL_ERR_DHM_XXX error code |
HannesTschofenig | 0:796d0f61a05b | 216 | */ |
HannesTschofenig | 0:796d0f61a05b | 217 | int dhm_make_public( dhm_context *ctx, int x_size, |
HannesTschofenig | 0:796d0f61a05b | 218 | unsigned char *output, size_t olen, |
HannesTschofenig | 0:796d0f61a05b | 219 | int (*f_rng)(void *, unsigned char *, size_t), |
HannesTschofenig | 0:796d0f61a05b | 220 | void *p_rng ); |
HannesTschofenig | 0:796d0f61a05b | 221 | |
HannesTschofenig | 0:796d0f61a05b | 222 | /** |
HannesTschofenig | 0:796d0f61a05b | 223 | * \brief Derive and export the shared secret (G^Y)^X mod P |
HannesTschofenig | 0:796d0f61a05b | 224 | * |
HannesTschofenig | 0:796d0f61a05b | 225 | * \param ctx DHM context |
HannesTschofenig | 0:796d0f61a05b | 226 | * \param output destination buffer |
HannesTschofenig | 0:796d0f61a05b | 227 | * \param olen number of chars written |
HannesTschofenig | 0:796d0f61a05b | 228 | * \param f_rng RNG function, for blinding purposes |
HannesTschofenig | 0:796d0f61a05b | 229 | * \param p_rng RNG parameter |
HannesTschofenig | 0:796d0f61a05b | 230 | * |
HannesTschofenig | 0:796d0f61a05b | 231 | * \return 0 if successful, or an POLARSSL_ERR_DHM_XXX error code |
HannesTschofenig | 0:796d0f61a05b | 232 | * |
HannesTschofenig | 0:796d0f61a05b | 233 | * \note If non-NULL, f_rng is used to blind the input as |
HannesTschofenig | 0:796d0f61a05b | 234 | * countermeasure against timing attacks. Blinding is |
HannesTschofenig | 0:796d0f61a05b | 235 | * automatically used if and only if our secret value X is |
HannesTschofenig | 0:796d0f61a05b | 236 | * re-used and costs nothing otherwise, so it is recommended |
HannesTschofenig | 0:796d0f61a05b | 237 | * to always pass a non-NULL f_rng argument. |
HannesTschofenig | 0:796d0f61a05b | 238 | */ |
HannesTschofenig | 0:796d0f61a05b | 239 | int dhm_calc_secret( dhm_context *ctx, |
HannesTschofenig | 0:796d0f61a05b | 240 | unsigned char *output, size_t *olen, |
HannesTschofenig | 0:796d0f61a05b | 241 | int (*f_rng)(void *, unsigned char *, size_t), |
HannesTschofenig | 0:796d0f61a05b | 242 | void *p_rng ); |
HannesTschofenig | 0:796d0f61a05b | 243 | |
HannesTschofenig | 0:796d0f61a05b | 244 | /** |
HannesTschofenig | 0:796d0f61a05b | 245 | * \brief Free the components of a DHM key |
HannesTschofenig | 0:796d0f61a05b | 246 | */ |
HannesTschofenig | 0:796d0f61a05b | 247 | void dhm_free( dhm_context *ctx ); |
HannesTschofenig | 0:796d0f61a05b | 248 | |
HannesTschofenig | 0:796d0f61a05b | 249 | #if defined(POLARSSL_ASN1_PARSE_C) |
HannesTschofenig | 0:796d0f61a05b | 250 | /** \ingroup x509_module */ |
HannesTschofenig | 0:796d0f61a05b | 251 | /** |
HannesTschofenig | 0:796d0f61a05b | 252 | * \brief Parse DHM parameters |
HannesTschofenig | 0:796d0f61a05b | 253 | * |
HannesTschofenig | 0:796d0f61a05b | 254 | * \param dhm DHM context to be initialized |
HannesTschofenig | 0:796d0f61a05b | 255 | * \param dhmin input buffer |
HannesTschofenig | 0:796d0f61a05b | 256 | * \param dhminlen size of the buffer |
HannesTschofenig | 0:796d0f61a05b | 257 | * |
HannesTschofenig | 0:796d0f61a05b | 258 | * \return 0 if successful, or a specific DHM or PEM error code |
HannesTschofenig | 0:796d0f61a05b | 259 | */ |
HannesTschofenig | 0:796d0f61a05b | 260 | int dhm_parse_dhm( dhm_context *dhm, const unsigned char *dhmin, |
HannesTschofenig | 0:796d0f61a05b | 261 | size_t dhminlen ); |
HannesTschofenig | 0:796d0f61a05b | 262 | |
HannesTschofenig | 0:796d0f61a05b | 263 | #if defined(POLARSSL_FS_IO) |
HannesTschofenig | 0:796d0f61a05b | 264 | /** \ingroup x509_module */ |
HannesTschofenig | 0:796d0f61a05b | 265 | /** |
HannesTschofenig | 0:796d0f61a05b | 266 | * \brief Load and parse DHM parameters |
HannesTschofenig | 0:796d0f61a05b | 267 | * |
HannesTschofenig | 0:796d0f61a05b | 268 | * \param dhm DHM context to be initialized |
HannesTschofenig | 0:796d0f61a05b | 269 | * \param path filename to read the DHM Parameters from |
HannesTschofenig | 0:796d0f61a05b | 270 | * |
HannesTschofenig | 0:796d0f61a05b | 271 | * \return 0 if successful, or a specific DHM or PEM error code |
HannesTschofenig | 0:796d0f61a05b | 272 | */ |
HannesTschofenig | 0:796d0f61a05b | 273 | int dhm_parse_dhmfile( dhm_context *dhm, const char *path ); |
HannesTschofenig | 0:796d0f61a05b | 274 | #endif /* POLARSSL_FS_IO */ |
HannesTschofenig | 0:796d0f61a05b | 275 | #endif /* POLARSSL_ASN1_PARSE_C */ |
HannesTschofenig | 0:796d0f61a05b | 276 | |
HannesTschofenig | 0:796d0f61a05b | 277 | /** |
HannesTschofenig | 0:796d0f61a05b | 278 | * \brief Checkup routine |
HannesTschofenig | 0:796d0f61a05b | 279 | * |
HannesTschofenig | 0:796d0f61a05b | 280 | * \return 0 if successful, or 1 if the test failed |
HannesTschofenig | 0:796d0f61a05b | 281 | */ |
HannesTschofenig | 0:796d0f61a05b | 282 | int dhm_self_test( int verbose ); |
HannesTschofenig | 0:796d0f61a05b | 283 | |
HannesTschofenig | 0:796d0f61a05b | 284 | #ifdef __cplusplus |
HannesTschofenig | 0:796d0f61a05b | 285 | } |
HannesTschofenig | 0:796d0f61a05b | 286 | #endif |
HannesTschofenig | 0:796d0f61a05b | 287 | |
HannesTschofenig | 0:796d0f61a05b | 288 | #endif /* dhm.h */ |
HannesTschofenig | 0:796d0f61a05b | 289 | |
HannesTschofenig | 0:796d0f61a05b | 290 |