00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #ifndef MBEDTLS_GCM_H
00057 #define MBEDTLS_GCM_H
00058
00059 #if !defined(MBEDTLS_CONFIG_FILE)
00060 #include "config.h"
00061 #else
00062 #include MBEDTLS_CONFIG_FILE
00063 #endif
00064
00065 #include "cipher.h"
00066
00067 #include <stdint.h>
00068
00069 #define MBEDTLS_GCM_ENCRYPT 1
00070 #define MBEDTLS_GCM_DECRYPT 0
00071
00072 #define MBEDTLS_ERR_GCM_AUTH_FAILED -0x0012
00073 #define MBEDTLS_ERR_GCM_HW_ACCEL_FAILED -0x0013
00074 #define MBEDTLS_ERR_GCM_BAD_INPUT -0x0014
00076 #if !defined(MBEDTLS_GCM_ALT)
00077
00078 #ifdef __cplusplus
00079 extern "C" {
00080 #endif
00081
00085 typedef struct {
00086 mbedtls_cipher_context_t cipher_ctx;
00087 uint64_t HL[16];
00088 uint64_t HH[16];
00089 uint64_t len;
00090 uint64_t add_len;
00091 unsigned char base_ectr[16];
00092 unsigned char y[16];
00093 unsigned char buf[16];
00094 int mode;
00097 }
00098 mbedtls_gcm_context;
00099
00111 void mbedtls_gcm_init( mbedtls_gcm_context *ctx );
00112
00127 int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx,
00128 mbedtls_cipher_id_t cipher,
00129 const unsigned char *key,
00130 unsigned int keybits );
00131
00176 int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx,
00177 int mode,
00178 size_t length,
00179 const unsigned char *iv,
00180 size_t iv_len,
00181 const unsigned char *add,
00182 size_t add_len,
00183 const unsigned char *input,
00184 unsigned char *output,
00185 size_t tag_len,
00186 unsigned char *tag );
00187
00215 int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx,
00216 size_t length,
00217 const unsigned char *iv,
00218 size_t iv_len,
00219 const unsigned char *add,
00220 size_t add_len,
00221 const unsigned char *tag,
00222 size_t tag_len,
00223 const unsigned char *input,
00224 unsigned char *output );
00225
00240 int mbedtls_gcm_starts( mbedtls_gcm_context *ctx,
00241 int mode,
00242 const unsigned char *iv,
00243 size_t iv_len,
00244 const unsigned char *add,
00245 size_t add_len );
00246
00266 int mbedtls_gcm_update( mbedtls_gcm_context *ctx,
00267 size_t length,
00268 const unsigned char *input,
00269 unsigned char *output );
00270
00284 int mbedtls_gcm_finish( mbedtls_gcm_context *ctx,
00285 unsigned char *tag,
00286 size_t tag_len );
00287
00294 void mbedtls_gcm_free( mbedtls_gcm_context *ctx );
00295
00296 #ifdef __cplusplus
00297 }
00298 #endif
00299
00300 #else
00301 #include "gcm_alt.h"
00302 #endif
00303
00304 #ifdef __cplusplus
00305 extern "C" {
00306 #endif
00307
00313 int mbedtls_gcm_self_test( int verbose );
00314
00315 #ifdef __cplusplus
00316 }
00317 #endif
00318
00319
00320 #endif