00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef MBEDTLS_GCM_H
00032 #define MBEDTLS_GCM_H
00033
00034 #if !defined(MBEDTLS_CONFIG_FILE)
00035 #include "config.h"
00036 #else
00037 #include MBEDTLS_CONFIG_FILE
00038 #endif
00039
00040 #include "cipher.h"
00041
00042 #include <stdint.h>
00043
00044 #define MBEDTLS_GCM_ENCRYPT 1
00045 #define MBEDTLS_GCM_DECRYPT 0
00046
00047 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
00048 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
00049 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
00051 #if !defined(MBEDTLS_GCM_ALT)
00052
00053 #ifdef __cplusplus
00054 extern "C" {
00055 #endif
00056
00060 typedef struct {
00061 mbedtls_cipher_context_t cipher_ctx;
00062 uint64_t HL[16];
00063 uint64_t HH[16];
00064 uint64_t len;
00065 uint64_t add_len;
00066 unsigned char base_ectr[16];
00067 unsigned char y[16];
00068 unsigned char buf[16];
00069 int mode;
00072 }
00073 mbedtls_gcm_context;
00074
00086 void mbedtls_gcm_init( mbedtls_gcm_context *ctx );
00087
00102 int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx,
00103 mbedtls_cipher_id_t cipher,
00104 const unsigned char *key,
00105 unsigned int keybits );
00106
00151 int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
00152 int mode,
00153 size_t length,
00154 const unsigned char *iv,
00155 size_t iv_len,
00156 const unsigned char *add,
00157 size_t add_len,
00158 const unsigned char *input,
00159 unsigned char *output,
00160 size_t tag_len,
00161 unsigned char *tag );
00162
00190 int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx,
00191 size_t length,
00192 const unsigned char *iv,
00193 size_t iv_len,
00194 const unsigned char *add,
00195 size_t add_len,
00196 const unsigned char *tag,
00197 size_t tag_len,
00198 const unsigned char *input,
00199 unsigned char *output );
00200
00215 int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
00216 int mode,
00217 const unsigned char *iv,
00218 size_t iv_len,
00219 const unsigned char *add,
00220 size_t add_len );
00221
00241 int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
00242 size_t length,
00243 const unsigned char *input,
00244 unsigned char *output );
00245
00259 int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
00260 unsigned char *tag,
00261 size_t tag_len );
00262
00269 void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
00270
00271 #ifdef __cplusplus
00272 }
00273 #endif
00274
00275 #else
00276 #include "gcm_alt.h"
00277 #endif
00278
00279 #ifdef __cplusplus
00280 extern "C" {
00281 #endif
00282
00288 int mbedtls_gcm_self_test( int verbose );
00289
00290 #ifdef __cplusplus
00291 }
00292 #endif
00293
00294
00295 #endif