mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 05:05:37 +01:00
Add (placeholder) CCM module
This commit is contained in:
parent
47431b6d31
commit
a6916fada8
52
include/polarssl/ccm.h
Normal file
52
include/polarssl/ccm.h
Normal file
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* \file ccm.h
|
||||
*
|
||||
* \brief Counter with CBC-MAC (CCM) for 128-bit block ciphers
|
||||
*
|
||||
* Copyright (C) 2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
#ifndef POLARSSL_CCM_H
|
||||
#define POLARSSL_CCM_H
|
||||
|
||||
#include "cipher.h"
|
||||
|
||||
#define POLARSSL_ERR_CCM_BAD_INPUT -0x000D /**< Bad input parameters to function. */
|
||||
#define POLARSSL_ERR_CCM_AUTH_FAILED -0x000F /**< Authenticated decryption failed. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_SELF_TEST) && defined(POLARSSL_AES_C)
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
* \return 0 if successful, or 1 if the test failed
|
||||
*/
|
||||
int ccm_self_test( int verbose );
|
||||
#endif /* POLARSSL_SELF_TEST && POLARSSL_AES_C */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* POLARSSL_CGM_H */
|
@ -1274,6 +1274,20 @@
|
||||
*/
|
||||
#define POLARSSL_CAMELLIA_C
|
||||
|
||||
/**
|
||||
* \def POLARSSL_GCM_C
|
||||
*
|
||||
* Enable the Counter with CBC-MAC (CCM) mode for 128-bit block cipher.
|
||||
*
|
||||
* Module: library/ccm.c
|
||||
*
|
||||
* Requires: POLARSSL_AES_C or POLARSSL_CAMELLIA_C
|
||||
*
|
||||
* This module enables the AES-CCM ciphersuites, if other requisites are
|
||||
* enabled as well.
|
||||
*/
|
||||
#define POLARSSL_CCM_C
|
||||
|
||||
/**
|
||||
* \def POLARSSL_CERTS_C
|
||||
*
|
||||
|
@ -77,6 +77,7 @@
|
||||
* PBKDF2 1 0x007C-0x007C
|
||||
* RIPEMD160 1 0x007E-0x007E
|
||||
* HMAC_DRBG 4 0x0003-0x0009
|
||||
* CCM 2 0x000D-0x000F
|
||||
*
|
||||
* High-level module nr (3 bits - 0x0...-0x7...)
|
||||
* Name ID Nr of Errors
|
||||
|
@ -11,6 +11,7 @@ set(src
|
||||
bignum.c
|
||||
blowfish.c
|
||||
camellia.c
|
||||
ccm.c
|
||||
certs.c
|
||||
cipher.c
|
||||
cipher_wrap.c
|
||||
|
@ -37,7 +37,7 @@ endif
|
||||
OBJS= aes.o aesni.o arc4.o \
|
||||
asn1parse.o \
|
||||
asn1write.o base64.o bignum.o \
|
||||
blowfish.o camellia.o \
|
||||
blowfish.o camellia.o ccm.o \
|
||||
certs.o cipher.o cipher_wrap.o \
|
||||
ctr_drbg.o debug.o des.o \
|
||||
dhm.o ecdh.o ecdsa.o \
|
||||
|
67
library/ccm.c
Normal file
67
library/ccm.c
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* NIST SP800-38C compliant CCM implementation
|
||||
*
|
||||
* Copyright (C) 2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Definition of CCM:
|
||||
* http://csrc.nist.gov/publications/nistpubs/800-38C/SP800-38C_updated-July20_2007.pdf
|
||||
* RFC 3610 "Counter with CBC-MAC (CCM)"
|
||||
*
|
||||
* Related:
|
||||
* RFC 5116 "An Interface and Algorithms for Authenticated Encryption"
|
||||
*/
|
||||
|
||||
#if !defined(POLARSSL_CONFIG_FILE)
|
||||
#include "polarssl/config.h"
|
||||
#else
|
||||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_CCM_C)
|
||||
|
||||
#include "polarssl/ccm.h"
|
||||
|
||||
|
||||
#if defined(POLARSSL_SELF_TEST) && defined(POLARSSL_AES_C)
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
int ccm_self_test( int verbose )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
polarssl_printf( " CCM: skip\n" );
|
||||
|
||||
if( verbose != 0 )
|
||||
polarssl_printf( "\n" );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif /* POLARSSL_SELF_TEST && POLARSSL_AES_C */
|
||||
|
||||
#endif /* POLARSSL_CCM_C */
|
@ -53,6 +53,10 @@
|
||||
#include "polarssl/camellia.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_CCM_C)
|
||||
#include "polarssl/ccm.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_CIPHER_C)
|
||||
#include "polarssl/cipher.h"
|
||||
#endif
|
||||
@ -575,6 +579,13 @@ void polarssl_strerror( int ret, char *buf, size_t buflen )
|
||||
snprintf( buf, buflen, "CAMELLIA - Invalid data input length" );
|
||||
#endif /* POLARSSL_CAMELLIA_C */
|
||||
|
||||
#if defined(POLARSSL_CCM_C)
|
||||
if( use_ret == -(POLARSSL_ERR_CCM_BAD_INPUT) )
|
||||
snprintf( buf, buflen, "CCM - Bad input parameters to function" );
|
||||
if( use_ret == -(POLARSSL_ERR_CCM_AUTH_FAILED) )
|
||||
snprintf( buf, buflen, "CCM - Authenticated decryption failed" );
|
||||
#endif /* POLARSSL_CCM_C */
|
||||
|
||||
#if defined(POLARSSL_CTR_DRBG_C)
|
||||
if( use_ret == -(POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) )
|
||||
snprintf( buf, buflen, "CTR_DRBG - The entropy source failed" );
|
||||
|
@ -366,6 +366,9 @@ const char *features[] = {
|
||||
#if defined(POLARSSL_CAMELLIA_C)
|
||||
"POLARSSL_CAMELLIA_C",
|
||||
#endif /* POLARSSL_CAMELLIA_C */
|
||||
#if defined(POLARSSL_CCM_C)
|
||||
"POLARSSL_CCM_C",
|
||||
#endif /* POLARSSL_CCM_C */
|
||||
#if defined(POLARSSL_CERTS_C)
|
||||
"POLARSSL_CERTS_C",
|
||||
#endif /* POLARSSL_CERTS_C */
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "polarssl/ctr_drbg.h"
|
||||
#include "polarssl/dhm.h"
|
||||
#include "polarssl/gcm.h"
|
||||
#include "polarssl/ccm.h"
|
||||
#include "polarssl/md2.h"
|
||||
#include "polarssl/md4.h"
|
||||
#include "polarssl/md5.h"
|
||||
@ -132,11 +133,16 @@ int main( int argc, char *argv[] )
|
||||
return( ret );
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_GCM_C)
|
||||
#if defined(POLARSSL_GCM_C) && defined(POLARSSL_AES_C)
|
||||
if( ( ret = gcm_self_test( v ) ) != 0 )
|
||||
return( ret );
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_CCM_C) && defined(POLARSSL_AES_C)
|
||||
if( ( ret = ccm_self_test( v ) ) != 0 )
|
||||
return( ret );
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_BASE64_C)
|
||||
if( ( ret = base64_self_test( v ) ) != 0 )
|
||||
return( ret );
|
||||
|
@ -12,7 +12,7 @@ my @low_level_modules = ( "AES", "ASN1", "BLOWFISH", "CAMELLIA", "BIGNUM",
|
||||
"BASE64", "XTEA", "PBKDF2", "OID",
|
||||
"PADLOCK", "DES", "NET", "CTR_DRBG", "ENTROPY",
|
||||
"HMAC_DRBG", "MD2", "MD4", "MD5", "RIPEMD160",
|
||||
"SHA1", "SHA256", "SHA512", "GCM", "THREADING" );
|
||||
"SHA1", "SHA256", "SHA512", "GCM", "THREADING", "CCM" );
|
||||
my @high_level_modules = ( "PEM", "X509", "DHM", "RSA", "ECP", "MD", "CIPHER", "SSL",
|
||||
"PK", "PKCS12", "PKCS5" );
|
||||
|
||||
|
@ -43,6 +43,7 @@ add_test_suite(arc4)
|
||||
add_test_suite(base64)
|
||||
add_test_suite(blowfish)
|
||||
add_test_suite(camellia)
|
||||
add_test_suite(ccm)
|
||||
add_test_suite(cipher cipher.aes)
|
||||
add_test_suite(cipher cipher.arc4)
|
||||
add_test_suite(cipher cipher.blowfish)
|
||||
|
@ -34,7 +34,8 @@ APPS = test_suite_aes.ecb test_suite_aes.cbc \
|
||||
test_suite_aes.cfb test_suite_aes.rest \
|
||||
test_suite_arc4 \
|
||||
test_suite_base64 test_suite_blowfish \
|
||||
test_suite_camellia test_suite_cipher.aes \
|
||||
test_suite_camellia test_suite_ccm \
|
||||
test_suite_cipher.aes \
|
||||
test_suite_cipher.arc4 test_suite_cipher.gcm \
|
||||
test_suite_cipher.blowfish \
|
||||
test_suite_cipher.camellia \
|
||||
@ -198,6 +199,10 @@ test_suite_camellia: test_suite_camellia.c $(DEP)
|
||||
echo " CC $@.c"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
|
||||
|
||||
test_suite_ccm: test_suite_ccm.c $(DEP)
|
||||
echo " CC $@.c"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
|
||||
|
||||
test_suite_cipher.aes: test_suite_cipher.aes.c $(DEP)
|
||||
echo " CC $@.c"
|
||||
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
|
||||
|
2
tests/suites/test_suite_ccm.data
Normal file
2
tests/suites/test_suite_ccm.data
Normal file
@ -0,0 +1,2 @@
|
||||
CCM self test
|
||||
ccm_self_test:
|
15
tests/suites/test_suite_ccm.function
Normal file
15
tests/suites/test_suite_ccm.function
Normal file
@ -0,0 +1,15 @@
|
||||
/* BEGIN_HEADER */
|
||||
#include <polarssl/ccm.h>
|
||||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_DEPENDENCIES
|
||||
* depends_on:POLARSSL_CCM_C
|
||||
* END_DEPENDENCIES
|
||||
*/
|
||||
|
||||
/* BEGIN_CASE depends_on:POLARSSL_SELF_TEST:POLARSSL_AES_C */
|
||||
void ccm_self_test( )
|
||||
{
|
||||
TEST_ASSERT( ccm_self_test( 0 ) == 0 );
|
||||
}
|
||||
/* END_CASE */
|
@ -152,6 +152,7 @@
|
||||
<ClInclude Include="..\..\include\polarssl\blowfish.h" />
|
||||
<ClInclude Include="..\..\include\polarssl\bn_mul.h" />
|
||||
<ClInclude Include="..\..\include\polarssl\camellia.h" />
|
||||
<ClInclude Include="..\..\include\polarssl\ccm.h" />
|
||||
<ClInclude Include="..\..\include\polarssl\certs.h" />
|
||||
<ClInclude Include="..\..\include\polarssl\cipher.h" />
|
||||
<ClInclude Include="..\..\include\polarssl\cipher_wrap.h" />
|
||||
@ -216,6 +217,7 @@
|
||||
<ClCompile Include="..\..\library\bignum.c" />
|
||||
<ClCompile Include="..\..\library\blowfish.c" />
|
||||
<ClCompile Include="..\..\library\camellia.c" />
|
||||
<ClCompile Include="..\..\library\ccm.c" />
|
||||
<ClCompile Include="..\..\library\certs.c" />
|
||||
<ClCompile Include="..\..\library\cipher.c" />
|
||||
<ClCompile Include="..\..\library\cipher_wrap.c" />
|
||||
|
@ -121,6 +121,10 @@ SOURCE=..\..\library\camellia.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\library\ccm.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\library\certs.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -401,6 +405,10 @@ SOURCE=..\..\include\polarssl\camellia.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\polarssl\ccm.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\polarssl\certs.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
Loading…
Reference in New Issue
Block a user