Example program to test AES-GCM functionality. Used for a workshop

Dependencies:   mbed

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?

UserRevisionLine numberNew contents of line
HannesTschofenig 0:796d0f61a05b 1 /**
HannesTschofenig 0:796d0f61a05b 2 * \file base64.h
HannesTschofenig 0:796d0f61a05b 3 *
HannesTschofenig 0:796d0f61a05b 4 * \brief RFC 1521 base64 encoding/decoding
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_BASE64_H
HannesTschofenig 0:796d0f61a05b 28 #define POLARSSL_BASE64_H
HannesTschofenig 0:796d0f61a05b 29
HannesTschofenig 0:796d0f61a05b 30 #include <string.h>
HannesTschofenig 0:796d0f61a05b 31
HannesTschofenig 0:796d0f61a05b 32 #define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL -0x002A /**< Output buffer too small. */
HannesTschofenig 0:796d0f61a05b 33 #define POLARSSL_ERR_BASE64_INVALID_CHARACTER -0x002C /**< Invalid character in input. */
HannesTschofenig 0:796d0f61a05b 34
HannesTschofenig 0:796d0f61a05b 35 #ifdef __cplusplus
HannesTschofenig 0:796d0f61a05b 36 extern "C" {
HannesTschofenig 0:796d0f61a05b 37 #endif
HannesTschofenig 0:796d0f61a05b 38
HannesTschofenig 0:796d0f61a05b 39 /**
HannesTschofenig 0:796d0f61a05b 40 * \brief Encode a buffer into base64 format
HannesTschofenig 0:796d0f61a05b 41 *
HannesTschofenig 0:796d0f61a05b 42 * \param dst destination buffer
HannesTschofenig 0:796d0f61a05b 43 * \param dlen size of the buffer
HannesTschofenig 0:796d0f61a05b 44 * \param src source buffer
HannesTschofenig 0:796d0f61a05b 45 * \param slen amount of data to be encoded
HannesTschofenig 0:796d0f61a05b 46 *
HannesTschofenig 0:796d0f61a05b 47 * \return 0 if successful, or POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL.
HannesTschofenig 0:796d0f61a05b 48 * *dlen is always updated to reflect the amount
HannesTschofenig 0:796d0f61a05b 49 * of data that has (or would have) been written.
HannesTschofenig 0:796d0f61a05b 50 *
HannesTschofenig 0:796d0f61a05b 51 * \note Call this function with *dlen = 0 to obtain the
HannesTschofenig 0:796d0f61a05b 52 * required buffer size in *dlen
HannesTschofenig 0:796d0f61a05b 53 */
HannesTschofenig 0:796d0f61a05b 54 int base64_encode( unsigned char *dst, size_t *dlen,
HannesTschofenig 0:796d0f61a05b 55 const unsigned char *src, size_t slen );
HannesTschofenig 0:796d0f61a05b 56
HannesTschofenig 0:796d0f61a05b 57 /**
HannesTschofenig 0:796d0f61a05b 58 * \brief Decode a base64-formatted buffer
HannesTschofenig 0:796d0f61a05b 59 *
HannesTschofenig 0:796d0f61a05b 60 * \param dst destination buffer (can be NULL for checking size)
HannesTschofenig 0:796d0f61a05b 61 * \param dlen size of the buffer
HannesTschofenig 0:796d0f61a05b 62 * \param src source buffer
HannesTschofenig 0:796d0f61a05b 63 * \param slen amount of data to be decoded
HannesTschofenig 0:796d0f61a05b 64 *
HannesTschofenig 0:796d0f61a05b 65 * \return 0 if successful, POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL, or
HannesTschofenig 0:796d0f61a05b 66 * POLARSSL_ERR_BASE64_INVALID_CHARACTER if the input data is
HannesTschofenig 0:796d0f61a05b 67 * not correct. *dlen is always updated to reflect the amount
HannesTschofenig 0:796d0f61a05b 68 * of data that has (or would have) been written.
HannesTschofenig 0:796d0f61a05b 69 *
HannesTschofenig 0:796d0f61a05b 70 * \note Call this function with *dst = NULL or *dlen = 0 to obtain
HannesTschofenig 0:796d0f61a05b 71 * the required buffer size in *dlen
HannesTschofenig 0:796d0f61a05b 72 */
HannesTschofenig 0:796d0f61a05b 73 int base64_decode( unsigned char *dst, size_t *dlen,
HannesTschofenig 0:796d0f61a05b 74 const unsigned char *src, size_t slen );
HannesTschofenig 0:796d0f61a05b 75
HannesTschofenig 0:796d0f61a05b 76 /**
HannesTschofenig 0:796d0f61a05b 77 * \brief Checkup routine
HannesTschofenig 0:796d0f61a05b 78 *
HannesTschofenig 0:796d0f61a05b 79 * \return 0 if successful, or 1 if the test failed
HannesTschofenig 0:796d0f61a05b 80 */
HannesTschofenig 0:796d0f61a05b 81 int base64_self_test( int verbose );
HannesTschofenig 0:796d0f61a05b 82
HannesTschofenig 0:796d0f61a05b 83 #ifdef __cplusplus
HannesTschofenig 0:796d0f61a05b 84 }
HannesTschofenig 0:796d0f61a05b 85 #endif
HannesTschofenig 0:796d0f61a05b 86
HannesTschofenig 0:796d0f61a05b 87 #endif /* base64.h */
HannesTschofenig 0:796d0f61a05b 88
HannesTschofenig 0:796d0f61a05b 89