mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-12-01 23:19:13 +00:00
Merge pull request #3302 from signalwire/libsrtp
[Core] Remove in-tree libsrtp: use libsrtp2-dev on Linux and the windows-deps package on Windows
This commit is contained in:
153 files changed
+135
-38928
No files matched your search
@@ -53,6 +53,7 @@ jobs:
|
||||
sofia-sip \
|
||||
speex \
|
||||
speexdsp \
|
||||
srtp \
|
||||
sqlite \
|
||||
&& \
|
||||
brew list --pinned | awk '{system("brew unpin " $1)}' && \
|
||||
|
||||
@@ -299,6 +299,8 @@ libs/miniupnpc-*/
|
||||
libs/miniupnpc-*.zip
|
||||
libs/libnatpmp-*/
|
||||
libs/libnatpmp-*.zip
|
||||
libs/libsrtp-*/
|
||||
libs/libsrtp-*.zip
|
||||
libs/SharpZipLib.*/
|
||||
libs/SharpZipLib.*.nupkg
|
||||
libs/nasm-*/
|
||||
|
||||
@@ -204,8 +204,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_dptools", "src\mod\appl
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_event_socket", "src\mod\event_handlers\mod_event_socket\mod_event_socket.2017.vcxproj", "{05515420-16DE-4E63-BE73-85BE85BA5142}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libsrtp", "libs\srtp\libsrtp.2017.vcxproj", "{EEF031CB-FED8-451E-A471-91EC8D4F6750}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libapr", "libs\win32\apr\libapr.2017.vcxproj", "{F6C55D93-B927-4483-BB69-15AEF3DD2DFF}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mod_sofia", "src\mod\endpoints\mod_sofia\mod_sofia.2017.vcxproj", "{0DF3ABD0-DDC0-4265-B778-07C66780979B}"
|
||||
@@ -698,17 +696,6 @@ Global
|
||||
{05515420-16DE-4E63-BE73-85BE85BA5142}.Release|Win32.Build.0 = Release|Win32
|
||||
{05515420-16DE-4E63-BE73-85BE85BA5142}.Release|x64.ActiveCfg = Release|x64
|
||||
{05515420-16DE-4E63-BE73-85BE85BA5142}.Release|x64.Build.0 = Release|x64
|
||||
{EEF031CB-FED8-451E-A471-91EC8D4F6750}.All|Win32.ActiveCfg = Release Dll|x64
|
||||
{EEF031CB-FED8-451E-A471-91EC8D4F6750}.All|x64.ActiveCfg = Release Dll|x64
|
||||
{EEF031CB-FED8-451E-A471-91EC8D4F6750}.All|x64.Build.0 = Release Dll|x64
|
||||
{EEF031CB-FED8-451E-A471-91EC8D4F6750}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{EEF031CB-FED8-451E-A471-91EC8D4F6750}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{EEF031CB-FED8-451E-A471-91EC8D4F6750}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{EEF031CB-FED8-451E-A471-91EC8D4F6750}.Debug|x64.Build.0 = Debug|x64
|
||||
{EEF031CB-FED8-451E-A471-91EC8D4F6750}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{EEF031CB-FED8-451E-A471-91EC8D4F6750}.Release|Win32.Build.0 = Release|Win32
|
||||
{EEF031CB-FED8-451E-A471-91EC8D4F6750}.Release|x64.ActiveCfg = Release|x64
|
||||
{EEF031CB-FED8-451E-A471-91EC8D4F6750}.Release|x64.Build.0 = Release|x64
|
||||
{F6C55D93-B927-4483-BB69-15AEF3DD2DFF}.All|Win32.ActiveCfg = Release|x64
|
||||
{F6C55D93-B927-4483-BB69-15AEF3DD2DFF}.All|x64.ActiveCfg = Release|x64
|
||||
{F6C55D93-B927-4483-BB69-15AEF3DD2DFF}.All|x64.Build.0 = Release|x64
|
||||
@@ -2133,7 +2120,6 @@ Global
|
||||
{C24FB505-05D7-4319-8485-7540B44C8603} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}
|
||||
{B5881A85-FE70-4F64-8607-2CAAE52669C6} = {E72B5BCB-6462-4D23-B419-3AF1A4AC3D78}
|
||||
{05515420-16DE-4E63-BE73-85BE85BA5142} = {9ADF1E48-2F5C-4ED7-A893-596259FABFE0}
|
||||
{EEF031CB-FED8-451E-A471-91EC8D4F6750} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B}
|
||||
{F6C55D93-B927-4483-BB69-15AEF3DD2DFF} = {EB910B0D-F27D-4B62-B67B-DE834C99AC5B}
|
||||
{0DF3ABD0-DDC0-4265-B778-07C66780979B} = {9460B5F1-0A95-41C4-BEB7-9C2C96459A7C}
|
||||
{FEA1EEF7-876F-48DE-88BF-C0E3E606D758} = {F881ADA2-2F1A-4046-9FEB-191D9422D781}
|
||||
|
||||
@@ -1536,11 +1536,6 @@ Files: src/include/switch_profile.h
|
||||
Copyright: 2009,2010, Sangoma Technologies
|
||||
License: BSD-3-clause
|
||||
|
||||
Files: libs/srtp/*
|
||||
Copyright: 2001-2006, Cisco Systems, Inc.
|
||||
2005 Ingate Systems AB
|
||||
License: BSD-3-clause
|
||||
|
||||
Files: libs/libsndfile/src/ima_oki_adpcm.h
|
||||
Copyright: 2007 <robs@users.sourceforge.net>
|
||||
2007-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
|
||||
+2
-29
@@ -114,12 +114,11 @@ install-recursive: install-libLTLIBRARIES install-binPROGRAMS
|
||||
|
||||
CORE_CFLAGS = $(AM_LIBAPR_CFLAGS) $(AM_LIBAPR_CPPFLAGS)
|
||||
CORE_CFLAGS += $(AM_LIBAPU_CPPFLAGS)
|
||||
CORE_CFLAGS += -I$(switch_srcdir)/libs/srtp/include
|
||||
CORE_CFLAGS += $(SRTP_CFLAGS)
|
||||
if ENABLE_LIBYUV
|
||||
CORE_CFLAGS += -I$(switch_srcdir)/libs/libyuv/include
|
||||
CORE_CFLAGS += -DSWITCH_HAVE_YUV
|
||||
endif
|
||||
CORE_CFLAGS += -I$(switch_srcdir)/libs/srtp/crypto/include -Ilibs/srtp/crypto/include
|
||||
CORE_CFLAGS += $(SPANDSP_CFLAGS)
|
||||
if ENABLE_LIBVPX
|
||||
CORE_CFLAGS += -DSWITCH_HAVE_VPX
|
||||
@@ -137,11 +136,6 @@ else
|
||||
CORE_LIBS += libs/apr/libapr-1.la
|
||||
endif
|
||||
|
||||
if ENABLE_SRTP
|
||||
CORE_CFLAGS += -DENABLE_SRTP
|
||||
CORE_LIBS += libs/srtp/libsrtp.la
|
||||
endif
|
||||
|
||||
MOD_LINK = $(switch_srcdir)/libfreeswitch.la
|
||||
CLEANFILES = src/include/switch_version.h src/include/switch_swigable_cpp.h
|
||||
BUILT_SOURCES = src/mod/modules.inc src/include/switch_version.h src/include/switch_swigable_cpp.h
|
||||
@@ -279,7 +273,7 @@ endif
|
||||
lib_LTLIBRARIES = libfreeswitch.la
|
||||
libfreeswitch_la_CFLAGS = $(CORE_CFLAGS) $(SQLITE_CFLAGS) $(GUMBO_CFLAGS) $(FVAD_CFLAGS) $(FREETYPE_CFLAGS) $(CURL_CFLAGS) $(PCRE2_CFLAGS) $(SPEEX_CFLAGS) $(MINIUPNPC_CFLAGS) $(LIBEDIT_CFLAGS) $(openssl_CFLAGS) $(SOFIA_SIP_CFLAGS) $(AM_CFLAGS) $(TPL_CFLAGS)
|
||||
libfreeswitch_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) $(PLATFORM_CORE_LDFLAGS) -no-undefined
|
||||
libfreeswitch_la_LIBADD = $(CORE_LIBS) $(APR_LIBS) $(SQLITE_LIBS) $(GUMBO_LIBS) $(FVAD_LIBS) $(FREETYPE_LIBS) $(CURL_LIBS) $(PCRE2_LIBS) $(SPEEX_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(LIBEDIT_LIBS) $(SYSTEMD_LIBS) $(openssl_LIBS) $(PLATFORM_CORE_LIBS) $(TPL_LIBS) $(SPANDSP_LIBS) $(SOFIA_SIP_LIBS)
|
||||
libfreeswitch_la_LIBADD = $(CORE_LIBS) $(APR_LIBS) $(SQLITE_LIBS) $(GUMBO_LIBS) $(FVAD_LIBS) $(FREETYPE_LIBS) $(CURL_LIBS) $(PCRE2_LIBS) $(SPEEX_LIBS) $(MINIUPNPC_LIBS) $(NATPMP_LIBS) $(SRTP_LIBS) $(LIBEDIT_LIBS) $(SYSTEMD_LIBS) $(openssl_LIBS) $(PLATFORM_CORE_LIBS) $(TPL_LIBS) $(SPANDSP_LIBS) $(SOFIA_SIP_LIBS)
|
||||
libfreeswitch_la_DEPENDENCIES = $(BUILT_SOURCES)
|
||||
|
||||
if HAVE_PNG
|
||||
@@ -606,21 +600,6 @@ libs/apr/Makefile: libs/apr/Makefile.in libs/apr/config.status libs/apr libs/apr
|
||||
libs/apr/libapr-1.la: libs/apr/Makefile libs/apr/.update
|
||||
@if [ $(MAKELEVEL) = 0 -o -z "`echo "$(MAKEARGS)" | grep "j"`" ] ; then touch $(switch_srcdir)/src/include/switch.h; cd libs/apr && $(MAKE) $(MFLAGS) && touch libapr-1.la; fi
|
||||
|
||||
SRTP_SRC = libs/srtp/srtp/srtp.c libs/srtp/crypto/cipher/cipher.c libs/srtp/crypto/cipher/null_cipher.c \
|
||||
libs/srtp/crypto/cipher/aes.c libs/srtp/crypto/cipher/aes_icm.c \
|
||||
libs/srtp/crypto/hash/null_auth.c libs/srtp/crypto/hash/sha1.c \
|
||||
libs/srtp/crypto/hash/hmac.c libs/srtp/crypto/hash/auth.c \
|
||||
libs/srtp/crypto/math/datatypes.c \
|
||||
libs/srtp/crypto/kernel/crypto_kernel.c libs/srtp/crypto/kernel/alloc.c \
|
||||
libs/srtp/crypto/kernel/key.c libs/srtp/crypto/kernel/err.c \
|
||||
libs/srtp/crypto/replay/rdb.c libs/srtp/crypto/replay/rdbx.c \
|
||||
libs/srtp/crypto/cipher/cipher_test_cases.c libs/srtp/crypto/hash/auth_test_cases.c
|
||||
|
||||
libs/srtp/libsrtp.la: libs/srtp libs/srtp/.update $(SRTP_SRC)
|
||||
touch $(switch_srcdir)/src/include/switch.h
|
||||
@cd libs/srtp && $(MAKE)
|
||||
@$(TOUCH_TARGET)
|
||||
|
||||
##
|
||||
## helper targets
|
||||
##
|
||||
@@ -744,7 +723,6 @@ pristine:
|
||||
|
||||
update-clean: clean python3-reconf
|
||||
cd libs/esl && $(MAKE) clean
|
||||
cd libs/srtp && $(MAKE) clean
|
||||
|
||||
swigall: src/include/switch_swigable_cpp.h
|
||||
@echo reswigging all
|
||||
@@ -764,11 +742,6 @@ reconf:
|
||||
sh ./config.status --recheck
|
||||
sh ./config.status
|
||||
|
||||
srtp-reconf:
|
||||
cd libs/srtp && $(MAKE) clean
|
||||
cd libs/srtp && sh ./config.status --recheck
|
||||
cd libs/srtp && sh ./config.status
|
||||
|
||||
cluecon:
|
||||
@clear
|
||||
@echo Thank you for updating. This is going to take a while so relax.
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ BGJOB=false
|
||||
VERBOSE=false
|
||||
BASEDIR=`pwd`;
|
||||
LIBDIR=${BASEDIR}/libs;
|
||||
SUBDIRS="apr srtp fs";
|
||||
SUBDIRS="apr fs";
|
||||
|
||||
while getopts 'jhd:v' o; do
|
||||
case "$o" in
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
# in that same directory.
|
||||
#
|
||||
#
|
||||
RPMS=git gcc-c++ autoconf automake libtool wget ncurses-devel zlib-devel libjpeg-devel openssl-devel e2fsprogs-devel sqlite-devel libcurl-devel pcre2-devel speex-devel miniupnpc-devel libnatpmp-devel ldns-devel libedit-devel
|
||||
DEBS=git build-essential automake autoconf 'libtool-bin|libtool' wget uuid-dev zlib1g-dev 'libjpeg8-dev|libjpeg62-turbo-dev' libncurses5-dev libssl-dev libpcre2-dev libcurl4-openssl-dev libldns-dev libedit-dev libspeexdsp-dev libspeexdsp-dev libsqlite3-dev libminiupnpc-dev libnatpmp-dev perl libgdbm-dev libdb-dev bison libvlc-dev pkg-config
|
||||
RPMS=git gcc-c++ autoconf automake libtool wget ncurses-devel zlib-devel libjpeg-devel openssl-devel e2fsprogs-devel sqlite-devel libcurl-devel pcre2-devel speex-devel miniupnpc-devel libnatpmp-devel libsrtp-devel ldns-devel libedit-devel
|
||||
DEBS=git build-essential automake autoconf 'libtool-bin|libtool' wget uuid-dev zlib1g-dev 'libjpeg8-dev|libjpeg62-turbo-dev' libncurses5-dev libssl-dev libpcre2-dev libcurl4-openssl-dev libldns-dev libedit-dev libspeexdsp-dev libspeexdsp-dev libsqlite3-dev libminiupnpc-dev libnatpmp-dev libsrtp2-dev perl libgdbm-dev libdb-dev bison libvlc-dev pkg-config
|
||||
|
||||
freeswitch: deps has-git freeswitch.git/Makefile
|
||||
cd freeswitch.git && make
|
||||
|
||||
+1
-8
@@ -262,8 +262,6 @@ if test "x${cross_compiling}" = "xyes"; then
|
||||
ac_cv_file__dev_ptmx=yes
|
||||
# libjs
|
||||
export ac_cv_va_copy=yes
|
||||
# srtp
|
||||
export ac_cv_file__dev_urandom=yes
|
||||
# rpl_malloc
|
||||
export ac_cv_func_realloc_0_nonnull=yes
|
||||
export ac_cv_func_malloc_0_nonnull=yes
|
||||
@@ -606,11 +604,6 @@ if test x"${LUA_LIBS}" = x"" ; then
|
||||
LUA_LIBS="-llua"
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(srtp,
|
||||
[AC_HELP_STRING([--disable-srtp],[build without srtp support])],[enable_srtp="$enableval"],[enable_srtp="yes"])
|
||||
|
||||
AM_CONDITIONAL([ENABLE_SRTP],[test "${enable_srtp}" = "yes"])
|
||||
|
||||
have_openal=no
|
||||
AC_CHECK_LIB(openal, alcLoopbackOpenDeviceSOFT, [have_openal="yes"])
|
||||
AM_CONDITIONAL([HAVE_OPENAL],[test "${have_openal}" = "yes"])
|
||||
@@ -1347,6 +1340,7 @@ PKG_CHECK_MODULES([CURL], [libcurl >= 7.19])
|
||||
PKG_CHECK_MODULES([PCRE2], [libpcre2-8 >= 10.00])
|
||||
PKG_CHECK_MODULES([SPEEX], [speex >= 1.2rc1 speexdsp >= 1.2rc1])
|
||||
PKG_CHECK_MODULES([MINIUPNPC], [miniupnpc >= 2.1])
|
||||
PKG_CHECK_MODULES([SRTP], [libsrtp2 >= 2.1.0])
|
||||
|
||||
AC_CHECK_HEADER([natpmp.h], [], [AC_MSG_ERROR([no usable libnatpmp; please install libnatpmp devel package or equivalent])])
|
||||
AC_CHECK_LIB([natpmp], [initnatpmp], [NATPMP_LIBS=-lnatpmp], [AC_MSG_ERROR([no usable libnatpmp; please install libnatpmp devel package or equivalent])])
|
||||
@@ -2272,7 +2266,6 @@ ac_configure_args="$ac_configure_args --with-modinstdir=${modulesdir} CONFIGURE_
|
||||
# --localstatedir='$localstatedir' --datadir='$datadir'"
|
||||
|
||||
# Run configure in all the subdirs
|
||||
AC_CONFIG_SUBDIRS([libs/srtp])
|
||||
if test "$use_system_apr" != "yes"; then
|
||||
AC_CONFIG_SUBDIRS([libs/apr])
|
||||
fi
|
||||
|
||||
Vendored
+1
@@ -305,6 +305,7 @@ Build-Depends:
|
||||
libtiff5-dev,
|
||||
libminiupnpc-dev (>= 2.1),
|
||||
libnatpmp-dev,
|
||||
libsrtp2-dev (>= 2.1.0),
|
||||
wget, pkg-config,
|
||||
yasm,
|
||||
# core codecs
|
||||
|
||||
Vendored
-5
@@ -1531,11 +1531,6 @@ Files: libs/libcodec2/src/pack.c
|
||||
Copyright: 2010 Perens LLC <bruce@perens.com>
|
||||
License: GPL-3+
|
||||
|
||||
Files: libs/srtp/*
|
||||
Copyright: 2001-2006, Cisco Systems, Inc.
|
||||
2005 Ingate Systems AB
|
||||
License: BSD-3-clause
|
||||
|
||||
Files: libs/libsndfile/src/ima_oki_adpcm.h
|
||||
Copyright: 2007 <robs@users.sourceforge.net>
|
||||
2007-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
|
||||
Vendored
-3
@@ -12,9 +12,6 @@ Rules:
|
||||
Glob: libs/sofia-sip/libsofia-sip-ua/su/su_md5.c
|
||||
Copyright: Nokia Corporation
|
||||
License: LGPL-2.1+
|
||||
-
|
||||
Glob: libs/srtp/update.sh
|
||||
Copyright: Ingate Systems AB
|
||||
-
|
||||
Glob: src/g711.c
|
||||
Matches: Copyright\s\(C\)\s2006\sSteve\sUnderwood
|
||||
|
||||
+1
-1
@@ -1242,7 +1242,7 @@ SEARCH_INCLUDES = YES
|
||||
|
||||
INCLUDE_PATH =../libs/apr ../libs/apr-util \
|
||||
../libs/sofia-sip ../libs/spandsp \
|
||||
../libs/srtp ../libs/win32 ../libs/xmlrpc-c
|
||||
../libs/win32 ../libs/xmlrpc-c
|
||||
|
||||
# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
|
||||
# patterns (like *.h and *.hpp) to filter out the header-files in the
|
||||
|
||||
@@ -137,6 +137,7 @@ BuildRequires: pcre2-devel
|
||||
BuildRequires: speex-devel
|
||||
BuildRequires: miniupnpc-devel >= 2.1
|
||||
BuildRequires: libnatpmp-devel
|
||||
BuildRequires: libsrtp-devel >= 2.1.0
|
||||
BuildRequires: sqlite-devel >= 3.6.20
|
||||
BuildRequires: libtiff-devel
|
||||
BuildRequires: libedit-devel
|
||||
@@ -153,6 +154,7 @@ Requires: pcre2
|
||||
Requires: speex
|
||||
Requires: miniupnpc >= 2.1
|
||||
Requires: libnatpmp
|
||||
Requires: libsrtp >= 2.1.0
|
||||
Requires: sqlite >= 3.6.20
|
||||
Requires: libtiff
|
||||
Requires: libedit
|
||||
|
||||
@@ -376,16 +376,6 @@ opal
|
||||
/sofia-sip/win32/Makefile.in
|
||||
/sounds/
|
||||
/sphinxbase-*/
|
||||
/srtp/aes_tables
|
||||
/srtp/config_in.h
|
||||
/srtp/crypto/include/config.h
|
||||
/srtp/crypto/include/stamp-h1
|
||||
/srtp/crypto/Makefile
|
||||
/srtp/doc/Makefile
|
||||
/srtp/Makefile
|
||||
/srtp/Makefile.in
|
||||
/srtp/test/Makefile
|
||||
/srtp/test/Makefile.in
|
||||
/tiff-*/build/Makefile
|
||||
/tiff-*/build/Makefile.in
|
||||
/tiff-*/tools/tiffcrop
|
||||
@@ -533,7 +523,6 @@ opal
|
||||
broadvoice/config/compile
|
||||
ilbc/config/compile
|
||||
libg722_1/config/compile
|
||||
srtp/build/compile
|
||||
/pcre-*/
|
||||
/speex-*/
|
||||
/speexdsp-*/
|
||||
@@ -545,7 +534,6 @@ srtp/build/compile
|
||||
apr/configure
|
||||
libyuv/Makefile
|
||||
libyuv/convert
|
||||
srtp/configure
|
||||
tiff-4.0.2/configure
|
||||
zlib-*/
|
||||
zlib-*
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
AccessModifierOffset: -4
|
||||
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlinesLeft: false
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
|
||||
BinPackArguments: true
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: true
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeTernaryOperators: true
|
||||
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
ContinuationIndentWidth: 4
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
|
||||
IndentCaseLabels: false
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
|
||||
MaxEmptyLinesToKeep: 1
|
||||
|
||||
PenaltyBreakBeforeFirstCallParameter: 16
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyExcessCharacter: 1000
|
||||
PenaltyReturnTypeOnItsOwnLine: 9000
|
||||
|
||||
Cpp11BracedListStyle: false
|
||||
|
||||
PointerAlignment: Right
|
||||
|
||||
ReflowComments: true
|
||||
|
||||
SortIncludes: false
|
||||
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
@@ -1,48 +0,0 @@
|
||||
# Misc crap
|
||||
*~
|
||||
old
|
||||
old?
|
||||
*.pc
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
# srtp things
|
||||
build
|
||||
Debug
|
||||
Makefile
|
||||
Root
|
||||
autom4te.cache
|
||||
config.log
|
||||
config.status
|
||||
crypto/include/config.h
|
||||
crypto/test/aes_calc
|
||||
crypto/test/cipher_driver
|
||||
crypto/test/datatypes_driver
|
||||
crypto/test/env
|
||||
crypto/test/kernel_driver
|
||||
crypto/test/sha1_driver
|
||||
crypto/test/stat_driver
|
||||
tables/aes_tables
|
||||
test/rdbx_driver
|
||||
test/replay_driver
|
||||
test/roc_driver
|
||||
test/rtp_decoder
|
||||
test/rtpw
|
||||
test/srtp_driver
|
||||
test/test_srtp
|
||||
@@ -1,462 +0,0 @@
|
||||
dist: xenial
|
||||
language: c
|
||||
|
||||
env:
|
||||
global:
|
||||
- secure: "QD09MuUxftXRXtz7ZrB7S0NV/3O9yVhjvIlCSbXN8B87rNSDC8wxMThKMT7iZewnqGk53m+Up19PiMw5ERlHose5tm2cmY1FO/l+c9oAyWZaAL+4XNXryq6zI5F5FX5I61NbfqV3xcnfLTI2QIJF6WqDojNxhPjTbNzQGxIDuqw="
|
||||
|
||||
matrix:
|
||||
include:
|
||||
|
||||
# linux build
|
||||
- os: linux
|
||||
env:
|
||||
- TEST="linux (gcc)"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- gcc-6
|
||||
- valgrind
|
||||
install:
|
||||
- pyenv global 3.7.1
|
||||
- pip3 install meson ninja
|
||||
script:
|
||||
- CC=gcc-6 EXTRA_CFLAGS=-Werror ./configure
|
||||
- make
|
||||
- make runtest
|
||||
- make runtest-valgrind
|
||||
- make distclean
|
||||
- mkdir build && cd build
|
||||
- cmake -DBUILD_WITH_SANITIZERS=TRUE ..
|
||||
- make
|
||||
- CTEST_OUTPUT_ON_FAILURE=1 make test
|
||||
- cd ..
|
||||
- CC=gcc-6 meson setup --werror builddir
|
||||
- meson compile -C builddir
|
||||
- meson test -v -C builddir
|
||||
|
||||
# linux build with openssl
|
||||
- os: linux
|
||||
env:
|
||||
- TEST="linux openssl (gcc)"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- gcc-6
|
||||
- valgrind
|
||||
install:
|
||||
- pyenv global 3.7.1
|
||||
- pip3 install meson ninja
|
||||
script:
|
||||
- CC=gcc-6 EXTRA_CFLAGS=-Werror ./configure --enable-openssl
|
||||
- make
|
||||
- make runtest
|
||||
- make runtest-valgrind
|
||||
- make distclean
|
||||
- mkdir build && cd build
|
||||
- cmake -DENABLE_OPENSSL=ON -DBUILD_WITH_SANITIZERS=TRUE ..
|
||||
- make
|
||||
- CTEST_OUTPUT_ON_FAILURE=1 make test
|
||||
- cd ..
|
||||
- mkdir build_shared && cd build_shared
|
||||
- cmake -DENABLE_OPENSSL=ON -DBUILD_SHARED_LIBS=ON ..
|
||||
- make
|
||||
- make test
|
||||
- cd ..
|
||||
- meson setup --werror -Dcrypto-library=openssl builddir
|
||||
- meson compile -C builddir
|
||||
- meson test -v -C builddir
|
||||
|
||||
# linux build with openssl and clang
|
||||
- os: linux
|
||||
env:
|
||||
- TEST="linux openssl (clang)"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang
|
||||
install:
|
||||
- pyenv global 3.7.1
|
||||
- pip3 install meson ninja
|
||||
script:
|
||||
- CC=clang EXTRA_CFLAGS=-Werror ./configure --enable-openssl
|
||||
- make
|
||||
- make runtest
|
||||
- CC=clang meson setup --werror -Dcrypto-library=openssl builddir
|
||||
- meson compile -C builddir
|
||||
- meson test -v -C builddir
|
||||
|
||||
# linux build with nss
|
||||
- os: linux
|
||||
env:
|
||||
- TEST="linux nss (gcc / valgrind)"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- gcc-6
|
||||
- valgrind
|
||||
- libnss3-dev
|
||||
install:
|
||||
- pyenv global 3.7.1
|
||||
- pip3 install meson ninja
|
||||
script:
|
||||
- CC=gcc-6 EXTRA_CFLAGS=-Werror ./configure --enable-nss
|
||||
- make
|
||||
- make runtest
|
||||
- make runtest-valgrind
|
||||
- mkdir build && cd build
|
||||
- cmake -DENABLE_NSS=ON -DBUILD_WITH_SANITIZERS=TRUE ..
|
||||
- make
|
||||
- CTEST_OUTPUT_ON_FAILURE=1 make test
|
||||
- cd ..
|
||||
- CC=gcc-6 meson setup --werror -Dcrypto-library=nss builddir
|
||||
- meson compile -C builddir
|
||||
- meson test -v -C builddir
|
||||
|
||||
# linux build with mbedtls
|
||||
- os: linux
|
||||
env:
|
||||
- TEST="linux mbedtls (gcc)"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- gcc-6
|
||||
- libmbedtls-dev
|
||||
script:
|
||||
- mkdir build && cd build
|
||||
- cmake -DENABLE_MBEDTLS=ON -DBUILD_WITH_SANITIZERS=TRUE ..
|
||||
- make
|
||||
- CTEST_OUTPUT_ON_FAILURE=1 make test
|
||||
- cd ..
|
||||
|
||||
# default osx build
|
||||
- os: osx
|
||||
env:
|
||||
- TEST="osx"
|
||||
before_install:
|
||||
- pip3 install meson ninja
|
||||
script:
|
||||
- EXTRA_CFLAGS=-Werror ./configure
|
||||
- make
|
||||
- make runtest
|
||||
- make distclean
|
||||
- mkdir build && cd build
|
||||
- cmake ..
|
||||
- make
|
||||
- make test
|
||||
- cd ..
|
||||
- meson setup --werror builddir
|
||||
- meson compile -C builddir
|
||||
- meson test -v -C builddir
|
||||
|
||||
# osx build with openssl
|
||||
- os: osx
|
||||
osx_image: xcode11.2
|
||||
env:
|
||||
- TEST="osx openssl"
|
||||
before_install:
|
||||
- pip3 install meson ninja
|
||||
- brew install openssl@1.1
|
||||
script:
|
||||
- PKG_CONFIG_PATH=$(brew --prefix openssl@1.1)/lib/pkgconfig EXTRA_CFLAGS=-Werror ./configure --enable-openssl
|
||||
- make
|
||||
- make runtest
|
||||
- make distclean
|
||||
- mkdir build && cd build
|
||||
- cmake -DOPENSSL_ROOT_DIR=$(brew --prefix openssl@1.1) -DENABLE_OPENSSL=ON ..
|
||||
- make
|
||||
- make test
|
||||
- cd ..
|
||||
- PKG_CONFIG_PATH=$(brew --prefix openssl@1.1)/lib/pkgconfig meson setup --werror -Dcrypto-library=openssl builddir
|
||||
- meson compile -C builddir
|
||||
- meson test -v -C builddir
|
||||
|
||||
# osx build with nss
|
||||
- os: osx
|
||||
osx_image: xcode11.2
|
||||
env:
|
||||
- TEST="osx nss"
|
||||
before_install:
|
||||
- pip3 install meson ninja
|
||||
script:
|
||||
- PKG_CONFIG_PATH=$(brew --prefix nss)/lib/pkgconfig EXTRA_CFLAGS=-Werror ./configure --enable-nss
|
||||
- make
|
||||
- make runtest
|
||||
- PKG_CONFIG_PATH=$(brew --prefix nss)/lib/pkgconfig meson setup --werror -Dcrypto-library=nss builddir
|
||||
- meson compile -C builddir
|
||||
- meson test -v -C builddir
|
||||
|
||||
# osx build for Apple Silicon
|
||||
- os: osx
|
||||
osx_image: xcode12u
|
||||
env:
|
||||
- TEST="osx Apple Silicon"
|
||||
script:
|
||||
- mkdir build && cd build
|
||||
- cmake "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" ..
|
||||
- make
|
||||
- lipo -info srtp_driver
|
||||
- make test
|
||||
|
||||
|
||||
# code format check
|
||||
- os: linux
|
||||
env:
|
||||
- TEST="clang-format"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-format-3.9
|
||||
script:
|
||||
- CLANG_FORMAT=clang-format-3.9 ./format.sh -d
|
||||
|
||||
# big-endian
|
||||
- os: linux
|
||||
env:
|
||||
- TEST="big-endian"
|
||||
services:
|
||||
- docker
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- qemu-user-static
|
||||
- qemu-system-mips
|
||||
before_install:
|
||||
- sudo docker run --volume $(pwd):/src --workdir /src --name mipsX --tty --detach ubuntu:16.04 tail
|
||||
- sudo docker exec --tty mipsX apt-get update
|
||||
- sudo docker exec --tty mipsX apt-get install build-essential -y
|
||||
- sudo docker exec --tty mipsX apt-get install qemu-user-static qemu-system-mips gcc-mips-linux-gnu python3-pip -y
|
||||
- sudo docker exec --tty mipsX pip3 install meson==0.56.2 ninja
|
||||
script:
|
||||
- sudo docker exec --tty mipsX bash -c 'EXTRA_CFLAGS=-static CC=mips-linux-gnu-gcc ./configure --host=mips-linux-gnu'
|
||||
- sudo docker exec --tty mipsX make
|
||||
- file test/srtp_driver
|
||||
- make runtest
|
||||
- |
|
||||
cat > mips-cross-file.txt <<EOF
|
||||
[host_machine]
|
||||
system = 'linux'
|
||||
cpu_family = 'mips'
|
||||
cpu = 'mips'
|
||||
endian = 'big'
|
||||
|
||||
[properties]
|
||||
c_args = ['-static', '-static-libgcc']
|
||||
c_link_args = ['-static', '-static-libgcc']
|
||||
|
||||
[binaries]
|
||||
ar = 'mips-linux-gnu-gcc-ar'
|
||||
c = 'mips-linux-gnu-gcc'
|
||||
ranlib = 'mips-linux-gnu-gcc-ranlib'
|
||||
exe_wrapper = 'qemu-mips-static'
|
||||
pkgconfig = 'false'
|
||||
EOF
|
||||
#- sudo docker exec --tty mipsX meson setup --cross-file mips-cross-file.txt -Ddefault_library=static -Db_staticpic=false builddir
|
||||
#- sudo docker exec --tty mipsX meson compile -C builddir
|
||||
#- sudo docker exec --tty mipsX meson test -v --timeout-multiplier 10 -C builddir
|
||||
- sudo docker kill mipsX
|
||||
|
||||
# linux build of fuzzer
|
||||
- os: linux
|
||||
env:
|
||||
- TEST="fuzzer (build only)"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang
|
||||
script:
|
||||
- CC=clang CXX=clang++ CXXFLAGS="-fsanitize=fuzzer-no-link,address,undefined -g -O3" CFLAGS="-fsanitize=fuzzer-no-link,address,undefined -g -O3" LDFLAGS="-fsanitize=fuzzer-no-link,address,undefined" ./configure
|
||||
- LIBFUZZER="-fsanitize=fuzzer" make srtp-fuzzer
|
||||
|
||||
# coverity scan
|
||||
- os: linux
|
||||
env:
|
||||
- TEST="Coverity Scan"
|
||||
addons:
|
||||
coverity_scan:
|
||||
project:
|
||||
name: "cisco-libSRTP"
|
||||
description: "Build submitted via Travis CI"
|
||||
version: 2
|
||||
notification_email: pabuhler@cisco.com
|
||||
build_command_prepend: "./configure"
|
||||
build_command: "make"
|
||||
branch_pattern: master
|
||||
script:
|
||||
- echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
|
||||
|
||||
# windows build
|
||||
- os: windows
|
||||
before_install:
|
||||
- choco install python --version 3.8.0
|
||||
- choco install ninja
|
||||
- pip3 install meson
|
||||
env:
|
||||
- TEST="windows"
|
||||
- PATH=/c/Python38:/c/Python38/Scripts:$PATH
|
||||
script:
|
||||
- export PATH="c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin":$PATH
|
||||
- mkdir build && cd build
|
||||
- cmake -G "Visual Studio 15 2017" ..
|
||||
- msbuild.exe libsrtp2.sln -p:Configuration=Release
|
||||
- msbuild.exe RUN_TESTS.vcxproj -p:Configuration=Release
|
||||
- cd ..
|
||||
- mkdir build_shared && cd build_shared
|
||||
- cmake -G "Visual Studio 15 2017" -DBUILD_SHARED_LIBS=ON ..
|
||||
- msbuild.exe libsrtp2.sln -p:Configuration=Release
|
||||
- msbuild.exe RUN_TESTS.vcxproj -p:Configuration=Release
|
||||
# Test mingw build
|
||||
- cd ..
|
||||
- meson setup builddir-gcc
|
||||
- meson compile -C builddir-gcc
|
||||
- meson test -v -C builddir-gcc
|
||||
# Test MSVC 64-bit build
|
||||
- cmd.exe //C 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat' amd64 \& set CC=cl \& meson setup --werror builddir-msvc-amd64 \& meson compile -C builddir-msvc-amd64 \& meson test -v -C builddir-msvc-amd64
|
||||
# Test MSVC 32-bit build
|
||||
- cmd.exe //C 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat' x86 \& set CC=cl \& meson setup --werror builddir-msvc-x86 \& meson compile -C builddir-msvc-x86 \& meson test -v -C builddir-msvc-x86
|
||||
# Test MSVC 64-bit UWP build. This is a cross build because we cannot run UWP binaries natively.
|
||||
- |
|
||||
cat > uwp-amd64-cross-file.txt <<EOF
|
||||
[host_machine]
|
||||
system = 'windows'
|
||||
cpu_family = 'x86_64'
|
||||
cpu = 'x86_64'
|
||||
endian = 'little'
|
||||
|
||||
[properties]
|
||||
c_args = ['-DWINAPI_FAMILY=WINAPI_FAMILY_APP']
|
||||
c_link_args = ['-APPCONTAINER', 'WindowsApp.lib']
|
||||
needs_exe_wrapper = true
|
||||
|
||||
[binaries]
|
||||
ar = 'lib'
|
||||
c = 'cl'
|
||||
cpp = 'cl'
|
||||
pkgconfig = 'false'
|
||||
EOF
|
||||
- cmd.exe //C 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat' amd64 uwp \& meson setup --werror --cross-file uwp-amd64-cross-file.txt builddir-uwp-amd64 \& meson compile -C builddir-uwp-amd64
|
||||
# Test MSVC ARM64 UWP build. This is a cross build.
|
||||
- |
|
||||
cat > uwp-arm64-cross-file.txt <<EOF
|
||||
[host_machine]
|
||||
system = 'windows'
|
||||
cpu_family = 'aarch64'
|
||||
cpu = 'aarch64'
|
||||
endian = 'little'
|
||||
|
||||
[properties]
|
||||
c_args = ['-DWINAPI_FAMILY=WINAPI_FAMILY_APP']
|
||||
c_link_args = ['-APPCONTAINER', 'WindowsApp.lib']
|
||||
needs_exe_wrapper = true
|
||||
|
||||
[binaries]
|
||||
ar = 'lib'
|
||||
c = 'cl'
|
||||
cpp = 'cl'
|
||||
pkgconfig = 'false'
|
||||
EOF
|
||||
- cmd.exe //C 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat' amd64_arm64 uwp \& meson setup --werror --cross-file uwp-arm64-cross-file.txt builddir-uwp-arm64 \& meson compile -C builddir-uwp-arm64
|
||||
|
||||
# android build
|
||||
- os: linux
|
||||
env:
|
||||
- TEST="android"
|
||||
install:
|
||||
- pyenv global 3.7.1
|
||||
- pip3 install meson ninja
|
||||
script:
|
||||
- wget -q https://dl.google.com/android/repository/android-ndk-r20b-linux-x86_64.zip
|
||||
- unzip -qq android-ndk-r20b-linux-x86_64.zip
|
||||
- ANDROID_NDK=`pwd`/android-ndk-r20b
|
||||
- mkdir build_android
|
||||
- cd build_android
|
||||
- cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a ..
|
||||
- make
|
||||
- cd ..
|
||||
- TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64
|
||||
- AR=$TOOLCHAIN/bin/aarch64-linux-android-ar
|
||||
AS=$TOOLCHAIN/bin/aarch64-linux-android-as
|
||||
CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang
|
||||
CXX=$TOOLCHAIN/bin/aarch64-linux-android21-clang++
|
||||
LD=$TOOLCHAIN/bin/aarch64-linux-android-ld
|
||||
RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib
|
||||
STRIP=$TOOLCHAIN/bin/aarch64-linux-android-strip
|
||||
./configure --host aarch64-linux-android
|
||||
- make
|
||||
- |
|
||||
cat > android-cross-file.txt <<EOF
|
||||
[host_machine]
|
||||
system = 'android'
|
||||
cpu_family = 'aarch64'
|
||||
cpu = 'aarch64'
|
||||
endian = 'little'
|
||||
|
||||
[properties]
|
||||
sys_root = '$ANDROID_NDK/sysroot'
|
||||
|
||||
[binaries]
|
||||
ar = '$TOOLCHAIN/bin/aarch64-linux-android-ar'
|
||||
c = '$TOOLCHAIN/bin/aarch64-linux-android21-clang'
|
||||
cpp = '$TOOLCHAIN/bin/aarch64-linux-android21-clang++'
|
||||
ranlib = '$TOOLCHAIN/bin/aarch64-linux-android-ranlib'
|
||||
strip = '$TOOLCHAIN/bin/aarch64-linux-android-strip'
|
||||
pkgconfig = 'false'
|
||||
EOF
|
||||
- meson setup --werror --cross-file android-cross-file.txt builddir
|
||||
- meson compile -C builddir
|
||||
|
||||
# ios build
|
||||
- os: osx
|
||||
osx_image: xcode11.2
|
||||
env:
|
||||
- TEST="ios"
|
||||
before_install:
|
||||
- pip3 install meson ninja
|
||||
script:
|
||||
- wget -q https://raw.githubusercontent.com/leetal/ios-cmake/master/ios.toolchain.cmake
|
||||
- mkdir build && cd build
|
||||
- cmake -DCMAKE_TOOLCHAIN_FILE=../ios.toolchain.cmake -DPLATFORM=OS64 ..
|
||||
- make
|
||||
- cd ..
|
||||
- CFLAGS="-arch arm64 --sysroot=$(xcrun --sdk iphoneos --show-sdk-path) -miphoneos-version-min=8.0 -fembed-bitcode"
|
||||
LDFLAGS="-arch arm64 --sysroot=$(xcrun --sdk iphoneos --show-sdk-path) -miphoneos-version-min=8.0 -fembed-bitcode"
|
||||
AR="$(xcrun --find --sdk iphoneos ar)"
|
||||
AS="$(xcrun --find --sdk iphoneos as)"
|
||||
CC="$(xcrun --find --sdk iphoneos clang)"
|
||||
CXX="$(xcrun --find --sdk iphoneos clang++)"
|
||||
LD="$(xcrun --find --sdk iphoneos ld)"
|
||||
RANLIB="$(xcrun --find --sdk iphoneos ranlib)"
|
||||
STRIP="$(xcrun --find --sdk iphoneos strip)"
|
||||
./configure --host arm-apple-darwin
|
||||
- make
|
||||
- make shared_library
|
||||
- |
|
||||
cat > ios-cross-file.txt <<EOF
|
||||
[host_machine]
|
||||
system = 'darwin'
|
||||
cpu_family = 'aarch64'
|
||||
cpu = 'aarch64'
|
||||
endian = 'little'
|
||||
|
||||
[properties]
|
||||
c_args = ['-arch', 'arm64', '--sysroot=$(xcrun --sdk iphoneos --show-sdk-path)', '-miphoneos-version-min=8.0']
|
||||
c_link_args = ['-arch', 'arm64', '--sysroot=$(xcrun --sdk iphoneos --show-sdk-path)', '-miphoneos-version-min=8.0']
|
||||
|
||||
[binaries]
|
||||
ar = '$(xcrun --find --sdk iphoneos ar)'
|
||||
c = '$(xcrun --find --sdk iphoneos clang)'
|
||||
cpp = '$(xcrun --find --sdk iphoneos clang++)'
|
||||
ranlib = '$(xcrun --find --sdk iphoneos ranlib)'
|
||||
strip = '$(xcrun --find --sdk iphoneos strip)'
|
||||
pkgconfig = 'false'
|
||||
EOF
|
||||
- meson setup --werror -Db_bitcode=true --cross-file ios-cross-file.txt builddir
|
||||
- meson compile -C builddir
|
||||
@@ -1 +0,0 @@
|
||||
Fri Apr 26 00:00:02 CDT 2019
|
||||
@@ -1,4 +0,0 @@
|
||||
David A. McGrew
|
||||
Cisco Systems, Inc.
|
||||
mcgrew@cisco.com
|
||||
|
||||
@@ -1,311 +0,0 @@
|
||||
Changelog
|
||||
|
||||
2.4.0
|
||||
|
||||
Major changes
|
||||
|
||||
#529 - Remove EKT files, this was never completed and the draft has since changed.
|
||||
|
||||
#512 - Adds suport for Mbedtls as a crypto backend.
|
||||
|
||||
#503 - Support apple silicon build.
|
||||
|
||||
#495 - Adds support for the Meson build system. This is an alternative to Cmake and auto tools.
|
||||
|
||||
Other changes
|
||||
|
||||
#546 - Improve OpenSSL KDF check.
|
||||
|
||||
#542 - Add void to function declarations for EVP_EncryptInit check.
|
||||
|
||||
#531 - Remove dead code.
|
||||
|
||||
#524 - Support running against nss >= 3.52.
|
||||
|
||||
#521 - Remove references to dtls from libsrtp.
|
||||
|
||||
#520 - Use nss based hmac when nss enabled.
|
||||
|
||||
#519 - Move selftest vectors form backends to common files.
|
||||
|
||||
#515 - Extend cmake support.
|
||||
|
||||
#514 - Fix gcc11 warning by defining output length.
|
||||
|
||||
#502 - Remove visual studio build files.
|
||||
|
||||
#501 - cmake: Set the VERSION property of the srtp2 library.
|
||||
|
||||
#500 - Fixed issue #499 with buffer overflow.
|
||||
|
||||
#498 - Feature/additional error checks.
|
||||
|
||||
#496 - Rework check for OPENSSL_cleanse().
|
||||
|
||||
#492 - Avoid non-existing compiler flag -O4.
|
||||
|
||||
#491 - Fix two-byte RTP header extension encryption.
|
||||
|
||||
#478 - Modify cmake to install crypto_types.h instead of cipher_types.h
|
||||
|
||||
2.3.0
|
||||
|
||||
Major changes
|
||||
|
||||
A fuzzer was added to the project based on libFuzzer. This is run as part of Google oss-fuzz, the current status can be found at https://oss-fuzz-build-logs.storage.googleapis.com/index.html#libsrtp . Details available in PR #442 and issue #393.
|
||||
|
||||
CMake support was added as an alternative build system. This was primarily added to replace the Visual Studio project files currently checked in but has been extend to support building on all platforms. Initial PR #449 and #455 but has been support has been continuously improved.
|
||||
|
||||
NSS support for crypto backend was added. This is can be used as an alternative to openssl. Initial PR #413 but there has been numerous improvements.
|
||||
|
||||
Other changes
|
||||
|
||||
PR #474 - Add flag to disable pcap dependency when build test apps.
|
||||
|
||||
PR #472 - Add ci builds for ios and android.
|
||||
|
||||
PR #463 - problem on srtp_aes_icm_openssl_encrypt.
|
||||
|
||||
PR #471 - Allow the pcap file to be read from a physical file.
|
||||
|
||||
PR #457 - Fix docs crypto_policy_* -> srtp_crypto_policy_* .
|
||||
|
||||
PR #452 - crypto/cipher: Reset the EVP_CIPHER_CTX structure before each test.
|
||||
|
||||
PR #444 - Extend rtp_ecoder to support RTCP and multiplexed SSRC's.
|
||||
|
||||
PR #443 - rtp_decoder avoid crash when no packets found.
|
||||
|
||||
PR #429 - Rand for test only.
|
||||
|
||||
PR #421 - Fix GCM IV logging.
|
||||
|
||||
PR #415 - Fixes unaligned trailer access.
|
||||
|
||||
PR #414 - Detect and handle broken "OPENSSL_cleanse".
|
||||
|
||||
2.2.0
|
||||
|
||||
Major changes
|
||||
|
||||
All code has been reformatted to be consistent. A .clang-format file and format.sh script has been added that can be use to verify and enforce consistent formatting. An automated check on code formatting is now part of travis build.
|
||||
|
||||
Other changes
|
||||
|
||||
PR #409 - Compatibilty with LibreSSL
|
||||
|
||||
PR #406 - Fix unprotect when pktlen < (2*mki_size + tag_len)
|
||||
|
||||
PR #405 - Prevent potential double free
|
||||
|
||||
PR #404 - Add back extern to global variables
|
||||
|
||||
PR #403 - Set gcm IV directly with EVP_CipherInit_ex
|
||||
|
||||
PR #401 - Fix memory access issue in srtp_get_session_keys()
|
||||
|
||||
PR #398 - Fix memory access fixes when invalid profiles where used
|
||||
|
||||
PR #391 - Return NULL when allocating memory of size zero
|
||||
|
||||
PR #390 - Bitvector of length zero is not valid
|
||||
|
||||
PR #385 - Treat warnings as errors on travis builds
|
||||
|
||||
PR #388 - Moved externs from crypto_kernel into its own header
|
||||
|
||||
PR #379 - Fixed several compiler warnings from Firefox builds
|
||||
|
||||
PR #377 - Removed variable init code in rdbx which never gets used
|
||||
|
||||
PR #381 - Added error in case the platform is not detected
|
||||
|
||||
PR #376 - Add coverity scan to travis builds
|
||||
|
||||
PR #374 - Add a big endian build on travis
|
||||
|
||||
PR #373 - Fixed buffer size issue in test/srtp_driver.c
|
||||
|
||||
PR #372 - Make rtp_decoder compile on MinGW
|
||||
|
||||
PR #367 - Rename configure.in to configure.ac
|
||||
|
||||
PR #365 - Replace calls to free() with srtp_crypto_free()
|
||||
|
||||
PR #364 - Add valgrind to travis and fix leaks in tests
|
||||
|
||||
PR #363 - Change smtp_crypto_alloc to initialize memory to zero
|
||||
|
||||
PR #354 - Fix potential leak if cloning of stream fails
|
||||
|
||||
PR #340 - Fix potential leak in srtp_add_stream()
|
||||
|
||||
PR #323 - Fix running test in out of source builds
|
||||
|
||||
Issue #316 - Remove VERSION file
|
||||
|
||||
2.1.0
|
||||
|
||||
Compatibility changes
|
||||
|
||||
PR #253 - Cipher type cleanup for AES
|
||||
When libSRTP is compiled with OpenSSL and the AES 256 ICM cipher is used
|
||||
with RTCP an incorrect initialization vector is formed.
|
||||
This change will break backwards compatibility with older versions (1.5,
|
||||
2.0) of libSRTP when using the AES 256 ICM cipher with OpenSSL for RTCP.
|
||||
|
||||
PR #259 - Sequence number incorrectly masked for AES GCM IV
|
||||
The initialization vector for AES GCM encryption was incorrectly formed on
|
||||
little endian machines.
|
||||
This change will break backwards compatibility with older versions (1.5,
|
||||
2.0) of libSRTP when using the AES GCM cipher for RTCP.
|
||||
|
||||
PR #287 - Fix OOB read in key generation for encrypted headers with GCM ciphers
|
||||
Adds padding of GCM salt to the corresponding ICM length used for header
|
||||
encryption.
|
||||
This change will break backwards compatibility with version 2.0 of libSRTP
|
||||
when using the header encryption extension with the AES GCM cipher.
|
||||
|
||||
Major changes
|
||||
|
||||
PR #204 - OpenSSL performance improvements
|
||||
Changed key expansion to occur once per key instead of once per packet.
|
||||
|
||||
PR #209 - Restore AES-192 under BoringSSL
|
||||
BoringSSL supports AES-192 and is now enabled in libSRTP.
|
||||
|
||||
PR #224 - Master Key Identifiers (MKI) Support patch
|
||||
Adds MKI support with up to 4 keys.
|
||||
|
||||
PR #234 - Report SSRC instead of srtp_stream_t in srtp_event_data_t
|
||||
srtp_stream_t is an opaque type making the event framework almost useless.
|
||||
Now the SSRC is returned instead for use as a key in the public API.
|
||||
|
||||
PR #238 - Configure changes and improvements
|
||||
CFLAGS check more shell neutral, quotation fixes, always generate and
|
||||
install pkg-config file, improved OpenSSL discovery and linking, remove
|
||||
-fPIC flag on Windows, fix shared library generation under Cygwin, replace
|
||||
hardcoded CFLAGS with compiler checks, and regenerate configure after
|
||||
configure.in changes.
|
||||
|
||||
PR #241 & PR #261 - Improved logging API to receive log messages from libSRTP
|
||||
Provides a logging API and the ability to enable logging to stdout and a
|
||||
file, as well as a switch to enable all internal debug modules.
|
||||
|
||||
PR #289 - Added support for set and get the roll-over-counter
|
||||
Adds an API to set and get the ROC in an (S)RTP session.
|
||||
|
||||
PR #304 - Fix (S)RTP and (S)RTCP for big endian machines
|
||||
The structures srtp_hdr_t, srtcp_hdr_t and srtcp_trailer_t were defined
|
||||
incorrectly on big endian systems.
|
||||
|
||||
Other changes
|
||||
|
||||
PR #149 - Don't create a symlink if there is no $(SHAREDLIBVERSION)
|
||||
|
||||
PR #151 - Make srtp_driver compile for MIPS
|
||||
|
||||
PR #160 - Use PKG_PROG_PKG_CONFIG to find correct pkg-config
|
||||
|
||||
PR #167 - Additional RTCP and SRTCP tests
|
||||
|
||||
PR #169 - Identified merge conflict created by commit 6b71fb9
|
||||
|
||||
PR #173 - Avoid error 'possibly undefined macro: AM_PROG_AR'
|
||||
|
||||
PR #174 - Avoid warning 'The macro AC_TRY_LINK is obsolete.'
|
||||
|
||||
PR #175 - Remove 2nd -fPIC
|
||||
|
||||
PR #182 - Add a length check before reading packet data
|
||||
|
||||
PR #191 - On debug, output correct endianness of SSRC
|
||||
|
||||
PR #192 - Replace octet_string_is_eq with a constant-time implementation
|
||||
|
||||
PR #195 - Add missing __cplusplus header guards
|
||||
|
||||
PR #198 - Update sha1_driver.c to avoid memory leaks
|
||||
|
||||
PR #202 - Add an explicit cast to avoid a printf format warning on macOS
|
||||
|
||||
PR #205 - Update Windows build files to Visual Studio 2015
|
||||
|
||||
PR #207 - Fix to install-win.bat syntax, and add installation of x64 libraries
|
||||
|
||||
PR #208 - Make replace_cipher and replace_auth public again
|
||||
|
||||
PR #211 - Changes for OpenSSL 1.1.0 compatibility
|
||||
|
||||
PR #213 - Add cast to `unsigned int` in call to printf in test
|
||||
|
||||
PR #214 - Avoid empty initializer braces
|
||||
|
||||
PR #222 - Fix issue: No consistency when use some srtp_* functions
|
||||
|
||||
PR #231 - Advance version on master in preparation for 2.1 release
|
||||
|
||||
PR #232 - Update Travis, do not build with OpenSSL on OSX
|
||||
|
||||
PR #233 - crypto/replay/rdbx.c: Return type of srtp_index_guess from int to
|
||||
int32_t
|
||||
|
||||
PR #236 - test/rtp_decoder.c: Removed superfluous conditional
|
||||
|
||||
PR #237 - test/rtp_decoder.c: spring cleaning
|
||||
|
||||
PR #239 - octet_string_set_to_zero() delegates to OPENSSL_cleanse() if
|
||||
available, if not it will use srtp_cleanse() to zero memory
|
||||
|
||||
PR #243 - EKT is not really supported yet, remove from install
|
||||
|
||||
PR #244 - Add simple error checking in timing test to avoid false results
|
||||
|
||||
PR #245 - Add missing srtp_cipher_dealloc calls when test fails
|
||||
|
||||
PR #246 - test/rtp_decoder: Add missing conditional
|
||||
|
||||
PR #248 - New README.md that integrates intro, credits and references from
|
||||
/doc/ and is used to generate documentation
|
||||
|
||||
PR #249 - Remove support for generic aesicm from configure.in
|
||||
|
||||
PR #250 - Update README.md, incorrect tag for link
|
||||
|
||||
PR #255 - Cleanup outdated comment related to MKI
|
||||
|
||||
PR #258 - Add AES-GCM to DTLS-SRTP Protection Profiles
|
||||
|
||||
PR #263 - Cleaning up and removing duplicated and outdated code
|
||||
|
||||
PR #265 - Introduction of unit test framework: CUTest
|
||||
|
||||
PR #267 - crypto/kernel/err.c: Include datatypes.h
|
||||
|
||||
PR #272 - Reduce literal constants
|
||||
|
||||
PR #273 - SRTP AEAD SRTCP initialization vector regression tests
|
||||
|
||||
PR #274 - Update Travis build - add ccache
|
||||
|
||||
PR #276 - Reference and docs updates
|
||||
|
||||
PR #278 - Removed crypto/test/auth_driver.c and test/lfsr.c
|
||||
|
||||
PR #279 - Bump copyright year
|
||||
|
||||
PR #283 - Add missing docs in srtp.h
|
||||
|
||||
PR #284 - Add strict-prototypes warning if supported
|
||||
|
||||
PR #291 - Use const char * for srtp_set_debug_module()
|
||||
|
||||
PR #294 - Fix incorrect result of rdb_increment on overflow
|
||||
|
||||
PR #300 - Standalone tests
|
||||
|
||||
PR #301 - Configure fixes
|
||||
|
||||
PR #302 - Fix warning regarding unused variable
|
||||
|
||||
PR #303 - Makefile.in: Add gnu as match for shared lib suffix
|
||||
@@ -1,348 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
|
||||
project(libsrtp2 VERSION 2.4.0 LANGUAGES C)
|
||||
|
||||
set(PACKAGE_VERSION ${CMAKE_PROJECT_VERSION})
|
||||
set(PACKAGE_STRING "${CMAKE_PROJECT_NAME} ${CMAKE_PROJECT_VERSION}")
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
include(TestBigEndian)
|
||||
include(CheckIncludeFile)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckTypeSize)
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
test_big_endian(WORDS_BIGENDIAN)
|
||||
|
||||
if (NOT APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
|
||||
set (HAVE_X86 TRUE)
|
||||
else ()
|
||||
set (HAVE_X86 FALSE)
|
||||
endif ()
|
||||
|
||||
check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
|
||||
check_include_file(byteswap.h HAVE_BYTESWAP_H)
|
||||
check_include_file(inttypes.h HAVE_INTTYPES_H)
|
||||
check_include_file(machine/types.h HAVE_MACHINE_TYPES_H)
|
||||
check_include_file(netinet/in.h HAVE_NETINET_IN_H)
|
||||
check_include_file(stdint.h HAVE_STDINT_H)
|
||||
check_include_file(stdlib.h HAVE_STDLIB_H)
|
||||
check_include_file(sys/int_types.h HAVE_SYS_INT_TYPES_H)
|
||||
check_include_file(sys/socket.h HAVE_SYS_SOCKET_H)
|
||||
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
|
||||
check_include_file(unistd.h HAVE_UNISTD_H)
|
||||
check_include_file(windows.h HAVE_WINDOWS_H)
|
||||
check_include_file(winsock2.h HAVE_WINSOCK2_H)
|
||||
|
||||
check_function_exists(sigaction HAVE_SIGACTION)
|
||||
check_function_exists(inet_aton HAVE_INET_ATON)
|
||||
check_function_exists(usleep HAVE_USLEEP)
|
||||
|
||||
check_type_size(uint8_t UINT8_T)
|
||||
check_type_size(uint16_t UINT16_T)
|
||||
check_type_size(uint32_t UINT32_T)
|
||||
check_type_size(uint64_t UINT64_T)
|
||||
check_type_size(int32_t INT32_T)
|
||||
check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG)
|
||||
check_type_size("unsigned long long" SIZEOF_UNSIGNED_LONG_LONG)
|
||||
|
||||
check_c_source_compiles("inline void func(); void func() { } int main() { func(); return 0; }" HAVE_INLINE)
|
||||
if(NOT HAVE_INLINE)
|
||||
check_c_source_compiles("__inline void func(); void func() { } int main() { func(); return 0; }" HAVE___INLINE)
|
||||
endif()
|
||||
|
||||
set(ENABLE_DEBUG_LOGGING OFF CACHE BOOL "Enable debug logging in all modules")
|
||||
set(ERR_REPORTING_STDOUT OFF CACHE BOOL "Enable logging to stdout")
|
||||
set(ERR_REPORTING_FILE "" CACHE FILEPATH "Use file for logging")
|
||||
set(ENABLE_OPENSSL OFF CACHE BOOL "Enable OpenSSL crypto engine")
|
||||
set(ENABLE_MBEDTLS OFF CACHE BOOL "Enable MbedTLS crypto engine")
|
||||
set(ENABLE_NSS OFF CACHE BOOL "Enable NSS crypto engine")
|
||||
set(TEST_APPS ON CACHE BOOL "Build test applications")
|
||||
set(BUILD_WITH_SANITIZERS OFF CACHE BOOL "Adds sanitizer flags to compiler")
|
||||
option(BUILD_SHARED_LIBS "Build shared library" OFF)
|
||||
|
||||
if(ENABLE_OPENSSL OR ENABLE_MBEDTLS OR ENABLE_NSS)
|
||||
set(USE_EXTERNAL_CRYPTO TRUE)
|
||||
else()
|
||||
set(USE_EXTERNAL_CRYPTO FALSE)
|
||||
endif()
|
||||
|
||||
if(ENABLE_OPENSSL)
|
||||
if(ENABLE_NSS OR ENABLE_MBEDTLS)
|
||||
message(FATAL_ERROR "ssl conflict. can not enable openssl and mbedtls or nss simultaneously.")
|
||||
endif()
|
||||
find_package(OpenSSL REQUIRED)
|
||||
set(OPENSSL ${ENABLE_OPENSSL} CACHE BOOL INTERNAL)
|
||||
set(GCM ${ENABLE_OPENSSL} CACHE BOOL INTERNAL)
|
||||
endif()
|
||||
|
||||
if(ENABLE_MBEDTLS)
|
||||
if(ENABLE_OPENSSL OR ENABLE_NSS)
|
||||
message(FATAL_ERROR "ssl conflict. can not enable mbedtls and openssl or nss simultaneously.")
|
||||
endif()
|
||||
find_package(MbedTLS REQUIRED)
|
||||
set(MBEDTLS ${ENABLE_MBEDTLS} CACHE BOOL INTERNAL)
|
||||
set(GCM ${ENABLE_MBEDTLS} CACHE BOOL INTERNAL)
|
||||
endif()
|
||||
|
||||
if(ENABLE_NSS)
|
||||
if(ENABLE_OPENSSL OR ENABLE_MBEDTLS)
|
||||
message(FATAL_ERROR "ssl conflict. can not enable nss and openssl or mbedtls simultaneously.")
|
||||
endif()
|
||||
find_package(NSS REQUIRED)
|
||||
set(NSS ${ENABLE_NSS} CACHE BOOL INTERNAL)
|
||||
set(GCM ${ENABLE_NSS} CACHE BOOL INTERNAL)
|
||||
endif()
|
||||
|
||||
set(CONFIG_FILE_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
||||
include_directories(${CONFIG_FILE_DIR})
|
||||
|
||||
configure_file(config_in_cmake.h ${CONFIG_FILE_DIR}/config.h)
|
||||
add_definitions(-DHAVE_CONFIG_H)
|
||||
|
||||
if(BUILD_WITH_SANITIZERS AND NOT WIN32)
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
set(SANITIZERS address,undefined)
|
||||
else()
|
||||
set(SANITIZERS leak,address,undefined)
|
||||
endif()
|
||||
message(STATUS "Using sanitizers: ${SANITIZERS}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=${SANITIZERS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=${SANITIZERS}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=${SANITIZERS}")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=${SANITIZERS}")
|
||||
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=${SANITIZERS}")
|
||||
endif()
|
||||
|
||||
set(SOURCES_C
|
||||
srtp/srtp.c
|
||||
)
|
||||
|
||||
set(CIPHERS_SOURCES_C
|
||||
crypto/cipher/cipher.c
|
||||
crypto/cipher/cipher_test_cases.c
|
||||
crypto/cipher/cipher_test_cases.h
|
||||
crypto/cipher/null_cipher.c
|
||||
)
|
||||
|
||||
if(ENABLE_OPENSSL)
|
||||
list(APPEND CIPHERS_SOURCES_C
|
||||
crypto/cipher/aes_icm_ossl.c
|
||||
crypto/cipher/aes_gcm_ossl.c
|
||||
)
|
||||
elseif(ENABLE_MBEDTLS)
|
||||
list(APPEND CIPHERS_SOURCES_C
|
||||
crypto/cipher/aes_icm_mbedtls.c
|
||||
crypto/cipher/aes_gcm_mbedtls.c
|
||||
)
|
||||
elseif(ENABLE_NSS)
|
||||
list(APPEND CIPHERS_SOURCES_C
|
||||
crypto/cipher/aes_icm_nss.c
|
||||
crypto/cipher/aes_gcm_nss.c
|
||||
)
|
||||
else()
|
||||
list(APPEND CIPHERS_SOURCES_C
|
||||
crypto/cipher/aes.c
|
||||
crypto/cipher/aes_icm.c
|
||||
)
|
||||
endif()
|
||||
|
||||
set(HASHES_SOURCES_C
|
||||
crypto/hash/auth.c
|
||||
crypto/hash/auth_test_cases.c
|
||||
crypto/hash/auth_test_cases.h
|
||||
crypto/hash/null_auth.c
|
||||
)
|
||||
|
||||
if(ENABLE_OPENSSL)
|
||||
list(APPEND HASHES_SOURCES_C
|
||||
crypto/hash/hmac_ossl.c
|
||||
)
|
||||
elseif(ENABLE_MBEDTLS)
|
||||
list(APPEND HASHES_SOURCES_C
|
||||
crypto/hash/hmac_mbedtls.c
|
||||
)
|
||||
elseif(ENABLE_NSS)
|
||||
list(APPEND HASHES_SOURCES_C
|
||||
crypto/hash/hmac_nss.c
|
||||
)
|
||||
else()
|
||||
list(APPEND HASHES_SOURCES_C
|
||||
crypto/hash/hmac.c
|
||||
crypto/hash/sha1.c
|
||||
)
|
||||
endif()
|
||||
|
||||
set(KERNEL_SOURCES_C
|
||||
crypto/kernel/alloc.c
|
||||
crypto/kernel/crypto_kernel.c
|
||||
crypto/kernel/err.c
|
||||
crypto/kernel/key.c
|
||||
)
|
||||
|
||||
set(MATH_SOURCES_C
|
||||
crypto/math/datatypes.c
|
||||
)
|
||||
|
||||
set(REPLAY_SOURCES_C
|
||||
crypto/replay/rdb.c
|
||||
crypto/replay/rdbx.c
|
||||
)
|
||||
|
||||
set(SOURCES_H
|
||||
crypto/include/aes.h
|
||||
crypto/include/aes_icm.h
|
||||
crypto/include/alloc.h
|
||||
crypto/include/auth.h
|
||||
crypto/include/cipher.h
|
||||
crypto/include/cipher_types.h
|
||||
crypto/include/crypto_kernel.h
|
||||
crypto/include/crypto_types.h
|
||||
crypto/include/datatypes.h
|
||||
crypto/include/err.h
|
||||
crypto/include/hmac.h
|
||||
crypto/include/integers.h
|
||||
crypto/include/key.h
|
||||
crypto/include/null_auth.h
|
||||
crypto/include/null_cipher.h
|
||||
crypto/include/rdb.h
|
||||
crypto/include/rdbx.h
|
||||
crypto/include/sha1.h
|
||||
include/srtp.h
|
||||
include/srtp_priv.h
|
||||
${CONFIG_FILE_DIR}/config.h
|
||||
)
|
||||
|
||||
if(BUILD_SHARED_LIBS AND WIN32)
|
||||
list(APPEND SOURCES_C
|
||||
srtp.def
|
||||
)
|
||||
endif()
|
||||
|
||||
source_group("src" FILES ${SOURCES_C})
|
||||
source_group("src\\Ciphers" FILES ${CIPHERS_SOURCES_C})
|
||||
source_group("src\\Hashes" FILES ${HASHES_SOURCES_C})
|
||||
source_group("src\\Kernel" FILES ${KERNEL_SOURCES_C})
|
||||
source_group("src\\Math" FILES ${MATH_SOURCES_C})
|
||||
source_group("src\\Replay" FILES ${REPLAY_SOURCES_C})
|
||||
source_group("include" FILES ${SOURCES_H})
|
||||
|
||||
add_library(srtp2
|
||||
${SOURCES_C}
|
||||
${CIPHERS_SOURCES_C}
|
||||
${HASHES_SOURCES_C}
|
||||
${KERNEL_SOURCES_C}
|
||||
${MATH_SOURCES_C}
|
||||
${REPLAY_SOURCES_C}
|
||||
${SOURCES_H}
|
||||
)
|
||||
|
||||
set_target_properties(srtp2 PROPERTIES VERSION ${CMAKE_PROJECT_VERSION})
|
||||
|
||||
target_include_directories(srtp2 PUBLIC crypto/include include)
|
||||
if(ENABLE_OPENSSL)
|
||||
target_include_directories(srtp2 PRIVATE ${OPENSSL_INCLUDE_DIR})
|
||||
target_link_libraries(srtp2 OpenSSL::Crypto)
|
||||
elseif(ENABLE_MBEDTLS)
|
||||
target_include_directories(srtp2 PRIVATE ${MBEDTLS_INCLUDE_DIRS})
|
||||
target_link_libraries(srtp2 ${MBEDTLS_LIBRARIES})
|
||||
elseif(ENABLE_NSS)
|
||||
target_include_directories(srtp2 PRIVATE ${NSS_INCLUDE_DIRS})
|
||||
target_link_libraries(srtp2 ${NSS_LIBRARIES})
|
||||
endif()
|
||||
if(WIN32)
|
||||
target_link_libraries(srtp2 ws2_32)
|
||||
target_compile_definitions(srtp2 PUBLIC _CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
install(TARGETS srtp2 DESTINATION lib)
|
||||
install(FILES include/srtp.h crypto/include/auth.h
|
||||
crypto/include/cipher.h
|
||||
crypto/include/crypto_types.h
|
||||
DESTINATION include/srtp2)
|
||||
|
||||
if(TEST_APPS)
|
||||
enable_testing()
|
||||
|
||||
if(NOT (BUILD_SHARED_LIBS AND WIN32))
|
||||
if(NOT USE_EXTERNAL_CRYPTO)
|
||||
add_executable(aes_calc crypto/test/aes_calc.c test/getopt_s.c test/util.c)
|
||||
target_include_directories(aes_calc PRIVATE test)
|
||||
target_link_libraries(aes_calc srtp2)
|
||||
add_test(aes_calc_128 aes_calc 000102030405060708090a0b0c0d0e0f
|
||||
00112233445566778899aabbccddeeff
|
||||
69c4e0d86a7b0430d8cdb78070b4c55a)
|
||||
add_test(aes_calc_256 aes_calc 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
|
||||
00112233445566778899aabbccddeeff
|
||||
8ea2b7ca516745bfeafc49904b496089)
|
||||
|
||||
add_executable(sha1_driver crypto/test/sha1_driver.c test/util.c)
|
||||
target_include_directories(sha1_driver PRIVATE test)
|
||||
target_link_libraries(sha1_driver srtp2)
|
||||
add_test(sha1_driver sha1_driver -v)
|
||||
endif()
|
||||
|
||||
add_executable(datatypes_driver crypto/test/datatypes_driver.c test/util.c)
|
||||
target_include_directories(datatypes_driver PRIVATE test)
|
||||
target_link_libraries(datatypes_driver srtp2)
|
||||
add_test(datatypes_driver datatypes_driver -v)
|
||||
|
||||
add_executable(cipher_driver crypto/test/cipher_driver.c test/getopt_s.c)
|
||||
target_include_directories(cipher_driver PRIVATE test)
|
||||
target_link_libraries(cipher_driver srtp2)
|
||||
add_test(cipher_driver cipher_driver -v)
|
||||
|
||||
add_executable(kernel_driver crypto/test/kernel_driver.c test/getopt_s.c)
|
||||
target_include_directories(kernel_driver PRIVATE test)
|
||||
target_link_libraries(kernel_driver srtp2)
|
||||
add_test(kernel_driver kernel_driver -v)
|
||||
|
||||
add_executable(rdbx_driver test/rdbx_driver.c test/getopt_s.c test/ut_sim.c)
|
||||
target_include_directories(rdbx_driver PRIVATE test)
|
||||
target_link_libraries(rdbx_driver srtp2)
|
||||
add_test(rdbx_driver rdbx_driver -v)
|
||||
|
||||
add_executable(replay_driver test/replay_driver.c test/ut_sim.c)
|
||||
target_include_directories(replay_driver PRIVATE test)
|
||||
target_link_libraries(replay_driver srtp2)
|
||||
add_test(replay_driver replay_driver -v)
|
||||
|
||||
add_executable(roc_driver test/roc_driver.c test/ut_sim.c)
|
||||
target_include_directories(roc_driver PRIVATE test)
|
||||
target_link_libraries(roc_driver srtp2)
|
||||
add_test(roc_driver roc_driver -v)
|
||||
endif()
|
||||
|
||||
add_executable(srtp_driver test/srtp_driver.c
|
||||
test/util.c test/getopt_s.c)
|
||||
target_link_libraries(srtp_driver srtp2)
|
||||
add_test(srtp_driver srtp_driver -v)
|
||||
|
||||
if(NOT (BUILD_SHARED_LIBS AND WIN32))
|
||||
add_executable(test_srtp test/test_srtp.c)
|
||||
if(ENABLE_OPENSSL)
|
||||
target_include_directories(test_srtp PRIVATE ${OPENSSL_INCLUDE_DIR})
|
||||
elseif(ENABLE_MBEDTLS)
|
||||
target_include_directories(test_srtp PRIVATE ${MBEDTLS_INCLUDE_DIRS})
|
||||
elseif(ENABLE_NSS)
|
||||
target_include_directories(test_srtp PRIVATE ${NSS_INCLUDE_DIRS})
|
||||
endif()
|
||||
target_link_libraries(test_srtp srtp2)
|
||||
add_test(test_srtp test_srtp)
|
||||
endif()
|
||||
|
||||
find_program(BASH_PROGRAM bash)
|
||||
if(BASH_PROGRAM AND NOT WIN32)
|
||||
add_executable(rtpw test/rtpw.c test/rtp.c test/util.c test/getopt_s.c)
|
||||
target_link_libraries(rtpw srtp2)
|
||||
add_test(NAME rtpw_test
|
||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test/rtpw_test.sh -w ${CMAKE_CURRENT_SOURCE_DIR}/test/words.txt
|
||||
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
if(GCM)
|
||||
add_test(NAME rtpw_test_gcm
|
||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test/rtpw_test_gcm.sh -w ${CMAKE_CURRENT_SOURCE_DIR}/test/words.txt
|
||||
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
@@ -1,3 +0,0 @@
|
||||
# Meson build file maintainers
|
||||
meson.build @nirbheek @tp-m @xhaakon
|
||||
meson_options.txt @nirbheek @tp-m @xhaakon
|
||||
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
@@ -1,49 +0,0 @@
|
||||
AUTOMAKE_OPTIONS = gnu subdir-objects
|
||||
NAME=srtp
|
||||
|
||||
AM_CFLAGS = $(new_AM_CFLAGS) -I./src -Icrypto/include -I$(srcdir)/include -I$(srcdir)/crypto/include
|
||||
AM_CPPFLAGS = $(AM_CFLAGS)
|
||||
AM_LDFLAGS = $(new_AM_LDFLAGS) -L.
|
||||
|
||||
HMAC_OBJS = @HMAC_OBJS@
|
||||
AES_ICM_OBJS = @AES_ICM_OBJS@
|
||||
|
||||
lib_LTLIBRARIES = libsrtp.la
|
||||
libsrtp_la_SOURCES = srtp/srtp.c crypto/cipher/cipher.c crypto/cipher/null_cipher.c \
|
||||
crypto/hash/null_auth.c crypto/hash/auth.c \
|
||||
crypto/math/datatypes.c \
|
||||
crypto/kernel/crypto_kernel.c crypto/kernel/alloc.c \
|
||||
crypto/kernel/key.c \
|
||||
crypto/kernel/err.c \
|
||||
crypto/replay/rdb.c crypto/replay/rdbx.c \
|
||||
crypto/cipher/cipher_test_cases.c crypto/hash/auth_test_cases.c
|
||||
|
||||
libsrtp_la_LDFLAGS = -version-info 2:4:0
|
||||
|
||||
EXTRA_DIST=
|
||||
|
||||
if GCM
|
||||
AM_CPPFLAGS += -DGCM
|
||||
AM_CFLAGS += -DGCM
|
||||
endif
|
||||
|
||||
if ENABLE_OPENSSL
|
||||
libsrtp_la_SOURCES += crypto/cipher/aes_icm_ossl.c crypto/cipher/aes_gcm_ossl.c
|
||||
libsrtp_la_SOURCES += crypto/hash/hmac_ossl.c
|
||||
else
|
||||
libsrtp_la_SOURCES += crypto/hash/sha1.c crypto/hash/hmac.c
|
||||
libsrtp_la_SOURCES += crypto/cipher/aes_icm.c crypto/cipher/aes.c
|
||||
endif
|
||||
|
||||
library_includedir = $(prefix)/include/srtp
|
||||
library_include_HEADERS = include/srtp.h crypto/include/auth.h \
|
||||
crypto/include/cipher_types.h \
|
||||
crypto/include/datatypes.h crypto/include/integers.h crypto/include/null_cipher.h \
|
||||
crypto/include/rdbx.h crypto/include/aes_icm.h crypto/include/cipher.h crypto/include/crypto_types.h \
|
||||
crypto/include/err.h crypto/include/sha1.h \
|
||||
crypto/include/aes.h crypto/include/config.h crypto/include/key.h \
|
||||
crypto/include/alloc.h crypto/include/crypto_kernel.h \
|
||||
crypto/include/hmac.h crypto/include/null_auth.h crypto/include/rdb.h
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = libsrtp2.pc
|
||||
Whitespace-only changes.
@@ -1,180 +0,0 @@
|
||||
Secure RTP (SRTP) Reference Implementation
|
||||
David A. McGrew
|
||||
Cisco Systems, Inc.
|
||||
mcgrew@cisco.com
|
||||
|
||||
|
||||
This package provides an implementation of the Secure Real-time
|
||||
Transport Protocol (SRTP), the Universal Security Transform (UST), and
|
||||
a supporting cryptographic kernel. These mechanisms are documented in
|
||||
the Internet Drafts in the doc/ subdirectory. The SRTP API is
|
||||
documented in include/srtp.h, and the library is in libsrtp.a (after
|
||||
compilation). An overview and reference manual is available in
|
||||
doc/libsrtp.pdf. The PDF documentation is more up to date than this
|
||||
file.
|
||||
|
||||
|
||||
Installation:
|
||||
|
||||
./configure [ options ] # GNU autoconf script
|
||||
make # or gmake if needed; use GNU make
|
||||
|
||||
The configure script accepts the following options:
|
||||
|
||||
--help provides a usage summary
|
||||
--disable-debug compile without the runtime debugging system
|
||||
--enable-syslog use syslog for error reporting
|
||||
--disable-stdout use stdout for error reporting
|
||||
--enable-console use /dev/console for error reporting
|
||||
--enable-openssl use OpenSSL crypto primitives
|
||||
--gdoi use GDOI key management (disabled at present)
|
||||
|
||||
By default, debugging is enabled and stdout is used for debugging.
|
||||
You can use the above configure options to have the debugging output
|
||||
sent to syslog or the system console. Alternatively, you can define
|
||||
ERR_REPORTING_FILE in include/conf.h to be any other file that can be
|
||||
opened by libSRTP, and debug messages will be sent to it.
|
||||
|
||||
This package has been tested on Mac OS X (powerpc-apple-darwin1.4),
|
||||
Cygwin (i686-pc-cygwin), and Sparc (sparc-sun-solaris2.6). Previous
|
||||
versions have been tested on Linux and OpenBSD on both x86 and sparc
|
||||
platforms.
|
||||
|
||||
A quick tour of this package:
|
||||
|
||||
Makefile targets: all, clean, ...
|
||||
README this file
|
||||
CHANGES change log
|
||||
VERSION version number of this package
|
||||
LICENSE legal details (it's a BSD-like license)
|
||||
crypto/ciphers/ ciphers (null, aes_icm, ...)
|
||||
crypto/math/ crypto math routines
|
||||
crypto/hash/ crypto hashing (hmac, tmmhv2, ...)
|
||||
crypto/replay/ replay protection
|
||||
doc/ documentation: rfcs, apis, and suchlike
|
||||
include/ include files for all code in distribution
|
||||
srtp/ secure real-time transport protocol implementation
|
||||
tables/ apps for generating tables (useful in porting)
|
||||
test/ test drivers
|
||||
|
||||
|
||||
Applications
|
||||
|
||||
Several test drivers and a simple and portable srtp application
|
||||
are included in the test/ subdirectory.
|
||||
|
||||
test driver function tested
|
||||
-------------------------------------------------------------
|
||||
kernel_driver crypto kernel (ciphers, auth funcs, rng)
|
||||
srtp_driver srtp in-memory tests (does not use the network)
|
||||
rdbx_driver rdbx (extended replay database)
|
||||
roc_driver extended sequence number functions
|
||||
replay_driver replay database (n.b. not used in libsrtp)
|
||||
cipher_driver ciphers
|
||||
auth_driver hash functions
|
||||
|
||||
The app rtpw is a simple rtp application which reads words from
|
||||
/usr/dict/words and then sends them out one at a time using [s]rtp.
|
||||
Manual srtp keying uses the -k option; automated key management
|
||||
using gdoi will be added later.
|
||||
|
||||
usage: rtpw [-d <debug>]* [-k <key> [-a][-e <key size>][-g]] [-s | -r] dest_ip dest_port
|
||||
or rtpw -l
|
||||
|
||||
Either the -s (sender) or -r (receiver) option must be chosen.
|
||||
|
||||
The values dest_ip, dest_port are the ip address and udp port to
|
||||
which the dictionary will be sent, respectively.
|
||||
|
||||
options:
|
||||
|
||||
-s (s)rtp sender - causes app to send words
|
||||
|
||||
-r (s)rtp receive - causes app to receive words
|
||||
|
||||
-k <key> use srtp master key <key>, where the
|
||||
key is a hexadecimal value (without the
|
||||
leading "0x")
|
||||
|
||||
-e <keysize> encrypt/decrypt (for data confidentiality)
|
||||
(requires use of -k option as well)
|
||||
(use 128, 192, or 256 for keysize)
|
||||
|
||||
-g use AES-GCM mode (must be used with -e)
|
||||
|
||||
-a message authentication
|
||||
(requires use of -k option as well)
|
||||
|
||||
-l list debug modules
|
||||
|
||||
-d <debug> turn on debugging for module <debug>
|
||||
-i specify input/output file
|
||||
(instead of using dictionary file)
|
||||
|
||||
|
||||
In order to get random 30-byte values for use as key/salt pairs , you
|
||||
can use the following bash function to format the output of
|
||||
/dev/random (where that device is available).
|
||||
|
||||
function randhex() {
|
||||
cat /dev/random | od --read-bytes=32 --width=32 -x | awk '{ print $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 }'
|
||||
}
|
||||
|
||||
|
||||
An example of an SRTP session using two rtpw programs follows:
|
||||
|
||||
set k=c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451
|
||||
|
||||
[sh1]$ test/rtpw -s -k $k -e 128 -a 0.0.0.0 9999
|
||||
Security services: confidentiality message authentication
|
||||
set master key/salt to C1EEC3717DA76195BB878578790AF71C/4EE9F859E197A414A78D5ABC7451
|
||||
setting SSRC to 2078917053
|
||||
sending word: A
|
||||
sending word: a
|
||||
sending word: aa
|
||||
sending word: aal
|
||||
...
|
||||
|
||||
[sh2]$ test/rtpw -r -k $k -e 128 -a 0.0.0.0 9999
|
||||
security services: confidentiality message authentication
|
||||
set master key/salt to C1EEC3717DA76195BB878578790AF71C/4EE9F859E197A414A78D5ABC7451
|
||||
19 octets received from SSRC 2078917053 word: A
|
||||
19 octets received from SSRC 2078917053 word: a
|
||||
20 octets received from SSRC 2078917053 word: aa
|
||||
21 octets received from SSRC 2078917053 word: aal
|
||||
...
|
||||
|
||||
Implementation Notes
|
||||
|
||||
* The srtp_protect() function assumes that the buffer holding the
|
||||
rtp packet has enough storage allocated that the authentication
|
||||
tag can be written to the end of that packet. If this assumption
|
||||
is not valid, memory corruption will ensue.
|
||||
|
||||
* Automated tests for the crypto functions are provided through
|
||||
the cipher_type_self_test() and auth_type_self_test() functions.
|
||||
These functions should be used to test each port of this code
|
||||
to a new platform.
|
||||
|
||||
* Replay protection is contained in the crypto engine, and
|
||||
tests for it are provided.
|
||||
|
||||
* This implementation provides calls to initialize, protect, and
|
||||
unprotect RTP packets, and makes as few as possible assumptions
|
||||
about how these functions will be called. For example, the
|
||||
caller is not expected to provide packets in order (though if
|
||||
they're called more than 65k out of sequence, synchronization
|
||||
will be lost).
|
||||
|
||||
* The sequence number in the rtp packet is used as the low 16 bits
|
||||
of the sender's local packet index. Note that RTP will start its
|
||||
sequence number in a random place, and the SRTP layer just jumps
|
||||
forward to that number at its first invocation. An earlier
|
||||
version of this library used initial sequence numbers that are
|
||||
less than 32,768; this trick is no longer required as the
|
||||
rdbx_estimate_index(...) function has been made smarter.
|
||||
|
||||
* The replay window is 128 bits in length, and is hard-coded to this
|
||||
value for now.
|
||||
|
||||
|
||||
@@ -1,540 +0,0 @@
|
||||
[](https://github.com/cisco/libsrtp/actions/workflows/cmake.yml)
|
||||
[](https://travis-ci.org/cisco/libsrtp)
|
||||
[](https://scan.coverity.com/projects/cisco-libsrtp)
|
||||
[](https://oss-fuzz-build-logs.storage.googleapis.com/index.html#libsrtp)
|
||||
|
||||
<a name="introduction-to-libsrtp"></a>
|
||||
# Introduction to libSRTP
|
||||
|
||||
This package provides an implementation of the Secure Real-time
|
||||
Transport Protocol (SRTP), the Universal Security Transform (UST), and
|
||||
a supporting cryptographic kernel. The SRTP API is documented in include/srtp.h,
|
||||
and the library is in libsrtp2.a (after compilation).
|
||||
|
||||
This document describes libSRTP, the Open Source Secure RTP library
|
||||
from Cisco Systems, Inc. RTP is the Real-time Transport Protocol, an
|
||||
IETF standard for the transport of real-time data such as telephony,
|
||||
audio, and video, defined by [RFC 3550](https://tools.ietf.org/html/rfc3550).
|
||||
Secure RTP (SRTP) is an RTP profile for providing confidentiality to RTP data
|
||||
and authentication to the RTP header and payload. SRTP is an IETF Standard,
|
||||
defined in [RFC 3711](https://tools.ietf.org/html/rfc3711), and was developed
|
||||
in the IETF Audio/Video Transport (AVT) Working Group. This library supports
|
||||
all of the mandatory features of SRTP, but not all of the optional features. See
|
||||
the [Supported Features](#supported-features) section for more detailed information.
|
||||
|
||||
This document is also used to generate the documentation files in the /doc/
|
||||
folder where a more detailed reference to the libSRTP API and related functions
|
||||
can be created (requires installing doxygen.). The reference material is created
|
||||
automatically from comments embedded in some of the C header files. The
|
||||
documentation is organized into modules in order to improve its clarity. These
|
||||
modules do not directly correspond to files. An underlying cryptographic kernel
|
||||
provides much of the basic functionality of libSRTP but is mostly undocumented
|
||||
because it does its work behind the scenes.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="contact-us"></a>
|
||||
# Contact Us
|
||||
|
||||
- [libsrtp@lists.packetizer.com](mailto:libsrtp@lists.packetizer.com) general mailing list for news / announcements / discussions. This is an open list, see
|
||||
[https://lists.packetizer.com/mailman/listinfo/libsrtp](https://lists.packetizer.com/mailman/listinfo/libsrtp) for singing up.
|
||||
|
||||
- [libsrtp-security@lists.packetizer.com](mailto:libsrtp-security@lists.packetizer.com) for disclosing security issues to the libsrtp maintenance team. This is a closed list but anyone can send to it.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="contents"></a>
|
||||
## Contents
|
||||
|
||||
- [Introduction to libSRTP](#introduction-to-libsrtp)
|
||||
- [Contact Us](#contact-us)
|
||||
- [Contents](#contents)
|
||||
- [License and Disclaimer](#license-and-disclaimer)
|
||||
- [libSRTP Overview](#libsrtp-overview)
|
||||
- [Secure RTP Background](#secure-rtp-background)
|
||||
- [Supported Features](#supported-features)
|
||||
- [Implementation Notes](#implementation-notes)
|
||||
- [Installing and Building libSRTP](#installing-and-building-libsrtp)
|
||||
- [Changing Build Configuration](#changing-build-configuration)
|
||||
- [Using Visual Studio](#using-visual-studio)
|
||||
- [Applications](#applications)
|
||||
- [Example Code](#example-code)
|
||||
- [Credits](#credits)
|
||||
- [References](#references)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="license-and-disclaimer"></a>
|
||||
# License and Disclaimer
|
||||
|
||||
libSRTP is distributed under the following license, which is included
|
||||
in the source code distribution. It is reproduced in the manual in
|
||||
case you got the library from another source.
|
||||
|
||||
> Copyright (c) 2001-2017 Cisco Systems, Inc. All rights reserved.
|
||||
>
|
||||
> Redistribution and use in source and binary forms, with or without
|
||||
> modification, are permitted provided that the following conditions
|
||||
> are met:
|
||||
>
|
||||
> - Redistributions of source code must retain the above copyright
|
||||
> notice, this list of conditions and the following disclaimer.
|
||||
> - Redistributions in binary form must reproduce the above copyright
|
||||
> notice, this list of conditions and the following disclaimer in
|
||||
> the documentation and/or other materials provided with the distribution.
|
||||
> - Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
> contributors may be used to endorse or promote products derived
|
||||
> from this software without specific prior written permission.
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
> "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
> LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
> FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
> COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
> INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
> (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
> SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
> STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
> ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
> OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="libsrtp-overview"></a>
|
||||
# libSRTP Overview
|
||||
|
||||
libSRTP provides functions for protecting RTP and RTCP. RTP packets
|
||||
can be encrypted and authenticated (using the `srtp_protect()`
|
||||
function), turning them into SRTP packets. Similarly, SRTP packets
|
||||
can be decrypted and have their authentication verified (using the
|
||||
`srtp_unprotect()` function), turning them into RTP packets. Similar
|
||||
functions apply security to RTCP packets.
|
||||
|
||||
The typedef `srtp_stream_t` points to a structure holding all of the
|
||||
state associated with an SRTP stream, including the keys and
|
||||
parameters for cipher and message authentication functions and the
|
||||
anti-replay data. A particular `srtp_stream_t` holds the information
|
||||
needed to protect a particular RTP and RTCP stream. This datatype
|
||||
is intentionally opaque in order to better seperate the libSRTP
|
||||
API from its implementation.
|
||||
|
||||
Within an SRTP session, there can be multiple streams, each
|
||||
originating from a particular sender. Each source uses a distinct
|
||||
stream context to protect the RTP and RTCP stream that it is
|
||||
originating. The typedef `srtp_t` points to a structure holding all of
|
||||
the state associated with an SRTP session. There can be multiple
|
||||
stream contexts associated with a single `srtp_t`. A stream context
|
||||
cannot exist indepent from an `srtp_t`, though of course an `srtp_t` can
|
||||
be created that contains only a single stream context. A device
|
||||
participating in an SRTP session must have a stream context for each
|
||||
source in that session, so that it can process the data that it
|
||||
receives from each sender.
|
||||
|
||||
In libSRTP, a session is created using the function `srtp_create()`.
|
||||
The policy to be implemented in the session is passed into this
|
||||
function as an `srtp_policy_t` structure. A single one of these
|
||||
structures describes the policy of a single stream. These structures
|
||||
can also be linked together to form an entire session policy. A linked
|
||||
list of `srtp_policy_t` structures is equivalent to a session policy.
|
||||
In such a policy, we refer to a single `srtp_policy_t` as an *element*.
|
||||
|
||||
An `srtp_policy_t` structure contains two `srtp_crypto_policy_t` structures
|
||||
that describe the cryptograhic policies for RTP and RTCP, as well as
|
||||
the SRTP master key and the SSRC value. The SSRC describes what to
|
||||
protect (e.g. which stream), and the `srtp_crypto_policy_t` structures
|
||||
describe how to protect it. The key is contained in a policy element
|
||||
because it simplifies the interface to the library. In many cases, it
|
||||
is desirable to use the same cryptographic policies across all of the
|
||||
streams in a session, but to use a distinct key for each stream. A
|
||||
`srtp_crypto_policy_t` structure can be initialized by using either the
|
||||
`srtp_crypto_policy_set_rtp_default()` or `srtp_crypto_policy_set_rtcp_default()`
|
||||
functions, which set a crypto policy structure to the default policies
|
||||
for RTP and RTCP protection, respectively.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="secure-rtp-background"></a>
|
||||
## Secure RTP Background
|
||||
|
||||
In this section we review SRTP and introduce some terms that are used
|
||||
in libSRTP. An RTP session is defined by a pair of destination
|
||||
transport addresses, that is, a network address plus a pair of UDP
|
||||
ports for RTP and RTCP. RTCP, the RTP control protocol, is used to
|
||||
coordinate between the participants in an RTP session, e.g. to provide
|
||||
feedback from receivers to senders. An *SRTP session* is
|
||||
similarly defined; it is just an RTP session for which the SRTP
|
||||
profile is being used. An SRTP session consists of the traffic sent
|
||||
to the SRTP or SRTCP destination transport addresses. Each
|
||||
participant in a session is identified by a synchronization source
|
||||
(SSRC) identifier. Some participants may not send any SRTP traffic;
|
||||
they are called receivers, even though they send out SRTCP traffic,
|
||||
such as receiver reports.
|
||||
|
||||
RTP allows multiple sources to send RTP and RTCP traffic during the
|
||||
same session. The synchronization source identifier (SSRC) is used to
|
||||
distinguish these sources. In libSRTP, we call the SRTP and SRTCP
|
||||
traffic from a particular source a *stream*. Each stream has its own
|
||||
SSRC, sequence number, rollover counter, and other data. A particular
|
||||
choice of options, cryptographic mechanisms, and keys is called a
|
||||
*policy*. Each stream within a session can have a distinct policy
|
||||
applied to it. A session policy is a collection of stream policies.
|
||||
|
||||
A single policy can be used for all of the streams in a given session,
|
||||
though the case in which a single *key* is shared across multiple
|
||||
streams requires care. When key sharing is used, the SSRC values that
|
||||
identify the streams **must** be distinct. This requirement can be
|
||||
enforced by using the convention that each SRTP and SRTCP key is used
|
||||
for encryption by only a single sender. In other words, the key is
|
||||
shared only across streams that originate from a particular device (of
|
||||
course, other SRTP participants will need to use the key for
|
||||
decryption). libSRTP supports this enforcement by detecting the case
|
||||
in which a key is used for both inbound and outbound data.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="supported-features"></a>
|
||||
## Supported Features
|
||||
|
||||
This library supports all of the mandatory-to-implement features of
|
||||
SRTP (as defined in [RFC 3711](https://tools.ietf.org/html/rfc3711)). Some of these
|
||||
features can be selected (or de-selected) at run time by setting an
|
||||
appropriate policy; this is done using the structure `srtp_policy_t`.
|
||||
Some other behaviors of the protocol can be adapted by defining an
|
||||
approriate event handler for the exceptional events; see the SRTPevents
|
||||
section in the generated documentation.
|
||||
|
||||
Some options that are described in the SRTP specification are not
|
||||
supported. This includes
|
||||
|
||||
- key derivation rates other than zero,
|
||||
- the cipher F8,
|
||||
- the use of the packet index to select between master keys.
|
||||
|
||||
The user should be aware that it is possible to misuse this libary,
|
||||
and that the result may be that the security level it provides is
|
||||
inadequate. If you are implementing a feature using this library, you
|
||||
will want to read the Security Considerations section of [RFC 3711](https://tools.ietf.org/html/rfc3711#section-9).
|
||||
In addition, it is important that you read and understand the
|
||||
terms outlined in the [License and Disclaimer](#license-and-disclaimer) section.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="implementation-notes"></a>
|
||||
## Implementation Notes
|
||||
|
||||
* The `srtp_protect()` function assumes that the buffer holding the
|
||||
rtp packet has enough storage allocated that the authentication
|
||||
tag can be written to the end of that packet. If this assumption
|
||||
is not valid, memory corruption will ensue.
|
||||
|
||||
* Automated tests for the crypto functions are provided through
|
||||
the `cipher_type_self_test()` and `auth_type_self_test()` functions.
|
||||
These functions should be used to test each port of this code
|
||||
to a new platform.
|
||||
|
||||
* Replay protection is contained in the crypto engine, and
|
||||
tests for it are provided.
|
||||
|
||||
* This implementation provides calls to initialize, protect, and
|
||||
unprotect RTP packets, and makes as few as possible assumptions
|
||||
about how these functions will be called. For example, the
|
||||
caller is not expected to provide packets in order (though if
|
||||
they're called more than 65k out of sequence, synchronization
|
||||
will be lost).
|
||||
|
||||
* The sequence number in the rtp packet is used as the low 16 bits
|
||||
of the sender's local packet index. Note that RTP will start its
|
||||
sequence number in a random place, and the SRTP layer just jumps
|
||||
forward to that number at its first invocation. An earlier
|
||||
version of this library used initial sequence numbers that are
|
||||
less than 32,768; this trick is no longer required as the
|
||||
`rdbx_estimate_index(...)` function has been made smarter.
|
||||
|
||||
* The replay window for (S)RTCP is hardcoded to 128 bits in length.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="installing-and-building-libsrtp"></a>
|
||||
# Installing and Building libSRTP
|
||||
|
||||
To install libSRTP, download the latest release of the distribution
|
||||
from [https://github.com/cisco/libsrtp/releases](https://github.com/cisco/libsrtp/releases).
|
||||
You probably want to get the most recent release. Unpack the distribution and
|
||||
extract the source files; the directory into which the source files
|
||||
will go is named `libsrtp-A-B-C` where `A` is the version number, `B` is the
|
||||
major release number and `C` is the minor release number.
|
||||
|
||||
libSRTP uses the GNU `autoconf` and `make` utilities (BSD make will not work; if
|
||||
both versions of make are on your platform, you can invoke GNU make as
|
||||
`gmake`.). In the `libsrtp` directory, run the configure script and then
|
||||
make:
|
||||
|
||||
~~~.txt
|
||||
./configure [ options ]
|
||||
make
|
||||
~~~
|
||||
|
||||
The configure script accepts the following options:
|
||||
|
||||
Option | Description
|
||||
-------------------------------|--------------------
|
||||
\-\-help \-h | Display help
|
||||
\-\-enable-debug-logging | Enable debug logging in all modules
|
||||
\-\-enable-log-stdout | Enable logging to stdout
|
||||
\-\-enable-openssl | Enable OpenSSL crypto engine
|
||||
\-\-enable-openssl-kdf | Enable OpenSSL KDF algorithm
|
||||
\-\-with-log-file | Use file for logging
|
||||
\-\-with-openssl-dir | Location of OpenSSL installation
|
||||
|
||||
By default there is no log output, logging can be enabled to be output to stdout
|
||||
or a given file using the configure options.
|
||||
|
||||
This package has been tested on the following platforms: Mac OS X
|
||||
(powerpc-apple-darwin1.4), Cygwin (i686-pc-cygwin), Solaris
|
||||
(sparc-sun-solaris2.6), RedHat Linux 7.1 and 9 (i686-pc-linux), and
|
||||
OpenBSD (sparc-unknown-openbsd2.7).
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="changing-build-configuration"></a>
|
||||
## Changing Build Configuration
|
||||
|
||||
To build the `./configure` script mentioned above, libSRTP relies on the
|
||||
[automake](https://www.gnu.org/software/automake/) toolchain. Since
|
||||
`./configure` is built from `configure.in` by automake, if you make changes in
|
||||
how `./configure` works (e.g., to add a new library dependency), you will need
|
||||
to rebuild `./configure` and commit the updated version. In addition to
|
||||
automake itself, you will need to have the `pkgconfig` tools installed as well.
|
||||
|
||||
For example, on macOS:
|
||||
|
||||
```
|
||||
brew install automake pkgconfig
|
||||
# Edit configure.in
|
||||
autoremake -ivf
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
<a name="using-visual-studio"></a>
|
||||
## Using Visual Studio
|
||||
|
||||
On Windows one can use Visual Studio via CMake. CMake can be downloaded here:
|
||||
https://cmake.org/ . To create Visual Studio build files, for example run the
|
||||
following commands:
|
||||
|
||||
```
|
||||
# Create build subdirectory
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
# Make project files
|
||||
cmake .. -G "Visual Studio 15 2017"
|
||||
|
||||
# Or for 64 bit project files
|
||||
cmake .. -G "Visual Studio 15 2017 Win64"
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
<a name="using-meson"></a>
|
||||
## Using Meson
|
||||
|
||||
On all platforms including Windows, one can build using [Meson](https://mesonbuild.org).
|
||||
Steps to download Meson are here: https://mesonbuild.com/Getting-meson.html
|
||||
|
||||
To build with Meson, you can do something like:
|
||||
|
||||
```
|
||||
# Setup the build subdirectory
|
||||
meson setup --prefix=/path/to/prefix builddir
|
||||
|
||||
# Build the project
|
||||
meson compile -C builddir
|
||||
|
||||
# Run tests
|
||||
meson test -C builddir
|
||||
|
||||
# Optionally, install
|
||||
meson install -C builddir
|
||||
```
|
||||
|
||||
To build with Visual Studio, run the above commands from inside a Visual Studio
|
||||
command prompt, or run `vcvarsall.bat` with the appropriate arguments inside
|
||||
a Command Prompt.
|
||||
|
||||
Note that you can also replace the above commands with the appropriate `ninja`
|
||||
targets: `ninja -C build`, `ninja -C build test`, `ninja -C build install`.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="applications"></a>
|
||||
# Applications
|
||||
|
||||
Several test drivers and a simple and portable srtp application are
|
||||
included in the `test/` subdirectory.
|
||||
|
||||
Test driver | Function tested
|
||||
--------- | -------
|
||||
kernel_driver | crypto kernel (ciphers, auth funcs, rng)
|
||||
srtp_driver | srtp in-memory tests (does not use the network)
|
||||
rdbx_driver | rdbx (extended replay database)
|
||||
roc_driver | extended sequence number functions
|
||||
replay_driver | replay database
|
||||
cipher_driver | ciphers
|
||||
auth_driver | hash functions
|
||||
|
||||
The app `rtpw` is a simple rtp application which reads words from
|
||||
`/usr/dict/words` and then sends them out one at a time using [s]rtp.
|
||||
Manual srtp keying uses the -k option; automated key management
|
||||
using gdoi will be added later.
|
||||
|
||||
usage:
|
||||
~~~.txt
|
||||
rtpw [[-d <debug>]* [-k|b <key> [-a][-e <key size>][-g]] [-s | -r] dest_ip dest_port] | [-l]
|
||||
~~~
|
||||
|
||||
Either the -s (sender) or -r (receiver) option must be chosen. The
|
||||
values `dest_ip`, `dest_port` are the IP address and UDP port to which
|
||||
the dictionary will be sent, respectively.
|
||||
|
||||
The options are:
|
||||
|
||||
Option | Description
|
||||
--------- | -------
|
||||
-s | (S)RTP sender - causes app to send words
|
||||
-r | (S)RTP receive - causes app to receive words
|
||||
-k <key> | use SRTP master key <key>, where the key is a hexadecimal (without the leading "0x")
|
||||
-b <key> | same as -k but with base64 encoded key
|
||||
-e <keysize> | encrypt/decrypt (for data confidentiality) (requires use of -k option as well) (use 128, 192, or 256 for keysize)
|
||||
-g | use AES-GCM mode (must be used with -e)
|
||||
-a | message authentication (requires use of -k option as well)
|
||||
-l | list the available debug modules
|
||||
-d <debug> | turn on debugging for module <debug>
|
||||
|
||||
In order to get random 30-byte values for use as key/salt pairs , you
|
||||
can use the following bash function to format the output of
|
||||
`/dev/random` (where that device is available).
|
||||
|
||||
~~~.txt
|
||||
function randhex() {
|
||||
cat /dev/random | od --read-bytes=32 --width=32 -x | awk '{ print $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 }'
|
||||
}
|
||||
~~~
|
||||
|
||||
An example of an SRTP session using two rtpw programs follows:
|
||||
|
||||
~~~.txt
|
||||
set k=c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451
|
||||
|
||||
[sh1]$ test/rtpw -s -k $k -e 128 -a 0.0.0.0 9999
|
||||
Security services: confidentiality message authentication
|
||||
set master key/salt to C1EEC3717DA76195BB878578790AF71C/4EE9F859E197A414A78D5ABC7451
|
||||
setting SSRC to 2078917053
|
||||
sending word: A
|
||||
sending word: a
|
||||
sending word: aa
|
||||
sending word: aal
|
||||
...
|
||||
|
||||
[sh2]$ test/rtpw -r -k $k -e 128 -a 0.0.0.0 9999
|
||||
security services: confidentiality message authentication
|
||||
set master key/salt to C1EEC3717DA76195BB878578790AF71C/4EE9F859E197A414A78D5ABC7451
|
||||
19 octets received from SSRC 2078917053 word: A
|
||||
19 octets received from SSRC 2078917053 word: a
|
||||
20 octets received from SSRC 2078917053 word: aa
|
||||
21 octets received from SSRC 2078917053 word: aal
|
||||
...
|
||||
~~~
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="example-code"></a>
|
||||
## Example Code
|
||||
|
||||
This section provides a simple example of how to use libSRTP. The
|
||||
example code lacks error checking, but is functional. Here we assume
|
||||
that the value ssrc is already set to describe the SSRC of the stream
|
||||
that we are sending, and that the functions `get_rtp_packet()` and
|
||||
`send_srtp_packet()` are available to us. The former puts an RTP packet
|
||||
into the buffer and returns the number of octets written to that
|
||||
buffer. The latter sends the RTP packet in the buffer, given the
|
||||
length as its second argument.
|
||||
|
||||
~~~.c
|
||||
srtp_t session;
|
||||
srtp_policy_t policy;
|
||||
|
||||
// Set key to predetermined value
|
||||
uint8_t key[30] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D};
|
||||
|
||||
// initialize libSRTP
|
||||
srtp_init();
|
||||
|
||||
// default policy values
|
||||
memset(&policy, 0x0, sizeof(srtp_policy_t));
|
||||
|
||||
// set policy to describe a policy for an SRTP stream
|
||||
srtp_crypto_policy_set_rtp_default(&policy.rtp);
|
||||
srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
|
||||
policy.ssrc = ssrc;
|
||||
policy.key = key;
|
||||
policy.next = NULL;
|
||||
|
||||
// allocate and initialize the SRTP session
|
||||
srtp_create(&session, &policy);
|
||||
|
||||
// main loop: get rtp packets, send srtp packets
|
||||
while (1) {
|
||||
char rtp_buffer[2048];
|
||||
unsigned len;
|
||||
|
||||
len = get_rtp_packet(rtp_buffer);
|
||||
srtp_protect(session, rtp_buffer, &len);
|
||||
send_srtp_packet(rtp_buffer, len);
|
||||
}
|
||||
~~~
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="credits"></a>
|
||||
# Credits
|
||||
|
||||
The original implementation and documentation of libSRTP was written
|
||||
by David McGrew of Cisco Systems, Inc. in order to promote the use,
|
||||
understanding, and interoperability of Secure RTP. Michael Jerris
|
||||
contributed support for building under MSVC. Andris Pavenis
|
||||
contributed many important fixes. Brian West contributed changes to
|
||||
enable dynamic linking. Yves Shumann reported documentation bugs.
|
||||
Randell Jesup contributed a working SRTCP implementation and other
|
||||
fixes. Steve Underwood contributed x86_64 portability changes. We also give
|
||||
thanks to Fredrik Thulin, Brian Weis, Mark Baugher, Jeff Chan, Bill
|
||||
Simon, Douglas Smith, Bill May, Richard Preistley, Joe Tardo and
|
||||
others for contributions, comments, and corrections.
|
||||
|
||||
This reference material, when applicable, in this documenation was generated
|
||||
using the doxygen utility for automatic documentation of source code.
|
||||
|
||||
Copyright 2001-2005 by David A. McGrew, Cisco Systems, Inc.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="references"></a>
|
||||
# References
|
||||
|
||||
SRTP and ICM References
|
||||
September, 2005
|
||||
|
||||
Secure RTP is defined in [RFC 3711](https://tools.ietf.org/html/rfc3711).
|
||||
The counter mode definition is in [Section 4.1.1](https://tools.ietf.org/html/rfc3711#section-4.1.1).
|
||||
|
||||
SHA-1 is defined in [FIPS PUB 180-4](http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
||||
|
||||
HMAC is defined in [RFC 2104](https://tools.ietf.org/html/rfc2104)
|
||||
and HMAC-SHA1 test vectors are available
|
||||
in [RFC 2202](https://tools.ietf.org/html/rfc2202#section-3).
|
||||
|
||||
AES-GCM usage in SRTP is defined in [RFC 7714](https://tools.ietf.org/html/rfc7714)
|
||||
@@ -1,142 +0,0 @@
|
||||
AC_DEFUN([AX_CFLAGS_GCC_OPTION_OLD], [dnl
|
||||
AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
|
||||
AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$2])dnl
|
||||
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)],
|
||||
VAR,[VAR="no, unknown"
|
||||
AC_LANG_SAVE
|
||||
AC_LANG_C
|
||||
ac_save_[]FLAGS="$[]FLAGS"
|
||||
for ac_arg dnl
|
||||
in "-pedantic % m4_ifval($2,$2,-option)" dnl GCC
|
||||
#
|
||||
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
|
||||
AC_TRY_COMPILE([],[return 0;],
|
||||
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
|
||||
done
|
||||
FLAGS="$ac_save_[]FLAGS"
|
||||
AC_LANG_RESTORE
|
||||
])
|
||||
case ".$VAR" in
|
||||
.ok|.ok,*) m4_ifvaln($3,$3) ;;
|
||||
.|.no|.no,*) m4_ifvaln($4,$4) ;;
|
||||
*) m4_ifvaln($3,$3,[
|
||||
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
|
||||
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
|
||||
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
|
||||
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
|
||||
fi ]) ;;
|
||||
esac
|
||||
AS_VAR_POPDEF([VAR])dnl
|
||||
AS_VAR_POPDEF([FLAGS])dnl
|
||||
])
|
||||
|
||||
|
||||
dnl the only difference - the LANG selection... and the default FLAGS
|
||||
|
||||
AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_OLD], [dnl
|
||||
AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
|
||||
AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_gcc_option_$2])dnl
|
||||
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for gcc m4_ifval($2,$2,-option)],
|
||||
VAR,[VAR="no, unknown"
|
||||
AC_LANG_SAVE
|
||||
AC_LANG_CXX
|
||||
ac_save_[]FLAGS="$[]FLAGS"
|
||||
for ac_arg dnl
|
||||
in "-pedantic % m4_ifval($2,$2,-option)" dnl GCC
|
||||
#
|
||||
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
|
||||
AC_TRY_COMPILE([],[return 0;],
|
||||
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
|
||||
done
|
||||
FLAGS="$ac_save_[]FLAGS"
|
||||
AC_LANG_RESTORE
|
||||
])
|
||||
case ".$VAR" in
|
||||
.ok|.ok,*) m4_ifvaln($3,$3) ;;
|
||||
.|.no|.no,*) m4_ifvaln($4,$4) ;;
|
||||
*) m4_ifvaln($3,$3,[
|
||||
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
|
||||
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
|
||||
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
|
||||
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
|
||||
fi ]) ;;
|
||||
esac
|
||||
AS_VAR_POPDEF([VAR])dnl
|
||||
AS_VAR_POPDEF([FLAGS])dnl
|
||||
])
|
||||
|
||||
dnl -------------------------------------------------------------------------
|
||||
|
||||
AC_DEFUN([AX_CFLAGS_GCC_OPTION_NEW], [dnl
|
||||
AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
|
||||
AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_gcc_option_$1])dnl
|
||||
AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)],
|
||||
VAR,[VAR="no, unknown"
|
||||
AC_LANG_SAVE
|
||||
AC_LANG_C
|
||||
ac_save_[]FLAGS="$[]FLAGS"
|
||||
for ac_arg dnl
|
||||
in "-pedantic % m4_ifval($1,$1,-option)" dnl GCC
|
||||
#
|
||||
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
|
||||
AC_TRY_COMPILE([],[return 0;],
|
||||
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
|
||||
done
|
||||
FLAGS="$ac_save_[]FLAGS"
|
||||
AC_LANG_RESTORE
|
||||
])
|
||||
case ".$VAR" in
|
||||
.ok|.ok,*) m4_ifvaln($3,$3) ;;
|
||||
.|.no|.no,*) m4_ifvaln($4,$4) ;;
|
||||
*) m4_ifvaln($3,$3,[
|
||||
if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
|
||||
then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR])
|
||||
else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"])
|
||||
m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"
|
||||
fi ]) ;;
|
||||
esac
|
||||
AS_VAR_POPDEF([VAR])dnl
|
||||
AS_VAR_POPDEF([FLAGS])dnl
|
||||
])
|
||||
|
||||
|
||||
dnl the only difference - the LANG selection... and the default FLAGS
|
||||
|
||||
AC_DEFUN([AX_CXXFLAGS_GCC_OPTION_NEW], [dnl
|
||||
AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
|
||||
AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_gcc_option_$1])dnl
|
||||
AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for gcc m4_ifval($1,$1,-option)],
|
||||
VAR,[VAR="no, unknown"
|
||||
AC_LANG_SAVE
|
||||
AC_LANG_CXX
|
||||
ac_save_[]FLAGS="$[]FLAGS"
|
||||
for ac_arg dnl
|
||||
in "-pedantic % m4_ifval($1,$1,-option)" dnl GCC
|
||||
#
|
||||
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
|
||||
AC_TRY_COMPILE([],[return 0;],
|
||||
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
|
||||
done
|
||||
FLAGS="$ac_save_[]FLAGS"
|
||||
AC_LANG_RESTORE
|
||||
])
|
||||
case ".$VAR" in
|
||||
.ok|.ok,*) m4_ifvaln($3,$3) ;;
|
||||
.|.no|.no,*) m4_ifvaln($4,$4) ;;
|
||||
*) m4_ifvaln($3,$3,[
|
||||
if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
|
||||
then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR])
|
||||
else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"])
|
||||
m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"
|
||||
fi ]) ;;
|
||||
esac
|
||||
AS_VAR_POPDEF([VAR])dnl
|
||||
AS_VAR_POPDEF([FLAGS])dnl
|
||||
])
|
||||
|
||||
AC_DEFUN([AX_CFLAGS_GCC_OPTION],[ifelse(m4_bregexp([$2],[-]),-1,
|
||||
[AX_CFLAGS_GCC_OPTION_NEW($@)],[AX_CFLAGS_GCC_OPTION_OLD($@)])])
|
||||
|
||||
AC_DEFUN([AX_CXXFLAGS_GCC_OPTION],[ifelse(m4_bregexp([$2],[-]),-1,
|
||||
[AX_CXXFLAGS_GCC_OPTION_NEW($@)],[AX_CXXFLAGS_GCC_OPTION_OLD($@)])])
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
AC_DEFUN([AX_CFLAGS_SUN_OPTION_OLD], [dnl
|
||||
AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
|
||||
AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_sun_option_$2])dnl
|
||||
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for sun/cc m4_ifval($2,$2,-option)],
|
||||
VAR,[VAR="no, unknown"
|
||||
AC_LANG_SAVE
|
||||
AC_LANG_C
|
||||
ac_save_[]FLAGS="$[]FLAGS"
|
||||
for ac_arg dnl
|
||||
in "+xstrconst % -xc99=all m4_ifval($2,$2,-option)" dnl Solaris C
|
||||
#
|
||||
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
|
||||
AC_TRY_COMPILE([],[return 0;],
|
||||
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
|
||||
done
|
||||
FLAGS="$ac_save_[]FLAGS"
|
||||
AC_LANG_RESTORE
|
||||
])
|
||||
case ".$VAR" in
|
||||
.ok|.ok,*) m4_ifvaln($3,$3) ;;
|
||||
.|.no|.no,*) m4_ifvaln($4,$4) ;;
|
||||
*) m4_ifvaln($3,$3,[
|
||||
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
|
||||
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
|
||||
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
|
||||
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
|
||||
fi ]) ;;
|
||||
esac
|
||||
AS_VAR_POPDEF([VAR])dnl
|
||||
AS_VAR_POPDEF([FLAGS])dnl
|
||||
])
|
||||
|
||||
dnl the only difference - the LANG selection... and the default FLAGS
|
||||
|
||||
AC_DEFUN([AX_CXXFLAGS_SUN_OPTION_OLD], [dnl
|
||||
AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
|
||||
AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_sun_option_$2])dnl
|
||||
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for sun/cc m4_ifval($2,$2,-option)],
|
||||
VAR,[VAR="no, unknown"
|
||||
AC_LANG_SAVE
|
||||
AC_LANG_CXX
|
||||
ac_save_[]FLAGS="$[]FLAGS"
|
||||
for ac_arg dnl
|
||||
in "+xstrconst % -xc99=all m4_ifval($2,$2,-option)" dnl Solaris C
|
||||
#
|
||||
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
|
||||
AC_TRY_COMPILE([],[return 0;],
|
||||
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
|
||||
done
|
||||
FLAGS="$ac_save_[]FLAGS"
|
||||
AC_LANG_RESTORE
|
||||
])
|
||||
case ".$VAR" in
|
||||
.ok|.ok,*) m4_ifvaln($3,$3) ;;
|
||||
.|.no|.no,*) m4_ifvaln($4,$4) ;;
|
||||
*) m4_ifvaln($3,$3,[
|
||||
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
|
||||
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
|
||||
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
|
||||
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
|
||||
fi ]) ;;
|
||||
esac
|
||||
AS_VAR_POPDEF([VAR])dnl
|
||||
AS_VAR_POPDEF([FLAGS])dnl
|
||||
])
|
||||
|
||||
dnl -----------------------------------------------------------------------
|
||||
|
||||
AC_DEFUN([AX_CFLAGS_SUN_OPTION_NEW], [dnl
|
||||
AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
|
||||
AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_sun_option_$1])dnl
|
||||
AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for sun/cc m4_ifval($1,$1,-option)],
|
||||
VAR,[VAR="no, unknown"
|
||||
AC_LANG_SAVE
|
||||
AC_LANG_C
|
||||
ac_save_[]FLAGS="$[]FLAGS"
|
||||
for ac_arg dnl
|
||||
in "+xstrconst % -xc99=all m4_ifval($1,$1,-option)" dnl Solaris C
|
||||
#
|
||||
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
|
||||
AC_TRY_COMPILE([],[return 0;],
|
||||
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
|
||||
done
|
||||
FLAGS="$ac_save_[]FLAGS"
|
||||
AC_LANG_RESTORE
|
||||
])
|
||||
case ".$VAR" in
|
||||
.ok|.ok,*) m4_ifvaln($3,$3) ;;
|
||||
.|.no|.no,*) m4_ifvaln($4,$4) ;;
|
||||
*) m4_ifvaln($3,$3,[
|
||||
if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
|
||||
then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR])
|
||||
else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"])
|
||||
m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"
|
||||
fi ]) ;;
|
||||
esac
|
||||
AS_VAR_POPDEF([VAR])dnl
|
||||
AS_VAR_POPDEF([FLAGS])dnl
|
||||
])
|
||||
|
||||
dnl the only difference - the LANG selection... and the default FLAGS
|
||||
|
||||
AC_DEFUN([AX_CXXFLAGS_SUN_OPTION_NEW], [dnl
|
||||
AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
|
||||
AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_sun_option_$1])dnl
|
||||
AC_CACHE_CHECK([m4_ifval($2,$2,FLAGS) for sun/cc m4_ifval($1,$1,-option)],
|
||||
VAR,[VAR="no, unknown"
|
||||
AC_LANG_SAVE
|
||||
AC_LANG_CXX
|
||||
ac_save_[]FLAGS="$[]FLAGS"
|
||||
for ac_arg dnl
|
||||
in "+xstrconst % -xc99=all m4_ifval($1,$1,-option)" dnl Solaris C
|
||||
#
|
||||
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
|
||||
AC_TRY_COMPILE([],[return 0;],
|
||||
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
|
||||
done
|
||||
FLAGS="$ac_save_[]FLAGS"
|
||||
AC_LANG_RESTORE
|
||||
])
|
||||
case ".$VAR" in
|
||||
.ok|.ok,*) m4_ifvaln($3,$3) ;;
|
||||
.|.no|.no,*) m4_ifvaln($4,$4) ;;
|
||||
*) m4_ifvaln($3,$3,[
|
||||
if echo " $[]m4_ifval($2,$2,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
|
||||
then AC_RUN_LOG([: m4_ifval($2,$2,FLAGS) does contain $VAR])
|
||||
else AC_RUN_LOG([: m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"])
|
||||
m4_ifval($2,$2,FLAGS)="$m4_ifval($2,$2,FLAGS) $VAR"
|
||||
fi ]) ;;
|
||||
esac
|
||||
AS_VAR_POPDEF([VAR])dnl
|
||||
AS_VAR_POPDEF([FLAGS])dnl
|
||||
])
|
||||
|
||||
AC_DEFUN([AX_CFLAGS_SUN_OPTION],[ifelse(m4_regexp([$2],[-]),-1,
|
||||
[AX_CFLAGS_SUN_OPTION_NEW($@)],[AX_CFLAGS_SUN_OPTION_OLD($@)])])
|
||||
|
||||
AC_DEFUN([AX_CXXFLAGS_SUN_OPTION],[ifelse(m4_regexp([$2],[-]),-1,
|
||||
[AX_CXXFLAGS_SUN_OPTION_NEW($@)],[AX_CXXFLAGS_SUN_OPTION_OLD($@)])])
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
AC_DEFUN([AX_GCC_ARCHFLAG],
|
||||
[AC_REQUIRE([AC_PROG_CC])
|
||||
|
||||
AC_ARG_WITH(gcc-arch, [AC_HELP_STRING([--with-gcc-arch=<arch>], [use architecture <arch> for gcc -march/-mtune, instead of guessing])],
|
||||
ax_gcc_arch=$withval, ax_gcc_arch=yes)
|
||||
|
||||
AC_MSG_CHECKING([for gcc architecture flag])
|
||||
AC_MSG_RESULT([])
|
||||
AC_CACHE_VAL(ax_cv_gcc_archflag,
|
||||
[
|
||||
ax_cv_gcc_archflag="unknown"
|
||||
|
||||
if test "$GCC" = yes; then
|
||||
|
||||
if test "x$ax_gcc_arch" = xyes; then
|
||||
ax_gcc_arch=""
|
||||
if test "$cross_compiling" = no; then
|
||||
case $host_cpu in
|
||||
i[[3456]]86*|x86_64*) # use cpuid codes, in part from x86info-1.7 by D. Jones
|
||||
AX_GCC_X86_CPUID(0)
|
||||
AX_GCC_X86_CPUID(1)
|
||||
case $ax_cv_gcc_x86_cpuid_0 in
|
||||
*:756e6547:*:*) # Intel
|
||||
case $ax_cv_gcc_x86_cpuid_1 in
|
||||
*5[[48]]?:*:*:*) ax_gcc_arch="pentium-mmx pentium" ;;
|
||||
*5??:*:*:*) ax_gcc_arch=pentium ;;
|
||||
*6[[3456]]?:*:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
|
||||
*6a?:*[[01]]:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
|
||||
*6a?:*[[234]]:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
|
||||
*6[[9d]]?:*:*:*) ax_gcc_arch="pentium-m pentium3 pentiumpro" ;;
|
||||
*6[[78b]]?:*:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
|
||||
*6??:*:*:*) ax_gcc_arch=pentiumpro ;;
|
||||
*f3[[347]]:*:*:*|*f4[1347]:*:*:*)
|
||||
case $host_cpu in
|
||||
x86_64*) ax_gcc_arch="nocona pentium4 pentiumpro" ;;
|
||||
*) ax_gcc_arch="prescott pentium4 pentiumpro" ;;
|
||||
esac ;;
|
||||
*f??:*:*:*) ax_gcc_arch="pentium4 pentiumpro";;
|
||||
esac ;;
|
||||
*:68747541:*:*) # AMD
|
||||
case $ax_cv_gcc_x86_cpuid_1 in
|
||||
*5[[67]]?:*:*:*) ax_gcc_arch=k6 ;;
|
||||
*5[[8d]]?:*:*:*) ax_gcc_arch="k6-2 k6" ;;
|
||||
*5[[9]]?:*:*:*) ax_gcc_arch="k6-3 k6" ;;
|
||||
*60?:*:*:*) ax_gcc_arch=k7 ;;
|
||||
*6[[12]]?:*:*:*) ax_gcc_arch="athlon k7" ;;
|
||||
*6[[34]]?:*:*:*) ax_gcc_arch="athlon-tbird k7" ;;
|
||||
*67?:*:*:*) ax_gcc_arch="athlon-4 athlon k7" ;;
|
||||
*6[[68a]]?:*:*:*)
|
||||
AX_GCC_X86_CPUID(0x80000006) # L2 cache size
|
||||
case $ax_cv_gcc_x86_cpuid_0x80000006 in
|
||||
*:*:*[[1-9a-f]]??????:*) # (L2 = ecx >> 16) >= 256
|
||||
ax_gcc_arch="athlon-xp athlon-4 athlon k7" ;;
|
||||
*) ax_gcc_arch="athlon-4 athlon k7" ;;
|
||||
esac ;;
|
||||
*f[[4cef8b]]?:*:*:*) ax_gcc_arch="athlon64 k8" ;;
|
||||
*f5?:*:*:*) ax_gcc_arch="opteron k8" ;;
|
||||
*f7?:*:*:*) ax_gcc_arch="athlon-fx opteron k8" ;;
|
||||
*f??:*:*:*) ax_gcc_arch="k8" ;;
|
||||
esac ;;
|
||||
*:746e6543:*:*) # IDT
|
||||
case $ax_cv_gcc_x86_cpuid_1 in
|
||||
*54?:*:*:*) ax_gcc_arch=winchip-c6 ;;
|
||||
*58?:*:*:*) ax_gcc_arch=winchip2 ;;
|
||||
*6[[78]]?:*:*:*) ax_gcc_arch=c3 ;;
|
||||
*69?:*:*:*) ax_gcc_arch="c3-2 c3" ;;
|
||||
esac ;;
|
||||
esac
|
||||
if test x"$ax_gcc_arch" = x; then # fallback
|
||||
case $host_cpu in
|
||||
i586*) ax_gcc_arch=pentium ;;
|
||||
i686*) ax_gcc_arch=pentiumpro ;;
|
||||
esac
|
||||
fi
|
||||
;;
|
||||
|
||||
sparc*)
|
||||
AC_PATH_PROG([PRTDIAG], [prtdiag], [prtdiag], [$PATH:/usr/platform/`uname -i`/sbin/:/usr/platform/`uname -m`/sbin/])
|
||||
cputype=`(((grep cpu /proc/cpuinfo | cut -d: -f2) ; ($PRTDIAG -v |grep -i sparc) ; grep -i cpu /var/run/dmesg.boot ) | head -n 1) 2> /dev/null`
|
||||
cputype=`echo "$cputype" | tr -d ' -' |tr $as_cr_LETTERS $as_cr_letters`
|
||||
case $cputype in
|
||||
*ultrasparciv*) ax_gcc_arch="ultrasparc4 ultrasparc3 ultrasparc v9" ;;
|
||||
*ultrasparciii*) ax_gcc_arch="ultrasparc3 ultrasparc v9" ;;
|
||||
*ultrasparc*) ax_gcc_arch="ultrasparc v9" ;;
|
||||
*supersparc*|*tms390z5[[05]]*) ax_gcc_arch="supersparc v8" ;;
|
||||
*hypersparc*|*rt62[[056]]*) ax_gcc_arch="hypersparc v8" ;;
|
||||
*cypress*) ax_gcc_arch=cypress ;;
|
||||
esac ;;
|
||||
|
||||
alphaev5) ax_gcc_arch=ev5 ;;
|
||||
alphaev56) ax_gcc_arch=ev56 ;;
|
||||
alphapca56) ax_gcc_arch="pca56 ev56" ;;
|
||||
alphapca57) ax_gcc_arch="pca57 pca56 ev56" ;;
|
||||
alphaev6) ax_gcc_arch=ev6 ;;
|
||||
alphaev67) ax_gcc_arch=ev67 ;;
|
||||
alphaev68) ax_gcc_arch="ev68 ev67" ;;
|
||||
alphaev69) ax_gcc_arch="ev69 ev68 ev67" ;;
|
||||
alphaev7) ax_gcc_arch="ev7 ev69 ev68 ev67" ;;
|
||||
alphaev79) ax_gcc_arch="ev79 ev7 ev69 ev68 ev67" ;;
|
||||
|
||||
powerpc*)
|
||||
cputype=`((grep cpu /proc/cpuinfo | head -n 1 | cut -d: -f2 | cut -d, -f1 | sed 's/ //g') ; /usr/bin/machine ; /bin/machine; grep CPU /var/run/dmesg.boot | head -n 1 | cut -d" " -f2) 2> /dev/null`
|
||||
cputype=`echo $cputype | sed -e 's/ppc//g;s/ *//g'`
|
||||
case $cputype in
|
||||
*750*) ax_gcc_arch="750 G3" ;;
|
||||
*740[[0-9]]*) ax_gcc_arch="$cputype 7400 G4" ;;
|
||||
*74[[4-5]][[0-9]]*) ax_gcc_arch="$cputype 7450 G4" ;;
|
||||
*74[[0-9]][[0-9]]*) ax_gcc_arch="$cputype G4" ;;
|
||||
*970*) ax_gcc_arch="970 G5 power4";;
|
||||
*POWER4*|*power4*|*gq*) ax_gcc_arch="power4 970";;
|
||||
*POWER5*|*power5*|*gr*|*gs*) ax_gcc_arch="power5 power4 970";;
|
||||
603ev|8240) ax_gcc_arch="$cputype 603e 603";;
|
||||
*) ax_gcc_arch=$cputype ;;
|
||||
esac
|
||||
ax_gcc_arch="$ax_gcc_arch powerpc"
|
||||
;;
|
||||
esac
|
||||
fi # not cross-compiling
|
||||
fi # guess arch
|
||||
|
||||
if test "x$ax_gcc_arch" != x -a "x$ax_gcc_arch" != xno; then
|
||||
for arch in $ax_gcc_arch; do
|
||||
if test "x[]m4_default([$1],yes)" = xyes; then # if we require portable code
|
||||
flags="-mtune=$arch"
|
||||
# -mcpu=$arch and m$arch generate nonportable code on every arch except
|
||||
# x86. And some other arches (e.g. Alpha) don't accept -mtune. Grrr.
|
||||
case $host_cpu in i*86|x86_64*) flags="$flags -mcpu=$arch -m$arch";; esac
|
||||
else
|
||||
flags="-march=$arch -mcpu=$arch -m$arch"
|
||||
fi
|
||||
for flag in $flags; do
|
||||
AX_CHECK_COMPILER_FLAGS($flag, [ax_cv_gcc_archflag=$flag; break])
|
||||
done
|
||||
test "x$ax_cv_gcc_archflag" = xunknown || break
|
||||
done
|
||||
fi
|
||||
|
||||
fi # $GCC=yes
|
||||
])
|
||||
AC_MSG_CHECKING([for gcc architecture flag])
|
||||
AC_MSG_RESULT($ax_cv_gcc_archflag)
|
||||
if test "x$ax_cv_gcc_archflag" = xunknown; then
|
||||
m4_default([$3],:)
|
||||
else
|
||||
m4_default([$2], [CFLAGS="$CFLAGS $ax_cv_gcc_archflag"])
|
||||
fi
|
||||
])
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
AC_DEFUN([AX_GCC_X86_CPUID],
|
||||
[AC_REQUIRE([AC_PROG_CC])
|
||||
AC_LANG_PUSH([C])
|
||||
AC_CACHE_CHECK(for x86 cpuid $1 output, ax_cv_gcc_x86_cpuid_$1,
|
||||
[AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [
|
||||
int op = $1, eax, ebx, ecx, edx;
|
||||
FILE *f;
|
||||
__asm__("cpuid"
|
||||
: "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
|
||||
: "a" (op));
|
||||
f = fopen("conftest_cpuid", "w"); if (!f) return 1;
|
||||
fprintf(f, "%x:%x:%x:%x\n", eax, ebx, ecx, edx);
|
||||
fclose(f);
|
||||
return 0;
|
||||
])],
|
||||
[ax_cv_gcc_x86_cpuid_$1=`cat conftest_cpuid`; rm -f conftest_cpuid],
|
||||
[ax_cv_gcc_x86_cpuid_$1=unknown; rm -f conftest_cpuid],
|
||||
[ax_cv_gcc_x86_cpuid_$1=unknown])])
|
||||
AC_LANG_POP([C])
|
||||
])
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
AC_DEFUN([AC_PROG_GZIP],[
|
||||
AC_CHECK_PROGS(gzip,[gzip],no)
|
||||
export gzip;
|
||||
if test $gzip = "no" ;
|
||||
then
|
||||
AC_MSG_ERROR([Unable to find the gzip application]);
|
||||
fi
|
||||
AC_SUBST(gzip)
|
||||
])
|
||||
@@ -1,9 +0,0 @@
|
||||
AC_DEFUN([AC_PROG_WGET],[
|
||||
AC_CHECK_PROGS(wget,[wget],no)
|
||||
export wget;
|
||||
if test $wget = "no" ;
|
||||
then
|
||||
AC_MSG_ERROR([Unable to find the wget application]);
|
||||
fi
|
||||
AC_SUBST(wget)
|
||||
])
|
||||
@@ -1,120 +0,0 @@
|
||||
AC_DEFUN([AX_CC_MAXOPT],
|
||||
[
|
||||
AC_REQUIRE([AC_PROG_CC])
|
||||
AC_REQUIRE([AX_COMPILER_VENDOR])
|
||||
|
||||
AC_ARG_ENABLE(portable-binary, [AC_HELP_STRING([--enable-portable-binary], [disable compiler optimizations that would produce unportable binaries])],
|
||||
acx_maxopt_portable=$withval, acx_maxopt_portable=no)
|
||||
|
||||
# Try to determine "good" native compiler flags if none specified via CFLAGS
|
||||
if test "$ac_test_CFLAGS" != "set"; then
|
||||
CFLAGS=""
|
||||
case $ax_cv_c_compiler_vendor in
|
||||
dec) CFLAGS="-newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host"
|
||||
if test "x$acx_maxopt_portable" = xno; then
|
||||
CFLAGS="$CFLAGS -arch host"
|
||||
fi;;
|
||||
|
||||
sun) CFLAGS="-native -fast -xO5 -dalign -xc99=all"
|
||||
if test "x$acx_maxopt_portable" = xyes; then
|
||||
CFLAGS="$CFLAGS -xarch=generic"
|
||||
fi;;
|
||||
|
||||
hp) CFLAGS="+Oall +Optrs_ansi +DSnative"
|
||||
if test "x$acx_maxopt_portable" = xyes; then
|
||||
CFLAGS="$CFLAGS +DAportable"
|
||||
fi;;
|
||||
|
||||
ibm) if test "x$acx_maxopt_portable" = xno; then
|
||||
xlc_opt="-qarch=auto -qtune=auto"
|
||||
else
|
||||
xlc_opt="-qtune=auto"
|
||||
fi
|
||||
AX_CHECK_COMPILER_FLAGS($xlc_opt,
|
||||
CFLAGS="-O3 -qansialias -w $xlc_opt",
|
||||
[CFLAGS="-O3 -qansialias -w"
|
||||
echo "******************************************************"
|
||||
echo "* You seem to have the IBM C compiler. It is *"
|
||||
echo "* recommended for best performance that you use: *"
|
||||
echo "* *"
|
||||
echo "* CFLAGS=-O3 -qarch=xxx -qtune=xxx -qansialias -w *"
|
||||
echo "* ^^^ ^^^ *"
|
||||
echo "* where xxx is pwr2, pwr3, 604, or whatever kind of *"
|
||||
echo "* CPU you have. (Set the CFLAGS environment var. *"
|
||||
echo "* and re-run configure.) For more info, man cc. *"
|
||||
echo "******************************************************"])
|
||||
;;
|
||||
|
||||
intel) CFLAGS="-O3 -ansi_alias"
|
||||
if test "x$acx_maxopt_portable" = xno; then
|
||||
icc_archflag=unknown
|
||||
icc_flags=""
|
||||
case $host_cpu in
|
||||
i686*|x86_64*)
|
||||
# icc accepts gcc assembly syntax, so these should work:
|
||||
AX_GCC_X86_CPUID(0)
|
||||
AX_GCC_X86_CPUID(1)
|
||||
case $ax_cv_gcc_x86_cpuid_0 in # see AX_GCC_ARCHFLAG
|
||||
*:756e6547:*:*) # Intel
|
||||
case $ax_cv_gcc_x86_cpuid_1 in
|
||||
*6a?:*[[234]]:*:*|*6[[789b]]?:*:*:*) icc_flags="-xK";;
|
||||
*f3[[347]]:*:*:*|*f4[1347]:*:*:*) icc_flags="-xP -xN -xW -xK";;
|
||||
*f??:*:*:*) icc_flags="-xN -xW -xK";;
|
||||
esac ;;
|
||||
esac ;;
|
||||
esac
|
||||
if test "x$icc_flags" != x; then
|
||||
for flag in $icc_flags; do
|
||||
AX_CHECK_COMPILER_FLAGS($flag, [icc_archflag=$flag; break])
|
||||
done
|
||||
fi
|
||||
AC_MSG_CHECKING([for icc architecture flag])
|
||||
AC_MSG_RESULT($icc_archflag)
|
||||
if test "x$icc_archflag" != xunknown; then
|
||||
CFLAGS="$CFLAGS $icc_archflag"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
|
||||
gnu)
|
||||
# default optimization flags for gcc on all systems
|
||||
CFLAGS="-O3 -fomit-frame-pointer"
|
||||
|
||||
# -malign-double for x86 systems
|
||||
AX_CHECK_COMPILER_FLAGS(-malign-double, CFLAGS="$CFLAGS -malign-double")
|
||||
|
||||
# -fstrict-aliasing for gcc-2.95+
|
||||
AX_CHECK_COMPILER_FLAGS(-fstrict-aliasing,
|
||||
CFLAGS="$CFLAGS -fstrict-aliasing")
|
||||
|
||||
# note that we enable "unsafe" fp optimization with other compilers, too
|
||||
AX_CHECK_COMPILER_FLAGS(-ffast-math, CFLAGS="$CFLAGS -ffast-math")
|
||||
|
||||
AX_GCC_ARCHFLAG($acx_maxopt_portable)
|
||||
;;
|
||||
esac
|
||||
|
||||
if test -z "$CFLAGS"; then
|
||||
echo ""
|
||||
echo "********************************************************"
|
||||
echo "* WARNING: Don't know the best CFLAGS for this system *"
|
||||
echo "* Use ./configure CFLAGS=... to specify your own flags *"
|
||||
echo "* (otherwise, a default of CFLAGS=-O3 will be used) *"
|
||||
echo "********************************************************"
|
||||
echo ""
|
||||
CFLAGS="-O3"
|
||||
fi
|
||||
|
||||
AX_CHECK_COMPILER_FLAGS($CFLAGS, [], [
|
||||
echo ""
|
||||
echo "********************************************************"
|
||||
echo "* WARNING: The guessed CFLAGS don't seem to work with *"
|
||||
echo "* your compiler. *"
|
||||
echo "* Use ./configure CFLAGS=... to specify your own flags *"
|
||||
echo "********************************************************"
|
||||
echo ""
|
||||
CFLAGS=""
|
||||
])
|
||||
|
||||
fi
|
||||
])
|
||||
@@ -1,94 +0,0 @@
|
||||
AC_DEFUN([AX_CFLAGS_WARN_ALL_ANSI],[dnl
|
||||
AS_VAR_PUSHDEF([FLAGS],[CFLAGS])dnl
|
||||
AS_VAR_PUSHDEF([VAR],[ac_cv_cflags_warn_all_ansi])dnl
|
||||
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum ansi warnings],
|
||||
VAR,[VAR="no, unknown"
|
||||
AC_LANG_SAVE
|
||||
AC_LANG_C
|
||||
ac_save_[]FLAGS="$[]FLAGS"
|
||||
# IRIX C compiler:
|
||||
# -use_readonly_const is the default for IRIX C,
|
||||
# puts them into .rodata, but they are copied later.
|
||||
# need to be "-G0 -rdatashared" for strictmode but
|
||||
# I am not sure what effect that has really. - guidod
|
||||
for ac_arg dnl
|
||||
in "-pedantic % -Wall -std=c99 -pedantic" dnl GCC
|
||||
"-xstrconst % -v -xc99=all" dnl Solaris C
|
||||
"-std1 % -verbose -w0 -warnprotos -std1" dnl Digital Unix
|
||||
" % -qlanglvl=ansi -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
|
||||
" % -ansi -ansiE -fullwarn" dnl IRIX
|
||||
"+ESlit % +w1 -Aa" dnl HP-UX C
|
||||
"-Xc % -pvctl[,]fullmsg -Xc" dnl NEC SX-5 (Super-UX 10)
|
||||
"-h conform % -h msglevel 2 -h conform" dnl Cray C (Unicos)
|
||||
#
|
||||
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
|
||||
AC_TRY_COMPILE([],[return 0;],
|
||||
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
|
||||
done
|
||||
FLAGS="$ac_save_[]FLAGS"
|
||||
AC_LANG_RESTORE
|
||||
])
|
||||
case ".$VAR" in
|
||||
.ok|.ok,*) m4_ifvaln($3,$3) ;;
|
||||
.|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
|
||||
AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
|
||||
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
|
||||
*) m4_ifvaln($3,$3,[
|
||||
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
|
||||
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
|
||||
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
|
||||
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
|
||||
fi ]) ;;
|
||||
esac
|
||||
AS_VAR_POPDEF([VAR])dnl
|
||||
AS_VAR_POPDEF([FLAGS])dnl
|
||||
])
|
||||
|
||||
dnl the only difference - the LANG selection... and the default FLAGS
|
||||
|
||||
AC_DEFUN([AX_CXXFLAGS_WARN_ALL_ANSI],[dnl
|
||||
AS_VAR_PUSHDEF([FLAGS],[CXXFLAGS])dnl
|
||||
AS_VAR_PUSHDEF([VAR],[ac_cv_cxxflags_warn_all_ansi])dnl
|
||||
AC_CACHE_CHECK([m4_ifval($1,$1,FLAGS) for maximum ansi warnings],
|
||||
VAR,[VAR="no, unknown"
|
||||
AC_LANG_SAVE
|
||||
AC_LANG_CXX
|
||||
ac_save_[]FLAGS="$[]FLAGS"
|
||||
# IRIX C compiler:
|
||||
# -use_readonly_const is the default for IRIX C,
|
||||
# puts them into .rodata, but they are copied later.
|
||||
# need to be "-G0 -rdatashared" for strictmode but
|
||||
# I am not sure what effect that has really. - guidod
|
||||
for ac_arg dnl
|
||||
in "-pedantic % -Wall -ansi -pedantic" dnl GCC
|
||||
"-xstrconst % -v -Xc" dnl Solaris C
|
||||
"-std1 % -verbose -w0 -warnprotos -std1" dnl Digital Unix
|
||||
" % -qlanglvl=ansi -qsrcmsg -qinfo=all:noppt:noppc:noobs:nocnd" dnl AIX
|
||||
" % -ansi -ansiE -fullwarn" dnl IRIX
|
||||
"+ESlit % +w1 -Aa" dnl HP-UX C
|
||||
"-Xc % -pvctl[,]fullmsg -Xc" dnl NEC SX-5 (Super-UX 10)
|
||||
"-h conform % -h msglevel 2 -h conform" dnl Cray C (Unicos)
|
||||
#
|
||||
do FLAGS="$ac_save_[]FLAGS "`echo $ac_arg | sed -e 's,%%.*,,' -e 's,%,,'`
|
||||
AC_TRY_COMPILE([],[return 0;],
|
||||
[VAR=`echo $ac_arg | sed -e 's,.*% *,,'` ; break])
|
||||
done
|
||||
FLAGS="$ac_save_[]FLAGS"
|
||||
AC_LANG_RESTORE
|
||||
])
|
||||
case ".$VAR" in
|
||||
.ok|.ok,*) m4_ifvaln($3,$3) ;;
|
||||
.|.no|.no,*) m4_ifvaln($4,$4,[m4_ifval($2,[
|
||||
AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])
|
||||
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $2"])]) ;;
|
||||
*) m4_ifvaln($3,$3,[
|
||||
if echo " $[]m4_ifval($1,$1,FLAGS) " | grep " $VAR " 2>&1 >/dev/null
|
||||
then AC_RUN_LOG([: m4_ifval($1,$1,FLAGS) does contain $VAR])
|
||||
else AC_RUN_LOG([: m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"])
|
||||
m4_ifval($1,$1,FLAGS)="$m4_ifval($1,$1,FLAGS) $VAR"
|
||||
fi ]) ;;
|
||||
esac
|
||||
AS_VAR_POPDEF([VAR])dnl
|
||||
AS_VAR_POPDEF([FLAGS])dnl
|
||||
])
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
AC_DEFUN([AX_CHECK_COMPILER_FLAGS],
|
||||
[AC_PREREQ(2.59) dnl for _AC_LANG_PREFIX
|
||||
AC_MSG_CHECKING([whether _AC_LANG compiler accepts $1])
|
||||
dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname:
|
||||
AS_LITERAL_IF([$1],
|
||||
[AC_CACHE_VAL(AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1), [
|
||||
ax_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
|
||||
_AC_LANG_PREFIX[]FLAGS="$1"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
|
||||
AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=yes,
|
||||
AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=no)
|
||||
_AC_LANG_PREFIX[]FLAGS=$ax_save_FLAGS])],
|
||||
[ax_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
|
||||
_AC_LANG_PREFIX[]FLAGS="$1"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
|
||||
eval AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=yes,
|
||||
eval AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=no)
|
||||
_AC_LANG_PREFIX[]FLAGS=$ax_save_FLAGS])
|
||||
eval ax_check_compiler_flags=$AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)
|
||||
AC_MSG_RESULT($ax_check_compiler_flags)
|
||||
if test "x$ax_check_compiler_flags" = xyes; then
|
||||
m4_default([$2], :)
|
||||
else
|
||||
m4_default([$3], :)
|
||||
fi
|
||||
])dnl AX_CHECK_COMPILER_FLAG
|
||||
@@ -1,15 +0,0 @@
|
||||
AC_DEFUN([AX_COMPILER_VENDOR],
|
||||
[
|
||||
AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor,
|
||||
[ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=unknown
|
||||
# note: don't check for gcc first since some other compilers define __GNUC__
|
||||
for ventest in intel:__ICC,__ECC,__INTEL_COMPILER ibm:__xlc__,__xlC__,__IBMC__,__IBMCPP__ gnu:__GNUC__ sun:__SUNPRO_C,__SUNPRO_CC hp:__HP_cc,__HP_aCC dec:__DECC,__DECCXX,__DECC_VER,__DECCXX_VER borland:__BORLANDC__,__TURBOC__ comeau:__COMO__ cray:_CRAYC kai:__KCC lcc:__LCC__ metrowerks:__MWERKS__ sgi:__sgi,sgi microsoft:_MSC_VER watcom:__WATCOMC__ portland:__PGI; do
|
||||
vencpp="defined("`echo $ventest | cut -d: -f2 | sed 's/,/) || defined(/g'`")"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[
|
||||
#if !($vencpp)
|
||||
thisisanerror;
|
||||
#endif
|
||||
])], [ax_cv_]_AC_LANG_ABBREV[_compiler_vendor=`echo $ventest | cut -d: -f1`; break])
|
||||
done
|
||||
])
|
||||
])
|
||||
@@ -1,38 +0,0 @@
|
||||
find_path(MBEDTLS_INCLUDE_DIRS mbedtls/ssl.h)
|
||||
|
||||
find_library(MBEDTLS_LIBRARY mbedtls)
|
||||
find_library(MBEDX509_LIBRARY mbedx509)
|
||||
find_library(MBEDCRYPTO_LIBRARY mbedcrypto)
|
||||
|
||||
set(MBEDTLS_LIBRARIES "${MBEDTLS_LIBRARY}" "${MBEDX509_LIBRARY}" "${MBEDCRYPTO_LIBRARY}")
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(MbedTLS DEFAULT_MSG
|
||||
MBEDTLS_LIBRARY MBEDTLS_INCLUDE_DIRS MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY)
|
||||
|
||||
mark_as_advanced(MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY)
|
||||
|
||||
if(NOT TARGET MbedTLS)
|
||||
message("in mbedtls ${MBEDTLS_LIBRARY}")
|
||||
add_library(MbedTLS UNKNOWN IMPORTED)
|
||||
set_target_properties(MbedTLS PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_INCLUDE_DIRS}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${MBEDTLS_LIBRARY}")
|
||||
endif()
|
||||
|
||||
if(NOT TARGET MbedCrypto)
|
||||
add_library(MbedCrypto UNKNOWN IMPORTED)
|
||||
set_target_properties(MbedCrypto PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_INCLUDE_DIRS}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${MBEDCRYPTO_LIBRARY}")
|
||||
endif()
|
||||
|
||||
if(NOT TARGET MbedX509)
|
||||
add_library(MbedX509 UNKNOWN IMPORTED)
|
||||
set_target_properties(MbedX509 PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_INCLUDE_DIRS}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${MBEDX509_LIBRARY}")
|
||||
endif()
|
||||
@@ -1,15 +0,0 @@
|
||||
find_path(NSS_INCLUDE_DIR nss/nss.h)
|
||||
find_path(NSPR_INCLUDE_DIR nspr/nspr.h)
|
||||
|
||||
set(NSS_INCLUDE_DIRS "${NSS_INCLUDE_DIR}/nss" "${NSPR_INCLUDE_DIR}/nspr")
|
||||
|
||||
find_library(NSS3_LIBRARY nss3)
|
||||
find_library(NSPR4_LIBRARY nspr4)
|
||||
|
||||
set(NSS_LIBRARIES "${NSS3_LIBRARY}" "${NSPR4_LIBRARY}")
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(NSS DEFAULT_MSG
|
||||
NSS3_LIBRARY NSS_INCLUDE_DIR NSPR4_LIBRARY NSPR_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced(NSS_INCLUDE_DIR NSPR_INCLUDE_DIR NSS3_LIBRARY NSPR4_LIBRARY)
|
||||
@@ -1,121 +0,0 @@
|
||||
/* clang-format off */
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_VERSION "2.4.0"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_STRING "libsrtp2 2.4.0"
|
||||
|
||||
/* Define to enabled debug logging for all mudules. */
|
||||
/* #undef ENABLE_DEBUG_LOGGING */
|
||||
|
||||
/* Logging statments will be writen to this file. */
|
||||
/* #undef ERR_REPORTING_FILE */
|
||||
|
||||
/* Define to redirect logging to stdout. */
|
||||
/* #undef ERR_REPORTING_STDOUT */
|
||||
|
||||
/* Define this to use OpenSSL crypto. */
|
||||
#define OPENSSL 1
|
||||
|
||||
/* Define this to use MBEDTLS. */
|
||||
/* #undef MBEDTLS */
|
||||
|
||||
/* Define this to use NSS crypto. */
|
||||
/* #undef NSS */
|
||||
|
||||
/* Define this to use AES-GCM. */
|
||||
#define GCM 1
|
||||
|
||||
/* Define if building for a CISC machine (e.g. Intel). */
|
||||
#define CPU_CISC 1
|
||||
|
||||
/* Define if building for a RISC machine (assume slow byte access). */
|
||||
/* #undef CPU_RISC */
|
||||
|
||||
/* Define to use X86 inlined assembly code */
|
||||
#define HAVE_X86 1
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
/* #undef WORDS_BIGENDIAN */
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
/* #undef HAVE_ARPA_INET_H */
|
||||
|
||||
/* Define to 1 if you have the <byteswap.h> header file. */
|
||||
/* #undef HAVE_BYTESWAP_H */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <machine/types.h> header file. */
|
||||
/* #undef HAVE_MACHINE_TYPES_H */
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
/* #undef HAVE_NETINET_IN_H */
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/int_types.h> header file. */
|
||||
/* #undef HAVE_SYS_INT_TYPES_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
/* #undef HAVE_SYS_SOCKET_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
/* #undef HAVE_UNISTD_H */
|
||||
|
||||
/* Define to 1 if you have the <windows.h> header file. */
|
||||
#define HAVE_WINDOWS_H 1
|
||||
|
||||
/* Define to 1 if you have the <winsock2.h> header file. */
|
||||
#define HAVE_WINSOCK2_H 1
|
||||
|
||||
/* Define to 1 if you have the `inet_aton' function. */
|
||||
/* #undef HAVE_INET_ATON */
|
||||
|
||||
/* Define to 1 if you have the `sigaction' function. */
|
||||
/* #undef HAVE_SIGACTION */
|
||||
|
||||
/* Define to 1 if you have the `usleep' function. */
|
||||
/* #undef HAVE_USLEEP */
|
||||
|
||||
/* Define to 1 if the system has the type `uint8_t'. */
|
||||
#define HAVE_UINT8_T 1
|
||||
|
||||
/* Define to 1 if the system has the type `uint16_t'. */
|
||||
#define HAVE_UINT16_T 1
|
||||
|
||||
/* Define to 1 if the system has the type `uint32_t'. */
|
||||
#define HAVE_UINT32_T 1
|
||||
|
||||
/* Define to 1 if the system has the type `uint64_t'. */
|
||||
#define HAVE_UINT64_T 1
|
||||
|
||||
/* Define to 1 if the system has the type `int32_t'. */
|
||||
#define HAVE_INT32_T 1
|
||||
|
||||
/* The size of `unsigned long', as computed by sizeof. */
|
||||
#define SIZEOF_UNSIGNED_LONG 4
|
||||
|
||||
/* The size of `unsigned long long', as computed by sizeof. */
|
||||
#define SIZEOF_UNSIGNED_LONG_LONG 8
|
||||
|
||||
/* Define inline to what is supported by compiler */
|
||||
#define HAVE_INLINE 1
|
||||
/* #undef HAVE___INLINE */
|
||||
#ifndef HAVE_INLINE
|
||||
#ifdef HAVE___INLINE
|
||||
#define inline __inline
|
||||
#else
|
||||
#define inline
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,121 +0,0 @@
|
||||
/* clang-format off */
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@"
|
||||
|
||||
/* Define to enabled debug logging for all mudules. */
|
||||
#cmakedefine ENABLE_DEBUG_LOGGING 1
|
||||
|
||||
/* Logging statments will be writen to this file. */
|
||||
#cmakedefine ERR_REPORTING_FILE "@ERR_REPORTING_FILE@"
|
||||
|
||||
/* Define to redirect logging to stdout. */
|
||||
#cmakedefine ERR_REPORTING_STDOUT 1
|
||||
|
||||
/* Define this to use OpenSSL crypto. */
|
||||
#cmakedefine OPENSSL 1
|
||||
|
||||
/* Define this to use MBEDTLS. */
|
||||
#cmakedefine MBEDTLS 1
|
||||
|
||||
/* Define this to use NSS crypto. */
|
||||
#cmakedefine NSS 1
|
||||
|
||||
/* Define this to use AES-GCM. */
|
||||
#cmakedefine GCM 1
|
||||
|
||||
/* Define if building for a CISC machine (e.g. Intel). */
|
||||
#define CPU_CISC 1
|
||||
|
||||
/* Define if building for a RISC machine (assume slow byte access). */
|
||||
/* #undef CPU_RISC */
|
||||
|
||||
/* Define to use X86 inlined assembly code */
|
||||
#cmakedefine HAVE_X86 1
|
||||
|
||||
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||
#cmakedefine WORDS_BIGENDIAN 1
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
#cmakedefine HAVE_ARPA_INET_H 1
|
||||
|
||||
/* Define to 1 if you have the <byteswap.h> header file. */
|
||||
#cmakedefine HAVE_BYTESWAP_H 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#cmakedefine HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <machine/types.h> header file. */
|
||||
#cmakedefine HAVE_MACHINE_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
#cmakedefine HAVE_NETINET_IN_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#cmakedefine HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#cmakedefine HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/int_types.h> header file. */
|
||||
#cmakedefine HAVE_SYS_INT_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#cmakedefine HAVE_SYS_SOCKET_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#cmakedefine HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#cmakedefine HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to 1 if you have the <windows.h> header file. */
|
||||
#cmakedefine HAVE_WINDOWS_H 1
|
||||
|
||||
/* Define to 1 if you have the <winsock2.h> header file. */
|
||||
#cmakedefine HAVE_WINSOCK2_H 1
|
||||
|
||||
/* Define to 1 if you have the `inet_aton' function. */
|
||||
#cmakedefine HAVE_INET_ATON 1
|
||||
|
||||
/* Define to 1 if you have the `sigaction' function. */
|
||||
#cmakedefine HAVE_SIGACTION 1
|
||||
|
||||
/* Define to 1 if you have the `usleep' function. */
|
||||
#cmakedefine HAVE_USLEEP 1
|
||||
|
||||
/* Define to 1 if the system has the type `uint8_t'. */
|
||||
#cmakedefine HAVE_UINT8_T 1
|
||||
|
||||
/* Define to 1 if the system has the type `uint16_t'. */
|
||||
#cmakedefine HAVE_UINT16_T 1
|
||||
|
||||
/* Define to 1 if the system has the type `uint32_t'. */
|
||||
#cmakedefine HAVE_UINT32_T 1
|
||||
|
||||
/* Define to 1 if the system has the type `uint64_t'. */
|
||||
#cmakedefine HAVE_UINT64_T 1
|
||||
|
||||
/* Define to 1 if the system has the type `int32_t'. */
|
||||
#cmakedefine HAVE_INT32_T 1
|
||||
|
||||
/* The size of `unsigned long', as computed by sizeof. */
|
||||
@SIZEOF_UNSIGNED_LONG_CODE@
|
||||
|
||||
/* The size of `unsigned long long', as computed by sizeof. */
|
||||
@SIZEOF_UNSIGNED_LONG_LONG_CODE@
|
||||
|
||||
/* Define inline to what is supported by compiler */
|
||||
#cmakedefine HAVE_INLINE 1
|
||||
#cmakedefine HAVE___INLINE 1
|
||||
#ifndef HAVE_INLINE
|
||||
#ifdef HAVE___INLINE
|
||||
#define inline __inline
|
||||
#else
|
||||
#define inline
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,337 +0,0 @@
|
||||
AC_PREREQ(2.59)
|
||||
AC_INIT(srtp, 2.4.0, mcgrew@cisco.com)
|
||||
AC_CONFIG_AUX_DIR(build)
|
||||
AM_INIT_AUTOMAKE
|
||||
|
||||
CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
|
||||
CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
|
||||
LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
|
||||
|
||||
#Set default language
|
||||
AC_LANG_C
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_AWK
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_LIBTOOL
|
||||
AX_COMPILER_VENDOR
|
||||
|
||||
# Optimization
|
||||
AC_ARG_ENABLE(optimization,
|
||||
[AC_HELP_STRING([--enable-optimization],[Set if you want us to add max optimising compiler flags])],[enable_optimizer="$enableval"],[enable_optimizer="no"])
|
||||
|
||||
if test "${enable_optimizer}" = "yes" ; then
|
||||
AC_DEFINE([OPTIMZER],[],[Enable Optimization.])
|
||||
AX_CC_MAXOPT
|
||||
fi
|
||||
|
||||
# Enable debugging
|
||||
AC_ARG_ENABLE(debug,
|
||||
[AC_HELP_STRING([--enable-debug],[build with debug information])],[enable_debug="$enable_debug"],[enable_debug="yes"])
|
||||
|
||||
if test "${enable_debug}" = "yes"; then
|
||||
AC_DEFINE([DEBUG],[],[Enable extra debugging.])
|
||||
AX_CFLAGS_WARN_ALL_ANSI
|
||||
fi
|
||||
|
||||
|
||||
AM_CONDITIONAL([WANT_DEBUG],[test "${enable_debug}" = "yes"])
|
||||
|
||||
IN_LINE=inline
|
||||
|
||||
case "$host" in
|
||||
*-solaris2*)
|
||||
if test "x${ax_cv_c_compiler_vendor}" = "xsun" ; then
|
||||
SOLINK="-Bdynamic -dy -G"
|
||||
new_AM_CFLAGS="-KPIC -DPIC"
|
||||
new_AM_LDFLAGS="-R${prefix}/lib"
|
||||
FUNC_DEF=__func__
|
||||
IN_LINE=""
|
||||
elif test "x${ax_cv_c_compiler_vendor}" = "xgnu" ; then
|
||||
SOLINK="-Bdynamic -dy -G"
|
||||
new_AM_CFLAGS="-fPIC -Wall -O4 -fexpensive-optimizations -funroll-loops"
|
||||
new_AM_LDFLAGS=""
|
||||
IN_LINE=inline
|
||||
fi
|
||||
;;
|
||||
*-darwin*)
|
||||
if test "x${ax_cv_c_compiler_vendor}"="xgnu" ; then
|
||||
SOLINK="-dynamic -bundle -force-flat-namespace"
|
||||
new_AM_CFLAGS="-DMACOSX"
|
||||
new_AM_LDFLAGS=""
|
||||
fi
|
||||
;;
|
||||
x86_64-*-linux-gnu)
|
||||
if test "x${ax_cv_c_compiler_vendor}" = "xsun" ; then
|
||||
SOLINK="-Bdynamic -dy -G"
|
||||
new_AM_CFLAGS="-KPIC -DPIC"
|
||||
new_AM_LDFLAGS="-R${prefix}/lib"
|
||||
FUNC_DEF=__func__
|
||||
elif test "x${ax_cv_c_compiler_vendor}"="xgnu" ; then
|
||||
SOLINK="-shared -Xlinker -x"
|
||||
new_AM_CFLAGS="-fPIC -Wall -O4 -fexpensive-optimizations -funroll-loops"
|
||||
new_AM_LDFLAGS=""
|
||||
fi
|
||||
;;
|
||||
i*6-*-linux-gnu)
|
||||
if test "x${ax_cv_c_compiler_vendor}" = "xsun" ; then
|
||||
SOLINK="-Bdynamic -dy -G"
|
||||
new_AM_CFLAGS="-KPIC -DPIC"
|
||||
new_AM_LDFLAGS="-R${prefix}/lib"
|
||||
FUNC_DEF=__func__
|
||||
elif test "x${ax_cv_c_compiler_vendor}"="xgnu" ; then
|
||||
SOLINK="-shared -Xlinker -x"
|
||||
new_AM_CFLAGS="-fpic -Wall -O4 -fexpensive-optimizations -funroll-loops"
|
||||
new_AM_LDFLAGS=""
|
||||
fi
|
||||
;;
|
||||
i*6*-*-freebsd*)
|
||||
SOLINK="-shared -Xlinker -x"
|
||||
new_AM_CFLAGS="-fPIC -Wall -O4 -fexpensive-optimizations -funroll-loops"
|
||||
new_AM_LDFLAGS=""
|
||||
;;
|
||||
x86_64-*-freebsd*|amd64-*-freebsd*)
|
||||
SOLINK="-shared -Xlinker -x"
|
||||
new_AM_CFLAGS="-fPIC -Wall -O4 -fexpensive-optimizations -funroll-loops"
|
||||
new_AM_LDFLAGS=""
|
||||
;;
|
||||
esac
|
||||
|
||||
# Enable 64 bit build
|
||||
AC_ARG_ENABLE(64,
|
||||
[AC_HELP_STRING([--enable-64],[build with 64 bit support])],[enable_64="$enable_64"],[enable_64="no"])
|
||||
|
||||
if test "x${ax_cv_c_compiler_vendor}" = "xsun" ; then
|
||||
if test "${enable_64}" = "yes"; then
|
||||
new_AM_CFLAGS="$new_AM_CFLAGS -m64"
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_SUBST(new_AM_CFLAGS)
|
||||
AC_SUBST(new_AM_LDFLAGS)
|
||||
AC_SUBST(SOLINK)
|
||||
if test "x$FUNC_DEF" != "x"; then
|
||||
AC_DEFINE_UNQUOTED([__FUNCTION__],[$FUNC_DEF],[define it the right way ;)])
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED([inline],[$IN_LINE],[sunpro is bad at inline])
|
||||
|
||||
|
||||
AC_ARG_ENABLE(kernel-linux,
|
||||
[AS_HELP_STRING([--enable-kernel-linux],
|
||||
[build library to run in Linux kernel context])],
|
||||
[], enable_kernel_linux=no)
|
||||
AC_MSG_CHECKING(whether to build for Linux kernel context)
|
||||
if test "$enable_kernel_linux" = "yes"; then
|
||||
AC_DEFINE(SRTP_KERNEL, 1,
|
||||
[Define to compile for kernel contexts.])
|
||||
AC_DEFINE(SRTP_KERNEL_LINUX, 1,
|
||||
[Define to compile for Linux kernel context.])
|
||||
fi
|
||||
AC_MSG_RESULT($enable_kernel_linux)
|
||||
|
||||
dnl Check for /dev/urandom
|
||||
AC_CHECK_FILE(/dev/urandom, DEV_URANDOM=/dev/urandom,
|
||||
[AC_CHECK_FILE(/dev/random, DEV_URANDOM=/dev/random)])
|
||||
|
||||
dnl Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS(stdlib.h)
|
||||
AC_CHECK_HEADERS(unistd.h)
|
||||
AC_CHECK_HEADERS(stdint.h)
|
||||
AC_CHECK_HEADERS(sys/uio.h)
|
||||
AC_CHECK_HEADERS(inttypes.h)
|
||||
AC_CHECK_HEADERS(sys/types.h)
|
||||
AC_CHECK_HEADERS(machine/types.h)
|
||||
AC_CHECK_HEADERS(sys/int_types.h)
|
||||
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include <inttypes.h>
|
||||
#include <byteswap.h>
|
||||
]],[[
|
||||
uint64_t y = 0x1122334455667788LL;
|
||||
bswap_64(y);
|
||||
]])],byteswap_cv_bswap_64_usable=yes,byteswap_cv_bswap_64_usable=no)
|
||||
|
||||
if test "x${byteswap_cv_bswap_64_usable}" = "xyes" ; then
|
||||
AC_DEFINE([HAVE_BYTESWAP_H],1,[define if you have a usable bswap_64 in byteswap.h])
|
||||
fi
|
||||
|
||||
dnl socket() and friends
|
||||
AC_CHECK_HEADERS(sys/socket.h netinet/in.h arpa/inet.h)
|
||||
AC_CHECK_HEADERS(windows.h, [AC_CHECK_HEADERS(winsock2.h)])
|
||||
|
||||
AC_CHECK_HEADERS(syslog.h)
|
||||
|
||||
AC_CHECK_TYPES([int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,uint64_t])
|
||||
AC_CHECK_SIZEOF(unsigned long)
|
||||
AC_CHECK_SIZEOF(unsigned long long)
|
||||
|
||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
AC_C_INLINE
|
||||
AC_TYPE_SIZE_T
|
||||
|
||||
dnl Checks for library functions.
|
||||
AC_CHECK_FUNCS(socket inet_aton usleep sigaction)
|
||||
|
||||
dnl Find socket function if not found yet.
|
||||
if test "x$ac_cv_func_socket" = "xno"; then
|
||||
AC_CHECK_LIB(socket, socket)
|
||||
AC_MSG_CHECKING([for socket in -lwsock32])
|
||||
SAVELIBS="$LIBS"
|
||||
LIBS="$LIBS -lwsock32"
|
||||
AC_TRY_LINK([
|
||||
#include <winsock2.h>
|
||||
],[
|
||||
socket(0, 0, 0);
|
||||
],
|
||||
ac_cv_func_socket=yes
|
||||
AC_MSG_RESULT(yes),
|
||||
LIBS="$SAVELIBS"
|
||||
AC_MSG_RESULT(no))
|
||||
fi
|
||||
|
||||
dnl Check the byte order
|
||||
AC_C_BIGENDIAN
|
||||
|
||||
|
||||
dnl check host_cpu type, set defines appropriately
|
||||
case $host_cpu in
|
||||
i*86 | x86_64 )
|
||||
AC_DEFINE(CPU_CISC, 1,
|
||||
[Define if building for a CISC machine (e.g. Intel).])
|
||||
# Do not enable use of asm for MACOSX
|
||||
if test "x$new_AM_CFLAGS" != "x-DMACOSX"; then
|
||||
AC_DEFINE(HAVE_X86, 1,
|
||||
[Define to use X86 inlined assembly code])
|
||||
fi
|
||||
;;
|
||||
* )
|
||||
# CPU_RISC is only supported for big endian machines.
|
||||
if test "$ac_cv_c_bigendian" = "yes"; then
|
||||
AC_DEFINE(CPU_RISC, 1,
|
||||
[Define if building for a RISC machine (assume slow byte access).])
|
||||
else
|
||||
AC_DEFINE(CPU_CISC, 1)
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
dnl Check if we're on a Windows platform.
|
||||
case $host_os in
|
||||
*cygwin*|*mingw* )
|
||||
EXE=.exe;;
|
||||
* ) EXE="";;
|
||||
esac
|
||||
|
||||
AC_SUBST(EXE) # define executable suffix; this is needed for `make clean'
|
||||
|
||||
AC_MSG_CHECKING(whether to compile in debugging)
|
||||
AC_ARG_ENABLE(debug,
|
||||
[AS_HELP_STRING([--disable-debug],
|
||||
[do not compile in dynamic debugging system])],
|
||||
[], enable_debug=yes)
|
||||
if test "$enable_debug" = "yes"; then
|
||||
AC_DEFINE(ENABLE_DEBUGGING, 1,
|
||||
[Define to compile in dynamic debugging system.])
|
||||
fi
|
||||
AC_MSG_RESULT($enable_debug)
|
||||
|
||||
AC_MSG_CHECKING(whether to use ISMAcryp code)
|
||||
AC_ARG_ENABLE(generic-aesicm,
|
||||
[AS_HELP_STRING([--enable-generic-aesicm],
|
||||
[compile in changes for ISMAcryp])],
|
||||
[], enable_generic_aesicm=no)
|
||||
if test "$enable_generic_aesicm" = "yes"; then
|
||||
AC_DEFINE(GENERIC_AESICM, 1, [Define this to use ISMAcryp code.])
|
||||
fi
|
||||
AC_MSG_RESULT($enable_generic_aesicm)
|
||||
|
||||
AC_MSG_CHECKING(whether to leverage OpenSSL crypto)
|
||||
AC_ARG_ENABLE(openssl,
|
||||
[AS_HELP_STRING([--enable-openssl],
|
||||
[compile in OpenSSL crypto engine])],
|
||||
[], enable_openssl=no)
|
||||
if test "$enable_openssl" = "yes"; then
|
||||
echo $enable_openssl
|
||||
LDFLAGS="$LDFLAGS $(pkg-config --libs openssl)";
|
||||
CFLAGS="$CFLAGS $(pkg-config --cflags openssl)";
|
||||
|
||||
AC_CHECK_LIB([crypto], [EVP_EncryptInit], [],
|
||||
[AC_MSG_FAILURE([can't find openssl >1.0.1 crypto lib])])
|
||||
AC_CHECK_LIB([crypto], [EVP_aes_128_ctr], [],
|
||||
[AC_MSG_FAILURE([can't find openssl >1.0.1 crypto lib])])
|
||||
AC_CHECK_LIB([crypto], [EVP_aes_128_gcm], [],
|
||||
[AC_MSG_FAILURE([can't find openssl >1.0.1 crypto lib])])
|
||||
AC_DEFINE(OPENSSL, 1, [Define this to use OpenSSL crypto.])
|
||||
AES_ICM_OBJS="crypto/cipher/aes_icm_ossl.o crypto/cipher/aes_gcm_ossl.o"
|
||||
HMAC_OBJS=crypto/hash/hmac_ossl.o
|
||||
USE_OPENSSL=1
|
||||
AC_SUBST(USE_OPENSSL)
|
||||
else
|
||||
echo $enable_openssl
|
||||
AES_ICM_OBJS="crypto/cipher/aes_icm.o crypto/cipher/aes.o crypto/cipher/aes_cbc.o"
|
||||
AC_MSG_CHECKING(which random device to use)
|
||||
if test "$enable_kernel_linux" = "yes"; then
|
||||
AC_MSG_RESULT([Linux kernel builtin])
|
||||
else
|
||||
if test -n "$DEV_URANDOM"; then
|
||||
AC_DEFINE_UNQUOTED(DEV_URANDOM, "$DEV_URANDOM",[Path to random device])
|
||||
AC_MSG_RESULT([$DEV_URANDOM])
|
||||
else
|
||||
AC_MSG_RESULT([standard rand() function...])
|
||||
fi
|
||||
fi
|
||||
HMAC_OBJS="crypto/hash/hmac.o crypto/hash/sha1.o"
|
||||
fi
|
||||
AM_CONDITIONAL([ENABLE_OPENSSL],[test "${enable_openssl}" = "yes"])
|
||||
AM_CONDITIONAL([GCM],[test "${enable_openssl}" = "yes"])
|
||||
|
||||
AC_SUBST(AES_ICM_OBJS)
|
||||
AC_SUBST(HMAC_OBJS)
|
||||
AC_MSG_RESULT($enable_openssl)
|
||||
|
||||
AC_MSG_CHECKING(whether to use syslog for error reporting)
|
||||
AC_ARG_ENABLE(syslog,
|
||||
[AS_HELP_STRING([--enable-syslog], [use syslog for error reporting])],
|
||||
[], enable_syslog=no)
|
||||
if test "$enable_syslog" = "yes"; then
|
||||
AC_DEFINE(USE_SYSLOG, 1, [Define to use syslog logging.])
|
||||
fi
|
||||
AC_MSG_RESULT($enable_syslog)
|
||||
|
||||
AC_MSG_CHECKING(whether to use stdout for error reporting)
|
||||
AC_ARG_ENABLE(stdout,
|
||||
[AS_HELP_STRING([--disable-stdout], [don't use stdout for error reporting])],
|
||||
[], enable_stdout=yes)
|
||||
if test "$enable_stdout" = "yes"; then
|
||||
AC_DEFINE(ERR_REPORTING_STDOUT, 1, [Define to use logging to stdout.])
|
||||
fi
|
||||
AC_MSG_RESULT($enable_stdout)
|
||||
|
||||
AC_MSG_CHECKING(whether to use /dev/console for error reporting)
|
||||
AC_ARG_ENABLE(console,
|
||||
[AS_HELP_STRING([--enable-console], [use /dev/console for error reporting])],
|
||||
[], enable_console=no)
|
||||
if test "$enable_console" = "yes"; then
|
||||
AC_DEFINE(USE_ERR_REPORTING_FILE, 1, [Write errors to this file])
|
||||
AC_DEFINE(ERR_REPORTING_FILE, "/dev/console", [Report errors to this file.])
|
||||
fi
|
||||
AC_MSG_RESULT($enable_console)
|
||||
|
||||
AC_CONFIG_HEADERS(crypto/include/config.h:config_in.h)
|
||||
|
||||
AC_OUTPUT(Makefile crypto/Makefile doc/Makefile libsrtp2.pc)
|
||||
|
||||
# This is needed when building outside the source dir.
|
||||
AS_MKDIR_P(crypto/cipher)
|
||||
AS_MKDIR_P(crypto/hash)
|
||||
AS_MKDIR_P(crypto/kernel)
|
||||
AS_MKDIR_P(crypto/math)
|
||||
AS_MKDIR_P(crypto/replay)
|
||||
AS_MKDIR_P(crypto/test)
|
||||
AS_MKDIR_P(doc)
|
||||
AS_MKDIR_P(srtp)
|
||||
AS_MKDIR_P(tables)
|
||||
AS_MKDIR_P(test)
|
||||
@@ -1,4 +0,0 @@
|
||||
#! /bin/sh
|
||||
srcpath=$(dirname $0 2>/dev/null ) || srcpath="."
|
||||
$srcpath/configure "$@" --disable-shared --with-pic --enable-openssl
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
# Makefile for crypto test suite
|
||||
#
|
||||
# David A. McGrew
|
||||
# Cisco Systems, Inc.
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
top_builddir = @top_builddir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
CC = @CC@
|
||||
INCDIR = -Iinclude -I$(srcdir)/include -I$(top_srcdir)/include
|
||||
DEFS = @DEFS@
|
||||
CPPFLAGS= @CPPFLAGS@
|
||||
CFLAGS = @CFLAGS@
|
||||
LIBS = @LIBS@
|
||||
LDFLAGS = @LDFLAGS@ -L. -L..
|
||||
COMPILE = $(CC) $(DEFS) $(INCDIR) $(CPPFLAGS) $(CFLAGS)
|
||||
CRYPTOLIB = -lsrtp2
|
||||
CRYPTO_LIBDIR = @CRYPTO_LIBDIR@
|
||||
|
||||
RANLIB = @RANLIB@
|
||||
|
||||
# Specify how tests should find shared libraries on macOS and Linux
|
||||
#
|
||||
# macOS purges DYLD_LIBRARY_PATH when spawning subprocesses, so it's
|
||||
# not possible to pass this in from the outside; we have to specify
|
||||
# it for any subprocesses we call. No support for dynamic linked
|
||||
# tests on Windows.
|
||||
ifneq ($(strip $(CRYPTO_LIBDIR)),)
|
||||
ifneq ($(OS),Windows_NT)
|
||||
UNAME_S = $(shell uname -s)
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
FIND_LIBRARIES = LD_LIBRARY_PATH=$(CRYPTO_LIBDIR)
|
||||
endif
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
FIND_LIBRARIES = DYLD_LIBRARY_PATH=$(CRYPTO_LIBDIR)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
# EXE defines the suffix on executables - it's .exe for cygwin, and
|
||||
# null on linux, bsd, and OS X and other OSes. we define this so that
|
||||
# `make clean` will work on the cygwin platform
|
||||
EXE = @EXE@
|
||||
# Random source.
|
||||
USE_EXTERNAL_CRYPTO = @USE_EXTERNAL_CRYPTO@
|
||||
|
||||
ifdef ARCH
|
||||
DEFS += -D$(ARCH)=1
|
||||
endif
|
||||
|
||||
ifdef sysname
|
||||
DEFS += -D$(sysname)=1
|
||||
endif
|
||||
|
||||
.PHONY: dummy all runtest clean superclean
|
||||
|
||||
dummy : all runtest
|
||||
|
||||
# test applications
|
||||
ifneq (1, $(USE_EXTERNAL_CRYPTO))
|
||||
AES_CALC = test/aes_calc$(EXE)
|
||||
SHA1_DRIVER = test/sha1_driver$(EXE)
|
||||
endif
|
||||
|
||||
testapp = test/cipher_driver$(EXE) test/datatypes_driver$(EXE) \
|
||||
$(SHA1_DRIVER) test/kernel_driver$(EXE) \
|
||||
$(AES_CALC) test/env$(EXE)
|
||||
|
||||
# data values used to test the aes_calc application for AES-128
|
||||
k128=000102030405060708090a0b0c0d0e0f
|
||||
p128=00112233445566778899aabbccddeeff
|
||||
c128=69c4e0d86a7b0430d8cdb78070b4c55a
|
||||
|
||||
|
||||
# data values used to test the aes_calc application for AES-256
|
||||
k256=000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
|
||||
p256=00112233445566778899aabbccddeeff
|
||||
c256=8ea2b7ca516745bfeafc49904b496089
|
||||
|
||||
|
||||
runtest: $(testapp)
|
||||
$(FIND_LIBRARIES) test/env$(EXE) # print out information on the build environment
|
||||
@echo "running crypto test applications..."
|
||||
ifneq (1, $(USE_EXTERNAL_CRYPTO))
|
||||
$(FIND_LIBRARIES) test `test/aes_calc $(k128) $(p128)` = $(c128)
|
||||
$(FIND_LIBRARIES) test `test/aes_calc $(k256) $(p256)` = $(c256)
|
||||
$(FIND_LIBRARIES) test/sha1_driver$(EXE) -v >/dev/null
|
||||
endif
|
||||
$(FIND_LIBRARIES) test/cipher_driver$(EXE) -v >/dev/null
|
||||
$(FIND_LIBRARIES) test/datatypes_driver$(EXE) -v >/dev/null
|
||||
$(FIND_LIBRARIES) test/kernel_driver$(EXE) -v >/dev/null
|
||||
@echo "crypto test applications passed."
|
||||
|
||||
|
||||
# the rule for making object files and test apps
|
||||
|
||||
%.o: %.c
|
||||
$(COMPILE) -c $< -o $@
|
||||
|
||||
%$(EXE): %.c $(srcdir)/../test/getopt_s.c
|
||||
$(COMPILE) $(LDFLAGS) $< $(srcdir)/../test/getopt_s.c -o $@ $(CRYPTOLIB) $(LIBS)
|
||||
|
||||
all: $(testapp)
|
||||
|
||||
# housekeeping functions
|
||||
|
||||
clean:
|
||||
rm -f $(testapp) *.o */*.o
|
||||
for a in * .* */*; do if [ -f "$$a~" ] ; then rm $$a~; fi; done;
|
||||
rm -f `find . -name "*.[ch]~*~"`
|
||||
rm -rf latex
|
||||
|
||||
superclean: clean
|
||||
rm -f *core TAGS ktrace.out
|
||||
|
||||
# EOF
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,412 +0,0 @@
|
||||
/*
|
||||
* aes_gcm_mbedtls.c
|
||||
*
|
||||
* AES Galois Counter Mode
|
||||
*
|
||||
* YongCheng Yang
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <mbedtls/gcm.h>
|
||||
#include "aes_gcm.h"
|
||||
#include "alloc.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "crypto_types.h"
|
||||
#include "cipher_types.h"
|
||||
#include "cipher_test_cases.h"
|
||||
|
||||
srtp_debug_module_t srtp_mod_aes_gcm = {
|
||||
0, /* debugging is off by default */
|
||||
"aes gcm mbedtls" /* printable module name */
|
||||
};
|
||||
|
||||
/**
|
||||
* SRTP IV Formation for AES-GCM
|
||||
* https://tools.ietf.org/html/rfc7714#section-8.1
|
||||
* 0 0 0 0 0 0 0 0 0 0 1 1
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* |00|00| SSRC | ROC | SEQ |---+
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+ |
|
||||
* |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+ |
|
||||
* | Encryption Salt |->(+)
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+ |
|
||||
* |
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+ |
|
||||
* | Initialization Vector |<--+
|
||||
* +--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*
|
||||
* SRTCP IV Formation for AES-GCM
|
||||
* https://tools.ietf.org/html/rfc7714#section-9.1
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* For now we only support 8 and 16 octet tags. The spec allows for
|
||||
* optional 12 byte tag, which may be supported in the future.
|
||||
*/
|
||||
#define GCM_IV_LEN 12
|
||||
#define GCM_AUTH_TAG_LEN 16
|
||||
#define GCM_AUTH_TAG_LEN_8 8
|
||||
|
||||
#define FUNC_ENTRY() debug_print(srtp_mod_aes_gcm, "%s entry", __func__);
|
||||
/*
|
||||
* This function allocates a new instance of this crypto engine.
|
||||
* The key_len parameter should be one of 28 or 44 for
|
||||
* AES-128-GCM or AES-256-GCM respectively. Note that the
|
||||
* key length includes the 14 byte salt value that is used when
|
||||
* initializing the KDF.
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_mbedtls_alloc(srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen)
|
||||
{
|
||||
FUNC_ENTRY();
|
||||
srtp_aes_gcm_ctx_t *gcm;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "allocating cipher with key length %d",
|
||||
key_len);
|
||||
debug_print(srtp_mod_aes_gcm, "allocating cipher with tag length %d", tlen);
|
||||
|
||||
/*
|
||||
* Verify the key_len is valid for one of: AES-128/256
|
||||
*/
|
||||
if (key_len != SRTP_AES_GCM_128_KEY_LEN_WSALT &&
|
||||
key_len != SRTP_AES_GCM_256_KEY_LEN_WSALT) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
if (tlen != GCM_AUTH_TAG_LEN && tlen != GCM_AUTH_TAG_LEN_8) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
/* allocate memory a cipher of type aes_gcm */
|
||||
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
|
||||
if (*c == NULL) {
|
||||
return (srtp_err_status_alloc_fail);
|
||||
}
|
||||
|
||||
gcm = (srtp_aes_gcm_ctx_t *)srtp_crypto_alloc(sizeof(srtp_aes_gcm_ctx_t));
|
||||
if (gcm == NULL) {
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return (srtp_err_status_alloc_fail);
|
||||
}
|
||||
|
||||
gcm->ctx =
|
||||
(mbedtls_gcm_context *)srtp_crypto_alloc(sizeof(mbedtls_gcm_context));
|
||||
if (gcm->ctx == NULL) {
|
||||
srtp_crypto_free(gcm);
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
mbedtls_gcm_init(gcm->ctx);
|
||||
|
||||
/* set pointers */
|
||||
(*c)->state = gcm;
|
||||
|
||||
/* setup cipher attributes */
|
||||
switch (key_len) {
|
||||
case SRTP_AES_GCM_128_KEY_LEN_WSALT:
|
||||
(*c)->type = &srtp_aes_gcm_128;
|
||||
(*c)->algorithm = SRTP_AES_GCM_128;
|
||||
gcm->key_size = SRTP_AES_128_KEY_LEN;
|
||||
gcm->tag_len = tlen;
|
||||
break;
|
||||
case SRTP_AES_GCM_256_KEY_LEN_WSALT:
|
||||
(*c)->type = &srtp_aes_gcm_256;
|
||||
(*c)->algorithm = SRTP_AES_GCM_256;
|
||||
gcm->key_size = SRTP_AES_256_KEY_LEN;
|
||||
gcm->tag_len = tlen;
|
||||
break;
|
||||
}
|
||||
|
||||
/* set key size */
|
||||
(*c)->key_len = key_len;
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function deallocates a GCM session
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_mbedtls_dealloc(srtp_cipher_t *c)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *ctx;
|
||||
FUNC_ENTRY();
|
||||
ctx = (srtp_aes_gcm_ctx_t *)c->state;
|
||||
if (ctx) {
|
||||
mbedtls_gcm_free(ctx->ctx);
|
||||
srtp_crypto_free(ctx->ctx);
|
||||
/* zeroize the key material */
|
||||
octet_string_set_to_zero(ctx, sizeof(srtp_aes_gcm_ctx_t));
|
||||
srtp_crypto_free(ctx);
|
||||
}
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(c);
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_aes_gcm_mbedtls_context_init(void *cv,
|
||||
const uint8_t *key)
|
||||
{
|
||||
FUNC_ENTRY();
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
uint32_t key_len_in_bits;
|
||||
int errCode = 0;
|
||||
c->dir = srtp_direction_any;
|
||||
c->aad_size = 0;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "key: %s",
|
||||
srtp_octet_string_hex_string(key, c->key_size));
|
||||
key_len_in_bits = (c->key_size << 3);
|
||||
switch (c->key_size) {
|
||||
case SRTP_AES_256_KEY_LEN:
|
||||
case SRTP_AES_128_KEY_LEN:
|
||||
break;
|
||||
default:
|
||||
return (srtp_err_status_bad_param);
|
||||
break;
|
||||
}
|
||||
|
||||
errCode = mbedtls_gcm_setkey(c->ctx, MBEDTLS_CIPHER_ID_AES,
|
||||
(const unsigned char *)key, key_len_in_bits);
|
||||
if (errCode != 0) {
|
||||
debug_print(srtp_mod_aes_gcm, "mbedtls error code: %d", errCode);
|
||||
return srtp_err_status_init_fail;
|
||||
}
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_aes_gcm_mbedtls_set_iv(
|
||||
void *cv,
|
||||
uint8_t *iv,
|
||||
srtp_cipher_direction_t direction)
|
||||
{
|
||||
FUNC_ENTRY();
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
|
||||
if (direction != srtp_direction_encrypt &&
|
||||
direction != srtp_direction_decrypt) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
c->dir = direction;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "setting iv: %s",
|
||||
srtp_octet_string_hex_string(iv, GCM_IV_LEN));
|
||||
c->iv_len = GCM_IV_LEN;
|
||||
memcpy(c->iv, iv, c->iv_len);
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function processes the AAD
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* aad Additional data to process for AEAD cipher suites
|
||||
* aad_len length of aad buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_mbedtls_set_aad(void *cv,
|
||||
const uint8_t *aad,
|
||||
uint32_t aad_len)
|
||||
{
|
||||
FUNC_ENTRY();
|
||||
int errCode = 0;
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "setting AAD: %s",
|
||||
srtp_octet_string_hex_string(aad, aad_len));
|
||||
|
||||
if (aad_len + c->aad_size > MAX_AD_SIZE) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
memcpy(c->aad + c->aad_size, aad, aad_len);
|
||||
c->aad_size += aad_len;
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function encrypts a buffer using AES GCM mode
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* enc_len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_mbedtls_encrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
FUNC_ENTRY();
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
int errCode = 0;
|
||||
|
||||
if (c->dir != srtp_direction_encrypt && c->dir != srtp_direction_decrypt) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
errCode = mbedtls_gcm_crypt_and_tag(c->ctx, MBEDTLS_GCM_ENCRYPT, *enc_len,
|
||||
c->iv, c->iv_len, c->aad, c->aad_size,
|
||||
buf, buf, c->tag_len, c->tag);
|
||||
|
||||
c->aad_size = 0;
|
||||
if (errCode != 0) {
|
||||
debug_print(srtp_mod_aes_gcm, "mbedtls error code: %d", errCode);
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function calculates and returns the GCM tag for a given context.
|
||||
* This should be called after encrypting the data. The *len value
|
||||
* is increased by the tag size. The caller must ensure that *buf has
|
||||
* enough room to accept the appended tag.
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_mbedtls_get_tag(void *cv,
|
||||
uint8_t *buf,
|
||||
uint32_t *len)
|
||||
{
|
||||
FUNC_ENTRY();
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
debug_print(srtp_mod_aes_gcm, "appended tag size: %d", c->tag_len);
|
||||
*len = c->tag_len;
|
||||
memcpy(buf, c->tag, c->tag_len);
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function decrypts a buffer using AES GCM mode
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* enc_len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_mbedtls_decrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
FUNC_ENTRY();
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
int errCode = 0;
|
||||
int len = *enc_len;
|
||||
|
||||
if (c->dir != srtp_direction_encrypt && c->dir != srtp_direction_decrypt) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "AAD: %s",
|
||||
srtp_octet_string_hex_string(c->aad, c->aad_size));
|
||||
|
||||
errCode = mbedtls_gcm_auth_decrypt(
|
||||
c->ctx, (*enc_len - c->tag_len), c->iv, c->iv_len, c->aad, c->aad_size,
|
||||
buf + (*enc_len - c->tag_len), c->tag_len, buf, buf);
|
||||
c->aad_size = 0;
|
||||
if (errCode != 0) {
|
||||
return (srtp_err_status_auth_fail);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reduce the buffer size by the tag length since the tag
|
||||
* is not part of the original payload
|
||||
*/
|
||||
*enc_len -= c->tag_len;
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* Name of this crypto engine
|
||||
*/
|
||||
static const char srtp_aes_gcm_128_mbedtls_description[] =
|
||||
"AES-128 GCM using mbedtls";
|
||||
static const char srtp_aes_gcm_256_mbedtls_description[] =
|
||||
"AES-256 GCM using mbedtls";
|
||||
|
||||
/*
|
||||
* This is the vector function table for this crypto engine.
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_gcm_128 = {
|
||||
srtp_aes_gcm_mbedtls_alloc,
|
||||
srtp_aes_gcm_mbedtls_dealloc,
|
||||
srtp_aes_gcm_mbedtls_context_init,
|
||||
srtp_aes_gcm_mbedtls_set_aad,
|
||||
srtp_aes_gcm_mbedtls_encrypt,
|
||||
srtp_aes_gcm_mbedtls_decrypt,
|
||||
srtp_aes_gcm_mbedtls_set_iv,
|
||||
srtp_aes_gcm_mbedtls_get_tag,
|
||||
srtp_aes_gcm_128_mbedtls_description,
|
||||
&srtp_aes_gcm_128_test_case_0,
|
||||
SRTP_AES_GCM_128
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the vector function table for this crypto engine.
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_gcm_256 = {
|
||||
srtp_aes_gcm_mbedtls_alloc,
|
||||
srtp_aes_gcm_mbedtls_dealloc,
|
||||
srtp_aes_gcm_mbedtls_context_init,
|
||||
srtp_aes_gcm_mbedtls_set_aad,
|
||||
srtp_aes_gcm_mbedtls_encrypt,
|
||||
srtp_aes_gcm_mbedtls_decrypt,
|
||||
srtp_aes_gcm_mbedtls_set_iv,
|
||||
srtp_aes_gcm_mbedtls_get_tag,
|
||||
srtp_aes_gcm_256_mbedtls_description,
|
||||
&srtp_aes_gcm_256_test_case_0,
|
||||
SRTP_AES_GCM_256
|
||||
};
|
||||
@@ -1,442 +0,0 @@
|
||||
/*
|
||||
* aes_gcm_nss.c
|
||||
*
|
||||
* AES Galois Counter Mode
|
||||
*
|
||||
* Richard L. Barnes
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "aes_gcm.h"
|
||||
#include "alloc.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "crypto_types.h"
|
||||
#include "cipher_types.h"
|
||||
#include "cipher_test_cases.h"
|
||||
#include <secerr.h>
|
||||
#include <nspr.h>
|
||||
|
||||
srtp_debug_module_t srtp_mod_aes_gcm = {
|
||||
0, /* debugging is off by default */
|
||||
"aes gcm nss" /* printable module name */
|
||||
};
|
||||
|
||||
/*
|
||||
* For now we only support 8 and 16 octet tags. The spec allows for
|
||||
* optional 12 byte tag, which may be supported in the future.
|
||||
*/
|
||||
#define GCM_IV_LEN 12
|
||||
#define GCM_AUTH_TAG_LEN 16
|
||||
#define GCM_AUTH_TAG_LEN_8 8
|
||||
|
||||
/*
|
||||
* This function allocates a new instance of this crypto engine.
|
||||
* The key_len parameter should be one of 28 or 44 for
|
||||
* AES-128-GCM or AES-256-GCM respectively. Note that the
|
||||
* key length includes the 14 byte salt value that is used when
|
||||
* initializing the KDF.
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_nss_alloc(srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *gcm;
|
||||
NSSInitContext *nss;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "allocating cipher with key length %d",
|
||||
key_len);
|
||||
debug_print(srtp_mod_aes_gcm, "allocating cipher with tag length %d", tlen);
|
||||
|
||||
/*
|
||||
* Verify the key_len is valid for one of: AES-128/256
|
||||
*/
|
||||
if (key_len != SRTP_AES_GCM_128_KEY_LEN_WSALT &&
|
||||
key_len != SRTP_AES_GCM_256_KEY_LEN_WSALT) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
if (tlen != GCM_AUTH_TAG_LEN && tlen != GCM_AUTH_TAG_LEN_8) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
/* Initialize NSS equiv of NSS_NoDB_Init(NULL) */
|
||||
nss = NSS_InitContext("", "", "", "", NULL,
|
||||
NSS_INIT_READONLY | NSS_INIT_NOCERTDB |
|
||||
NSS_INIT_NOMODDB | NSS_INIT_FORCEOPEN |
|
||||
NSS_INIT_OPTIMIZESPACE);
|
||||
if (!nss) {
|
||||
return (srtp_err_status_cipher_fail);
|
||||
}
|
||||
|
||||
/* allocate memory a cipher of type aes_gcm */
|
||||
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
|
||||
if (*c == NULL) {
|
||||
NSS_ShutdownContext(nss);
|
||||
return (srtp_err_status_alloc_fail);
|
||||
}
|
||||
|
||||
gcm = (srtp_aes_gcm_ctx_t *)srtp_crypto_alloc(sizeof(srtp_aes_gcm_ctx_t));
|
||||
if (gcm == NULL) {
|
||||
NSS_ShutdownContext(nss);
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return (srtp_err_status_alloc_fail);
|
||||
}
|
||||
|
||||
gcm->nss = nss;
|
||||
|
||||
/* set pointers */
|
||||
(*c)->state = gcm;
|
||||
|
||||
/* setup cipher attributes */
|
||||
switch (key_len) {
|
||||
case SRTP_AES_GCM_128_KEY_LEN_WSALT:
|
||||
(*c)->type = &srtp_aes_gcm_128;
|
||||
(*c)->algorithm = SRTP_AES_GCM_128;
|
||||
gcm->key_size = SRTP_AES_128_KEY_LEN;
|
||||
gcm->tag_size = tlen;
|
||||
gcm->params.ulTagBits = 8 * tlen;
|
||||
break;
|
||||
case SRTP_AES_GCM_256_KEY_LEN_WSALT:
|
||||
(*c)->type = &srtp_aes_gcm_256;
|
||||
(*c)->algorithm = SRTP_AES_GCM_256;
|
||||
gcm->key_size = SRTP_AES_256_KEY_LEN;
|
||||
gcm->tag_size = tlen;
|
||||
gcm->params.ulTagBits = 8 * tlen;
|
||||
break;
|
||||
default:
|
||||
/* this should never hit, but to be sure... */
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
/* set key size and tag size*/
|
||||
(*c)->key_len = key_len;
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function deallocates a GCM session
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_nss_dealloc(srtp_cipher_t *c)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *ctx;
|
||||
|
||||
ctx = (srtp_aes_gcm_ctx_t *)c->state;
|
||||
if (ctx) {
|
||||
/* release NSS resources */
|
||||
if (ctx->key) {
|
||||
PK11_FreeSymKey(ctx->key);
|
||||
}
|
||||
|
||||
if (ctx->nss) {
|
||||
NSS_ShutdownContext(ctx->nss);
|
||||
ctx->nss = NULL;
|
||||
}
|
||||
|
||||
/* zeroize the key material */
|
||||
octet_string_set_to_zero(ctx, sizeof(srtp_aes_gcm_ctx_t));
|
||||
srtp_crypto_free(ctx);
|
||||
}
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(c);
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_gcm_nss_context_init(...) initializes the aes_gcm_context
|
||||
* using the value in key[].
|
||||
*
|
||||
* the key is the secret key
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_nss_context_init(void *cv,
|
||||
const uint8_t *key)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
|
||||
c->dir = srtp_direction_any;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "key: %s",
|
||||
srtp_octet_string_hex_string(key, c->key_size));
|
||||
|
||||
if (c->key) {
|
||||
PK11_FreeSymKey(c->key);
|
||||
c->key = NULL;
|
||||
}
|
||||
|
||||
PK11SlotInfo *slot = PK11_GetBestSlot(CKM_AES_GCM, NULL);
|
||||
if (!slot) {
|
||||
return (srtp_err_status_cipher_fail);
|
||||
}
|
||||
|
||||
SECItem key_item = { siBuffer, (unsigned char *)key, c->key_size };
|
||||
c->key = PK11_ImportSymKey(slot, CKM_AES_GCM, PK11_OriginUnwrap,
|
||||
CKA_ENCRYPT, &key_item, NULL);
|
||||
PK11_FreeSlot(slot);
|
||||
|
||||
if (!c->key) {
|
||||
return (srtp_err_status_cipher_fail);
|
||||
}
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_gcm_nss_set_iv(c, iv) sets the counter value to the exor of iv with
|
||||
* the offset
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_nss_set_iv(
|
||||
void *cv,
|
||||
uint8_t *iv,
|
||||
srtp_cipher_direction_t direction)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
|
||||
if (direction != srtp_direction_encrypt &&
|
||||
direction != srtp_direction_decrypt) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
c->dir = direction;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "setting iv: %s",
|
||||
srtp_octet_string_hex_string(iv, GCM_IV_LEN));
|
||||
|
||||
memcpy(c->iv, iv, GCM_IV_LEN);
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function processes the AAD
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* aad Additional data to process for AEAD cipher suites
|
||||
* aad_len length of aad buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_nss_set_aad(void *cv,
|
||||
const uint8_t *aad,
|
||||
uint32_t aad_len)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "setting AAD: %s",
|
||||
srtp_octet_string_hex_string(aad, aad_len));
|
||||
|
||||
if (aad_len + c->aad_size > MAX_AD_SIZE) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
memcpy(c->aad + c->aad_size, aad, aad_len);
|
||||
c->aad_size += aad_len;
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_aes_gcm_nss_do_crypto(void *cv,
|
||||
int encrypt,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
|
||||
c->params.pIv = c->iv;
|
||||
c->params.ulIvLen = GCM_IV_LEN;
|
||||
c->params.pAAD = c->aad;
|
||||
c->params.ulAADLen = c->aad_size;
|
||||
|
||||
// Reset AAD
|
||||
c->aad_size = 0;
|
||||
|
||||
int rv;
|
||||
SECItem param = { siBuffer, (unsigned char *)&c->params,
|
||||
sizeof(CK_GCM_PARAMS) };
|
||||
if (encrypt) {
|
||||
rv = PK11_Encrypt(c->key, CKM_AES_GCM, ¶m, buf, enc_len,
|
||||
*enc_len + 16, buf, *enc_len);
|
||||
} else {
|
||||
rv = PK11_Decrypt(c->key, CKM_AES_GCM, ¶m, buf, enc_len, *enc_len,
|
||||
buf, *enc_len);
|
||||
}
|
||||
|
||||
srtp_err_status_t status = (srtp_err_status_ok);
|
||||
if (rv != SECSuccess) {
|
||||
status = (srtp_err_status_cipher_fail);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function encrypts a buffer using AES GCM mode
|
||||
*
|
||||
* XXX(rlb@ipv.sx): We're required to break off and cache the tag
|
||||
* here, because the get_tag() method is separate and the tests expect
|
||||
* encrypt() not to change the size of the plaintext. It might be
|
||||
* good to update the calling API so that this is cleaner.
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* enc_len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_nss_encrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
|
||||
// When we get a non-NULL buffer, we know that the caller is
|
||||
// prepared to also take the tag. When we get a NULL buffer,
|
||||
// even though there's no data, we need to give NSS a buffer
|
||||
// where it can write the tag. We can't just use c->tag because
|
||||
// memcpy has undefined behavior on overlapping ranges.
|
||||
unsigned char tagbuf[16];
|
||||
unsigned char *non_null_buf = buf;
|
||||
if (!non_null_buf && (*enc_len == 0)) {
|
||||
non_null_buf = tagbuf;
|
||||
} else if (!non_null_buf) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
srtp_err_status_t status =
|
||||
srtp_aes_gcm_nss_do_crypto(cv, 1, non_null_buf, enc_len);
|
||||
if (status != srtp_err_status_ok) {
|
||||
return status;
|
||||
}
|
||||
|
||||
memcpy(c->tag, non_null_buf + (*enc_len - c->tag_size), c->tag_size);
|
||||
*enc_len -= c->tag_size;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function calculates and returns the GCM tag for a given context.
|
||||
* This should be called after encrypting the data. The *len value
|
||||
* is increased by the tag size. The caller must ensure that *buf has
|
||||
* enough room to accept the appended tag.
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_nss_get_tag(void *cv,
|
||||
uint8_t *buf,
|
||||
uint32_t *len)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
*len = c->tag_size;
|
||||
memcpy(buf, c->tag, c->tag_size);
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function decrypts a buffer using AES GCM mode
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* enc_len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_nss_decrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
srtp_err_status_t status = srtp_aes_gcm_nss_do_crypto(cv, 0, buf, enc_len);
|
||||
if (status != srtp_err_status_ok) {
|
||||
int err = PR_GetError();
|
||||
if (err == SEC_ERROR_BAD_DATA) {
|
||||
status = srtp_err_status_auth_fail;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* Name of this crypto engine
|
||||
*/
|
||||
static const char srtp_aes_gcm_128_nss_description[] = "AES-128 GCM using NSS";
|
||||
static const char srtp_aes_gcm_256_nss_description[] = "AES-256 GCM using NSS";
|
||||
|
||||
/*
|
||||
* This is the vector function table for this crypto engine.
|
||||
*/
|
||||
/* clang-format off */
|
||||
const srtp_cipher_type_t srtp_aes_gcm_128 = {
|
||||
srtp_aes_gcm_nss_alloc,
|
||||
srtp_aes_gcm_nss_dealloc,
|
||||
srtp_aes_gcm_nss_context_init,
|
||||
srtp_aes_gcm_nss_set_aad,
|
||||
srtp_aes_gcm_nss_encrypt,
|
||||
srtp_aes_gcm_nss_decrypt,
|
||||
srtp_aes_gcm_nss_set_iv,
|
||||
srtp_aes_gcm_nss_get_tag,
|
||||
srtp_aes_gcm_128_nss_description,
|
||||
&srtp_aes_gcm_128_test_case_0,
|
||||
SRTP_AES_GCM_128
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/*
|
||||
* This is the vector function table for this crypto engine.
|
||||
*/
|
||||
/* clang-format off */
|
||||
const srtp_cipher_type_t srtp_aes_gcm_256 = {
|
||||
srtp_aes_gcm_nss_alloc,
|
||||
srtp_aes_gcm_nss_dealloc,
|
||||
srtp_aes_gcm_nss_context_init,
|
||||
srtp_aes_gcm_nss_set_aad,
|
||||
srtp_aes_gcm_nss_encrypt,
|
||||
srtp_aes_gcm_nss_decrypt,
|
||||
srtp_aes_gcm_nss_set_iv,
|
||||
srtp_aes_gcm_nss_get_tag,
|
||||
srtp_aes_gcm_256_nss_description,
|
||||
&srtp_aes_gcm_256_test_case_0,
|
||||
SRTP_AES_GCM_256
|
||||
};
|
||||
/* clang-format on */
|
||||
@@ -1,428 +0,0 @@
|
||||
/*
|
||||
* aes_gcm_ossl.c
|
||||
*
|
||||
* AES Galois Counter Mode
|
||||
*
|
||||
* John A. Foley
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include "aes_gcm.h"
|
||||
#include "alloc.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "crypto_types.h"
|
||||
#include "cipher_types.h"
|
||||
#include "cipher_test_cases.h"
|
||||
|
||||
srtp_debug_module_t srtp_mod_aes_gcm = {
|
||||
0, /* debugging is off by default */
|
||||
"aes gcm" /* printable module name */
|
||||
};
|
||||
|
||||
/*
|
||||
* For now we only support 8 and 16 octet tags. The spec allows for
|
||||
* optional 12 byte tag, which may be supported in the future.
|
||||
*/
|
||||
#define GCM_AUTH_TAG_LEN 16
|
||||
#define GCM_AUTH_TAG_LEN_8 8
|
||||
|
||||
/*
|
||||
* This function allocates a new instance of this crypto engine.
|
||||
* The key_len parameter should be one of 28 or 44 for
|
||||
* AES-128-GCM or AES-256-GCM respectively. Note that the
|
||||
* key length includes the 14 byte salt value that is used when
|
||||
* initializing the KDF.
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_alloc(srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *gcm;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "allocating cipher with key length %d",
|
||||
key_len);
|
||||
debug_print(srtp_mod_aes_gcm, "allocating cipher with tag length %d", tlen);
|
||||
|
||||
/*
|
||||
* Verify the key_len is valid for one of: AES-128/256
|
||||
*/
|
||||
if (key_len != SRTP_AES_GCM_128_KEY_LEN_WSALT &&
|
||||
key_len != SRTP_AES_GCM_256_KEY_LEN_WSALT) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
if (tlen != GCM_AUTH_TAG_LEN && tlen != GCM_AUTH_TAG_LEN_8) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
/* allocate memory a cipher of type aes_gcm */
|
||||
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
|
||||
if (*c == NULL) {
|
||||
return (srtp_err_status_alloc_fail);
|
||||
}
|
||||
|
||||
gcm = (srtp_aes_gcm_ctx_t *)srtp_crypto_alloc(sizeof(srtp_aes_gcm_ctx_t));
|
||||
if (gcm == NULL) {
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return (srtp_err_status_alloc_fail);
|
||||
}
|
||||
|
||||
gcm->ctx = EVP_CIPHER_CTX_new();
|
||||
if (gcm->ctx == NULL) {
|
||||
srtp_crypto_free(gcm);
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* set pointers */
|
||||
(*c)->state = gcm;
|
||||
|
||||
/* setup cipher attributes */
|
||||
switch (key_len) {
|
||||
case SRTP_AES_GCM_128_KEY_LEN_WSALT:
|
||||
(*c)->type = &srtp_aes_gcm_128;
|
||||
(*c)->algorithm = SRTP_AES_GCM_128;
|
||||
gcm->key_size = SRTP_AES_128_KEY_LEN;
|
||||
gcm->tag_len = tlen;
|
||||
break;
|
||||
case SRTP_AES_GCM_256_KEY_LEN_WSALT:
|
||||
(*c)->type = &srtp_aes_gcm_256;
|
||||
(*c)->algorithm = SRTP_AES_GCM_256;
|
||||
gcm->key_size = SRTP_AES_256_KEY_LEN;
|
||||
gcm->tag_len = tlen;
|
||||
break;
|
||||
}
|
||||
|
||||
/* set key size */
|
||||
(*c)->key_len = key_len;
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function deallocates a GCM session
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_dealloc(srtp_cipher_t *c)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *ctx;
|
||||
|
||||
ctx = (srtp_aes_gcm_ctx_t *)c->state;
|
||||
if (ctx) {
|
||||
EVP_CIPHER_CTX_free(ctx->ctx);
|
||||
/* zeroize the key material */
|
||||
octet_string_set_to_zero(ctx, sizeof(srtp_aes_gcm_ctx_t));
|
||||
srtp_crypto_free(ctx);
|
||||
}
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(c);
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_gcm_openssl_context_init(...) initializes the aes_gcm_context
|
||||
* using the value in key[].
|
||||
*
|
||||
* the key is the secret key
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_context_init(void *cv,
|
||||
const uint8_t *key)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
const EVP_CIPHER *evp;
|
||||
|
||||
c->dir = srtp_direction_any;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "key: %s",
|
||||
srtp_octet_string_hex_string(key, c->key_size));
|
||||
|
||||
switch (c->key_size) {
|
||||
case SRTP_AES_256_KEY_LEN:
|
||||
evp = EVP_aes_256_gcm();
|
||||
break;
|
||||
case SRTP_AES_128_KEY_LEN:
|
||||
evp = EVP_aes_128_gcm();
|
||||
break;
|
||||
default:
|
||||
return (srtp_err_status_bad_param);
|
||||
break;
|
||||
}
|
||||
|
||||
EVP_CIPHER_CTX_cleanup(c->ctx);
|
||||
if (!EVP_CipherInit_ex(c->ctx, evp, NULL, key, NULL, 0)) {
|
||||
return (srtp_err_status_init_fail);
|
||||
}
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_gcm_openssl_set_iv(c, iv) sets the counter value to the exor of iv with
|
||||
* the offset
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_set_iv(
|
||||
void *cv,
|
||||
uint8_t *iv,
|
||||
srtp_cipher_direction_t direction)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
|
||||
if (direction != srtp_direction_encrypt &&
|
||||
direction != srtp_direction_decrypt) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
c->dir = direction;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "setting iv: %s",
|
||||
srtp_octet_string_hex_string(iv, 12));
|
||||
|
||||
if (!EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_SET_IVLEN, 12, 0)) {
|
||||
return (srtp_err_status_init_fail);
|
||||
}
|
||||
|
||||
if (!EVP_CipherInit_ex(c->ctx, NULL, NULL, NULL, iv,
|
||||
(c->dir == srtp_direction_encrypt ? 1 : 0))) {
|
||||
return (srtp_err_status_init_fail);
|
||||
}
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function processes the AAD
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* aad Additional data to process for AEAD cipher suites
|
||||
* aad_len length of aad buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_set_aad(void *cv,
|
||||
const uint8_t *aad,
|
||||
uint32_t aad_len)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
int rv;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "setting AAD: %s",
|
||||
srtp_octet_string_hex_string(aad, aad_len));
|
||||
|
||||
/*
|
||||
* EVP_CTRL_GCM_SET_TAG can only be used when decrypting
|
||||
*/
|
||||
if (c->dir == srtp_direction_decrypt) {
|
||||
/*
|
||||
* Set dummy tag, OpenSSL requires the Tag to be set before
|
||||
* processing AAD
|
||||
*/
|
||||
|
||||
/*
|
||||
* OpenSSL never write to address pointed by the last parameter of
|
||||
* EVP_CIPHER_CTX_ctrl while EVP_CTRL_GCM_SET_TAG (in reality,
|
||||
* OpenSSL copy its content to the context), so we can make
|
||||
* aad read-only in this function and all its wrappers.
|
||||
*/
|
||||
unsigned char dummy_tag[GCM_AUTH_TAG_LEN];
|
||||
memset(dummy_tag, 0x0, GCM_AUTH_TAG_LEN);
|
||||
if (!EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_SET_TAG, c->tag_len,
|
||||
&dummy_tag)) {
|
||||
return (srtp_err_status_algo_fail);
|
||||
}
|
||||
}
|
||||
|
||||
rv = EVP_Cipher(c->ctx, NULL, aad, aad_len);
|
||||
if (rv != aad_len) {
|
||||
return (srtp_err_status_algo_fail);
|
||||
} else {
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function encrypts a buffer using AES GCM mode
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* enc_len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_encrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
if (c->dir != srtp_direction_encrypt && c->dir != srtp_direction_decrypt) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
/*
|
||||
* Encrypt the data
|
||||
*/
|
||||
EVP_Cipher(c->ctx, buf, buf, *enc_len);
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function calculates and returns the GCM tag for a given context.
|
||||
* This should be called after encrypting the data. The *len value
|
||||
* is increased by the tag size. The caller must ensure that *buf has
|
||||
* enough room to accept the appended tag.
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_get_tag(void *cv,
|
||||
uint8_t *buf,
|
||||
uint32_t *len)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
/*
|
||||
* Calculate the tag
|
||||
*/
|
||||
EVP_Cipher(c->ctx, NULL, NULL, 0);
|
||||
|
||||
/*
|
||||
* Retreive the tag
|
||||
*/
|
||||
if (!EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_GET_TAG, c->tag_len, buf)) {
|
||||
return (srtp_err_status_algo_fail);
|
||||
}
|
||||
|
||||
/*
|
||||
* Increase encryption length by desired tag size
|
||||
*/
|
||||
*len = c->tag_len;
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function decrypts a buffer using AES GCM mode
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* enc_len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_decrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
if (c->dir != srtp_direction_encrypt && c->dir != srtp_direction_decrypt) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the tag before decrypting
|
||||
*/
|
||||
if (!EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_SET_TAG, c->tag_len,
|
||||
buf + (*enc_len - c->tag_len))) {
|
||||
return (srtp_err_status_auth_fail);
|
||||
}
|
||||
EVP_Cipher(c->ctx, buf, buf, *enc_len - c->tag_len);
|
||||
|
||||
/*
|
||||
* Check the tag
|
||||
*/
|
||||
if (EVP_Cipher(c->ctx, NULL, NULL, 0)) {
|
||||
return (srtp_err_status_auth_fail);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reduce the buffer size by the tag length since the tag
|
||||
* is not part of the original payload
|
||||
*/
|
||||
*enc_len -= c->tag_len;
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* Name of this crypto engine
|
||||
*/
|
||||
static const char srtp_aes_gcm_128_openssl_description[] =
|
||||
"AES-128 GCM using openssl";
|
||||
static const char srtp_aes_gcm_256_openssl_description[] =
|
||||
"AES-256 GCM using openssl";
|
||||
|
||||
/*
|
||||
* This is the vector function table for this crypto engine.
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_gcm_128 = {
|
||||
srtp_aes_gcm_openssl_alloc,
|
||||
srtp_aes_gcm_openssl_dealloc,
|
||||
srtp_aes_gcm_openssl_context_init,
|
||||
srtp_aes_gcm_openssl_set_aad,
|
||||
srtp_aes_gcm_openssl_encrypt,
|
||||
srtp_aes_gcm_openssl_decrypt,
|
||||
srtp_aes_gcm_openssl_set_iv,
|
||||
srtp_aes_gcm_openssl_get_tag,
|
||||
srtp_aes_gcm_128_openssl_description,
|
||||
&srtp_aes_gcm_128_test_case_0,
|
||||
SRTP_AES_GCM_128
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the vector function table for this crypto engine.
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_gcm_256 = {
|
||||
srtp_aes_gcm_openssl_alloc,
|
||||
srtp_aes_gcm_openssl_dealloc,
|
||||
srtp_aes_gcm_openssl_context_init,
|
||||
srtp_aes_gcm_openssl_set_aad,
|
||||
srtp_aes_gcm_openssl_encrypt,
|
||||
srtp_aes_gcm_openssl_decrypt,
|
||||
srtp_aes_gcm_openssl_set_iv,
|
||||
srtp_aes_gcm_openssl_get_tag,
|
||||
srtp_aes_gcm_256_openssl_description,
|
||||
&srtp_aes_gcm_256_test_case_0,
|
||||
SRTP_AES_GCM_256
|
||||
};
|
||||
@@ -1,433 +0,0 @@
|
||||
/*
|
||||
* aes_icm.c
|
||||
*
|
||||
* AES Integer Counter Mode
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#define ALIGN_32 0
|
||||
|
||||
#include "aes_icm.h"
|
||||
#include "alloc.h"
|
||||
#include "cipher_types.h"
|
||||
#include "cipher_test_cases.h"
|
||||
|
||||
srtp_debug_module_t srtp_mod_aes_icm = {
|
||||
0, /* debugging is off by default */
|
||||
"aes icm" /* printable module name */
|
||||
};
|
||||
|
||||
/*
|
||||
* integer counter mode works as follows:
|
||||
*
|
||||
* 16 bits
|
||||
* <----->
|
||||
* +------+------+------+------+------+------+------+------+
|
||||
* | nonce | pakcet index | ctr |---+
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* |
|
||||
* +------+------+------+------+------+------+------+------+ v
|
||||
* | salt |000000|->(+)
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* |
|
||||
* +---------+
|
||||
* | encrypt |
|
||||
* +---------+
|
||||
* |
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* | keystream block |<--+
|
||||
* +------+------+------+------+------+------+------+------+
|
||||
*
|
||||
* All fields are big-endian
|
||||
*
|
||||
* ctr is the block counter, which increments from zero for
|
||||
* each packet (16 bits wide)
|
||||
*
|
||||
* packet index is distinct for each packet (48 bits wide)
|
||||
*
|
||||
* nonce can be distinct across many uses of the same key, or
|
||||
* can be a fixed value per key, or can be per-packet randomness
|
||||
* (64 bits)
|
||||
*
|
||||
*/
|
||||
|
||||
static srtp_err_status_t srtp_aes_icm_alloc(srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *icm;
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "allocating cipher with key length %d",
|
||||
key_len);
|
||||
|
||||
/*
|
||||
* The check for key_len = 30/46 does not apply. Our usage
|
||||
* of aes functions with key_len = values other than 30
|
||||
* has not broken anything. Don't know what would be the
|
||||
* effect of skipping this check for srtp in general.
|
||||
*/
|
||||
if (key_len != SRTP_AES_ICM_128_KEY_LEN_WSALT &&
|
||||
key_len != SRTP_AES_ICM_256_KEY_LEN_WSALT) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* allocate memory a cipher of type aes_icm */
|
||||
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
|
||||
if (*c == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
icm = (srtp_aes_icm_ctx_t *)srtp_crypto_alloc(sizeof(srtp_aes_icm_ctx_t));
|
||||
if (icm == NULL) {
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* set pointers */
|
||||
(*c)->state = icm;
|
||||
|
||||
switch (key_len) {
|
||||
case SRTP_AES_ICM_256_KEY_LEN_WSALT:
|
||||
(*c)->algorithm = SRTP_AES_ICM_256;
|
||||
(*c)->type = &srtp_aes_icm_256;
|
||||
break;
|
||||
default:
|
||||
(*c)->algorithm = SRTP_AES_ICM_128;
|
||||
(*c)->type = &srtp_aes_icm_128;
|
||||
break;
|
||||
}
|
||||
|
||||
/* set key size */
|
||||
icm->key_size = key_len;
|
||||
(*c)->key_len = key_len;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_aes_icm_dealloc(srtp_cipher_t *c)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *ctx;
|
||||
|
||||
if (c == NULL) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
ctx = (srtp_aes_icm_ctx_t *)c->state;
|
||||
if (ctx) {
|
||||
/* zeroize the key material */
|
||||
octet_string_set_to_zero(ctx, sizeof(srtp_aes_icm_ctx_t));
|
||||
srtp_crypto_free(ctx);
|
||||
}
|
||||
|
||||
/* free the cipher context */
|
||||
srtp_crypto_free(c);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_icm_context_init(...) initializes the aes_icm_context
|
||||
* using the value in key[].
|
||||
*
|
||||
* the key is the secret key
|
||||
*
|
||||
* the salt is unpredictable (but not necessarily secret) data which
|
||||
* randomizes the starting point in the keystream
|
||||
*/
|
||||
|
||||
static srtp_err_status_t srtp_aes_icm_context_init(void *cv, const uint8_t *key)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
srtp_err_status_t status;
|
||||
int base_key_len, copy_len;
|
||||
|
||||
if (c->key_size == SRTP_AES_ICM_128_KEY_LEN_WSALT ||
|
||||
c->key_size == SRTP_AES_ICM_256_KEY_LEN_WSALT) {
|
||||
base_key_len = c->key_size - SRTP_SALT_LEN;
|
||||
} else {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/*
|
||||
* set counter and initial values to 'offset' value, being careful not to
|
||||
* go past the end of the key buffer
|
||||
*/
|
||||
v128_set_to_zero(&c->counter);
|
||||
v128_set_to_zero(&c->offset);
|
||||
|
||||
copy_len = c->key_size - base_key_len;
|
||||
/* force last two octets of the offset to be left zero (for srtp
|
||||
* compatibility) */
|
||||
if (copy_len > SRTP_SALT_LEN) {
|
||||
copy_len = SRTP_SALT_LEN;
|
||||
}
|
||||
|
||||
memcpy(&c->counter, key + base_key_len, copy_len);
|
||||
memcpy(&c->offset, key + base_key_len, copy_len);
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "key: %s",
|
||||
srtp_octet_string_hex_string(key, base_key_len));
|
||||
debug_print(srtp_mod_aes_icm, "offset: %s", v128_hex_string(&c->offset));
|
||||
|
||||
/* expand key */
|
||||
status =
|
||||
srtp_aes_expand_encryption_key(key, base_key_len, &c->expanded_key);
|
||||
if (status) {
|
||||
v128_set_to_zero(&c->counter);
|
||||
v128_set_to_zero(&c->offset);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* indicate that the keystream_buffer is empty */
|
||||
c->bytes_in_buffer = 0;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_icm_set_iv(c, iv) sets the counter value to the exor of iv with
|
||||
* the offset
|
||||
*/
|
||||
|
||||
static srtp_err_status_t srtp_aes_icm_set_iv(void *cv,
|
||||
uint8_t *iv,
|
||||
srtp_cipher_direction_t direction)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
v128_t nonce;
|
||||
|
||||
/* set nonce (for alignment) */
|
||||
v128_copy_octet_string(&nonce, iv);
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "setting iv: %s", v128_hex_string(&nonce));
|
||||
|
||||
v128_xor(&c->counter, &c->offset, &nonce);
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "set_counter: %s",
|
||||
v128_hex_string(&c->counter));
|
||||
|
||||
/* indicate that the keystream_buffer is empty */
|
||||
c->bytes_in_buffer = 0;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_icm_advance(...) refills the keystream_buffer and
|
||||
* advances the block index of the sicm_context forward by one
|
||||
*
|
||||
* this is an internal, hopefully inlined function
|
||||
*/
|
||||
static void srtp_aes_icm_advance(srtp_aes_icm_ctx_t *c)
|
||||
{
|
||||
/* fill buffer with new keystream */
|
||||
v128_copy(&c->keystream_buffer, &c->counter);
|
||||
srtp_aes_encrypt(&c->keystream_buffer, &c->expanded_key);
|
||||
c->bytes_in_buffer = sizeof(v128_t);
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "counter: %s",
|
||||
v128_hex_string(&c->counter));
|
||||
debug_print(srtp_mod_aes_icm, "ciphertext: %s",
|
||||
v128_hex_string(&c->keystream_buffer));
|
||||
|
||||
/* clock counter forward */
|
||||
if (!++(c->counter.v8[15])) {
|
||||
++(c->counter.v8[14]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* icm_encrypt deals with the following cases:
|
||||
*
|
||||
* bytes_to_encr < bytes_in_buffer
|
||||
* - add keystream into data
|
||||
*
|
||||
* bytes_to_encr > bytes_in_buffer
|
||||
* - add keystream into data until keystream_buffer is depleted
|
||||
* - loop over blocks, filling keystream_buffer and then
|
||||
* adding keystream into data
|
||||
* - fill buffer then add in remaining (< 16) bytes of keystream
|
||||
*/
|
||||
|
||||
static srtp_err_status_t srtp_aes_icm_encrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
unsigned int bytes_to_encr = *enc_len;
|
||||
unsigned int i;
|
||||
uint32_t *b;
|
||||
|
||||
/* check that there's enough segment left*/
|
||||
if ((bytes_to_encr + htons(c->counter.v16[7])) > 0xffff) {
|
||||
return srtp_err_status_terminus;
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "block index: %d", htons(c->counter.v16[7]));
|
||||
if (bytes_to_encr <= (unsigned int)c->bytes_in_buffer) {
|
||||
/* deal with odd case of small bytes_to_encr */
|
||||
for (i = (sizeof(v128_t) - c->bytes_in_buffer);
|
||||
i < (sizeof(v128_t) - c->bytes_in_buffer + bytes_to_encr); i++) {
|
||||
*buf++ ^= c->keystream_buffer.v8[i];
|
||||
}
|
||||
|
||||
c->bytes_in_buffer -= bytes_to_encr;
|
||||
|
||||
/* return now to avoid the main loop */
|
||||
return srtp_err_status_ok;
|
||||
|
||||
} else {
|
||||
/* encrypt bytes until the remaining data is 16-byte aligned */
|
||||
for (i = (sizeof(v128_t) - c->bytes_in_buffer); i < sizeof(v128_t);
|
||||
i++) {
|
||||
*buf++ ^= c->keystream_buffer.v8[i];
|
||||
}
|
||||
|
||||
bytes_to_encr -= c->bytes_in_buffer;
|
||||
c->bytes_in_buffer = 0;
|
||||
}
|
||||
|
||||
/* now loop over entire 16-byte blocks of keystream */
|
||||
for (i = 0; i < (bytes_to_encr / sizeof(v128_t)); i++) {
|
||||
/* fill buffer with new keystream */
|
||||
srtp_aes_icm_advance(c);
|
||||
|
||||
/*
|
||||
* add keystream into the data buffer (this would be a lot faster
|
||||
* if we could assume 32-bit alignment!)
|
||||
*/
|
||||
|
||||
#if ALIGN_32
|
||||
b = (uint32_t *)buf;
|
||||
*b++ ^= c->keystream_buffer.v32[0];
|
||||
*b++ ^= c->keystream_buffer.v32[1];
|
||||
*b++ ^= c->keystream_buffer.v32[2];
|
||||
*b++ ^= c->keystream_buffer.v32[3];
|
||||
buf = (uint8_t *)b;
|
||||
#else
|
||||
if ((((uintptr_t)buf) & 0x03) != 0) {
|
||||
*buf++ ^= c->keystream_buffer.v8[0];
|
||||
*buf++ ^= c->keystream_buffer.v8[1];
|
||||
*buf++ ^= c->keystream_buffer.v8[2];
|
||||
*buf++ ^= c->keystream_buffer.v8[3];
|
||||
*buf++ ^= c->keystream_buffer.v8[4];
|
||||
*buf++ ^= c->keystream_buffer.v8[5];
|
||||
*buf++ ^= c->keystream_buffer.v8[6];
|
||||
*buf++ ^= c->keystream_buffer.v8[7];
|
||||
*buf++ ^= c->keystream_buffer.v8[8];
|
||||
*buf++ ^= c->keystream_buffer.v8[9];
|
||||
*buf++ ^= c->keystream_buffer.v8[10];
|
||||
*buf++ ^= c->keystream_buffer.v8[11];
|
||||
*buf++ ^= c->keystream_buffer.v8[12];
|
||||
*buf++ ^= c->keystream_buffer.v8[13];
|
||||
*buf++ ^= c->keystream_buffer.v8[14];
|
||||
*buf++ ^= c->keystream_buffer.v8[15];
|
||||
} else {
|
||||
b = (uint32_t *)buf;
|
||||
*b++ ^= c->keystream_buffer.v32[0];
|
||||
*b++ ^= c->keystream_buffer.v32[1];
|
||||
*b++ ^= c->keystream_buffer.v32[2];
|
||||
*b++ ^= c->keystream_buffer.v32[3];
|
||||
buf = (uint8_t *)b;
|
||||
}
|
||||
#endif /* #if ALIGN_32 */
|
||||
}
|
||||
|
||||
/* if there is a tail end of the data, process it */
|
||||
if ((bytes_to_encr & 0xf) != 0) {
|
||||
/* fill buffer with new keystream */
|
||||
srtp_aes_icm_advance(c);
|
||||
|
||||
for (i = 0; i < (bytes_to_encr & 0xf); i++) {
|
||||
*buf++ ^= c->keystream_buffer.v8[i];
|
||||
}
|
||||
|
||||
/* reset the keystream buffer size to right value */
|
||||
c->bytes_in_buffer = sizeof(v128_t) - i;
|
||||
} else {
|
||||
/* no tail, so just reset the keystream buffer size to zero */
|
||||
c->bytes_in_buffer = 0;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static const char srtp_aes_icm_128_description[] =
|
||||
"AES-128 integer counter mode";
|
||||
static const char srtp_aes_icm_256_description[] =
|
||||
"AES-256 integer counter mode";
|
||||
|
||||
/*
|
||||
* note: the encrypt function is identical to the decrypt function
|
||||
*/
|
||||
|
||||
const srtp_cipher_type_t srtp_aes_icm_128 = {
|
||||
srtp_aes_icm_alloc, /* */
|
||||
srtp_aes_icm_dealloc, /* */
|
||||
srtp_aes_icm_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_encrypt, /* */
|
||||
srtp_aes_icm_encrypt, /* */
|
||||
srtp_aes_icm_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_128_description, /* */
|
||||
&srtp_aes_icm_128_test_case_0, /* */
|
||||
SRTP_AES_ICM_128 /* */
|
||||
};
|
||||
|
||||
const srtp_cipher_type_t srtp_aes_icm_256 = {
|
||||
srtp_aes_icm_alloc, /* */
|
||||
srtp_aes_icm_dealloc, /* */
|
||||
srtp_aes_icm_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_encrypt, /* */
|
||||
srtp_aes_icm_encrypt, /* */
|
||||
srtp_aes_icm_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_256_description, /* */
|
||||
&srtp_aes_icm_256_test_case_0, /* */
|
||||
SRTP_AES_ICM_256 /* */
|
||||
};
|
||||
@@ -1,371 +0,0 @@
|
||||
/*
|
||||
* aes_icm_mbedtls.c
|
||||
*
|
||||
* AES Integer Counter Mode
|
||||
*
|
||||
* YongCheng Yang
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
#include <mbedtls/aes.h>
|
||||
#include "aes_icm_ext.h"
|
||||
#include "crypto_types.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "alloc.h"
|
||||
#include "cipher_types.h"
|
||||
#include "cipher_test_cases.h"
|
||||
|
||||
srtp_debug_module_t srtp_mod_aes_icm = {
|
||||
0, /* debugging is off by default */
|
||||
"aes icm mbedtls" /* printable module name */
|
||||
};
|
||||
|
||||
/*
|
||||
* integer counter mode works as follows:
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc3711#section-4.1.1
|
||||
*
|
||||
* E(k, IV) || E(k, IV + 1 mod 2^128) || E(k, IV + 2 mod 2^128) ...
|
||||
* IV = (k_s * 2^16) XOR (SSRC * 2^64) XOR (i * 2^16)
|
||||
*
|
||||
* IV SHALL be defined by the SSRC, the SRTP packet index i,
|
||||
* and the SRTP session salting key k_s.
|
||||
*
|
||||
* SSRC: 32bits.
|
||||
* Sequence number: 16bits.
|
||||
* nonce is 64bits. .
|
||||
* packet index = ROC || SEQ. (ROC: Rollover counter)
|
||||
*
|
||||
* 16 bits
|
||||
* <----->
|
||||
* +------+------+------+------+------+------+------+------+
|
||||
* | nonce | packet index | ctr |---+
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* |
|
||||
* +------+------+------+------+------+------+------+------+ v
|
||||
* | salt |000000|->(+)
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* |
|
||||
* +---------+
|
||||
* | encrypt |
|
||||
* +---------+
|
||||
* |
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* | keystream block |<--+
|
||||
* +------+------+------+------+------+------+------+------+
|
||||
*
|
||||
* All fields are big-endian
|
||||
*
|
||||
* ctr is the block counter, which increments from zero for
|
||||
* each packet (16 bits wide)
|
||||
*
|
||||
* packet index is distinct for each packet (48 bits wide)
|
||||
*
|
||||
* nonce can be distinct across many uses of the same key, or
|
||||
* can be a fixed value per key, or can be per-packet randomness
|
||||
* (64 bits)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This function allocates a new instance of this crypto engine.
|
||||
* The key_len parameter should be one of 30, 38, or 46 for
|
||||
* AES-128, AES-192, and AES-256 respectively. Note, this key_len
|
||||
* value is inflated, as it also accounts for the 112 bit salt
|
||||
* value. The tlen argument is for the AEAD tag length, which
|
||||
* isn't used in counter mode.
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_mbedtls_alloc(srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *icm;
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "allocating cipher with key length %d",
|
||||
key_len);
|
||||
|
||||
/*
|
||||
* Verify the key_len is valid for one of: AES-128/192/256
|
||||
*/
|
||||
if (key_len != SRTP_AES_ICM_128_KEY_LEN_WSALT &&
|
||||
key_len != SRTP_AES_ICM_192_KEY_LEN_WSALT &&
|
||||
key_len != SRTP_AES_ICM_256_KEY_LEN_WSALT) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* allocate memory a cipher of type aes_icm */
|
||||
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
|
||||
if (*c == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
icm = (srtp_aes_icm_ctx_t *)srtp_crypto_alloc(sizeof(srtp_aes_icm_ctx_t));
|
||||
if (icm == NULL) {
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
icm->ctx =
|
||||
(mbedtls_aes_context *)srtp_crypto_alloc(sizeof(mbedtls_aes_context));
|
||||
if (icm->ctx == NULL) {
|
||||
srtp_crypto_free(icm);
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
mbedtls_aes_init(icm->ctx);
|
||||
|
||||
/* set pointers */
|
||||
(*c)->state = icm;
|
||||
|
||||
/* setup cipher parameters */
|
||||
switch (key_len) {
|
||||
case SRTP_AES_ICM_128_KEY_LEN_WSALT:
|
||||
(*c)->algorithm = SRTP_AES_ICM_128;
|
||||
(*c)->type = &srtp_aes_icm_128;
|
||||
icm->key_size = SRTP_AES_128_KEY_LEN;
|
||||
break;
|
||||
case SRTP_AES_ICM_192_KEY_LEN_WSALT:
|
||||
(*c)->algorithm = SRTP_AES_ICM_192;
|
||||
(*c)->type = &srtp_aes_icm_192;
|
||||
icm->key_size = SRTP_AES_192_KEY_LEN;
|
||||
break;
|
||||
case SRTP_AES_ICM_256_KEY_LEN_WSALT:
|
||||
(*c)->algorithm = SRTP_AES_ICM_256;
|
||||
(*c)->type = &srtp_aes_icm_256;
|
||||
icm->key_size = SRTP_AES_256_KEY_LEN;
|
||||
break;
|
||||
}
|
||||
|
||||
/* set key size */
|
||||
(*c)->key_len = key_len;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function deallocates an instance of this engine
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_mbedtls_dealloc(srtp_cipher_t *c)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *ctx;
|
||||
|
||||
if (c == NULL) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the aes context
|
||||
*/
|
||||
ctx = (srtp_aes_icm_ctx_t *)c->state;
|
||||
if (ctx != NULL) {
|
||||
mbedtls_aes_free(ctx->ctx);
|
||||
srtp_crypto_free(ctx->ctx);
|
||||
/* zeroize the key material */
|
||||
octet_string_set_to_zero(ctx, sizeof(srtp_aes_icm_ctx_t));
|
||||
srtp_crypto_free(ctx);
|
||||
}
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(c);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_aes_icm_mbedtls_context_init(void *cv,
|
||||
const uint8_t *key)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
uint32_t key_size_in_bits = (c->key_size << 3);
|
||||
int errcode = 0;
|
||||
|
||||
/*
|
||||
* set counter and initial values to 'offset' value, being careful not to
|
||||
* go past the end of the key buffer
|
||||
*/
|
||||
v128_set_to_zero(&c->counter);
|
||||
v128_set_to_zero(&c->offset);
|
||||
memcpy(&c->counter, key + c->key_size, SRTP_SALT_LEN);
|
||||
memcpy(&c->offset, key + c->key_size, SRTP_SALT_LEN);
|
||||
|
||||
/* force last two octets of the offset to zero (for srtp compatibility) */
|
||||
c->offset.v8[SRTP_SALT_LEN] = c->offset.v8[SRTP_SALT_LEN + 1] = 0;
|
||||
c->counter.v8[SRTP_SALT_LEN] = c->counter.v8[SRTP_SALT_LEN + 1] = 0;
|
||||
debug_print(srtp_mod_aes_icm, "key: %s",
|
||||
srtp_octet_string_hex_string(key, c->key_size));
|
||||
debug_print(srtp_mod_aes_icm, "offset: %s", v128_hex_string(&c->offset));
|
||||
|
||||
switch (c->key_size) {
|
||||
case SRTP_AES_256_KEY_LEN:
|
||||
case SRTP_AES_192_KEY_LEN:
|
||||
case SRTP_AES_128_KEY_LEN:
|
||||
break;
|
||||
default:
|
||||
return srtp_err_status_bad_param;
|
||||
break;
|
||||
}
|
||||
|
||||
errcode = mbedtls_aes_setkey_enc(c->ctx, key, key_size_in_bits);
|
||||
if (errcode != 0) {
|
||||
debug_print(srtp_mod_aes_icm, "errCode: %d", errcode);
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_icm_set_iv(c, iv) sets the counter value to the exor of iv with
|
||||
* the offset
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_mbedtls_set_iv(
|
||||
void *cv,
|
||||
uint8_t *iv,
|
||||
srtp_cipher_direction_t dir)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
v128_t nonce;
|
||||
c->nc_off = 0;
|
||||
/* set nonce (for alignment) */
|
||||
v128_copy_octet_string(&nonce, iv);
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "setting iv: %s", v128_hex_string(&nonce));
|
||||
|
||||
v128_xor(&c->counter, &c->offset, &nonce);
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "set_counter: %s",
|
||||
v128_hex_string(&c->counter));
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function encrypts a buffer using AES CTR mode
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* enc_len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_mbedtls_encrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
|
||||
int errCode = 0;
|
||||
debug_print(srtp_mod_aes_icm, "rs0: %s", v128_hex_string(&c->counter));
|
||||
|
||||
errCode =
|
||||
mbedtls_aes_crypt_ctr(c->ctx, *enc_len, &(c->nc_off), c->counter.v8,
|
||||
c->stream_block.v8, buf, buf);
|
||||
if (errCode != 0) {
|
||||
debug_print(srtp_mod_aes_icm, "encrypt error: %d", errCode);
|
||||
return srtp_err_status_cipher_fail;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* Name of this crypto engine
|
||||
*/
|
||||
static const char srtp_aes_icm_128_mbedtls_description[] =
|
||||
"AES-128 counter mode using mbedtls";
|
||||
static const char srtp_aes_icm_192_mbedtls_description[] =
|
||||
"AES-192 counter mode using mbedtls";
|
||||
static const char srtp_aes_icm_256_mbedtls_description[] =
|
||||
"AES-256 counter mode using mbedtls";
|
||||
|
||||
/*
|
||||
* This is the function table for this crypto engine.
|
||||
* note: the encrypt function is identical to the decrypt function
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_icm_128 = {
|
||||
srtp_aes_icm_mbedtls_alloc, /* */
|
||||
srtp_aes_icm_mbedtls_dealloc, /* */
|
||||
srtp_aes_icm_mbedtls_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_mbedtls_encrypt, /* */
|
||||
srtp_aes_icm_mbedtls_encrypt, /* */
|
||||
srtp_aes_icm_mbedtls_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_128_mbedtls_description, /* */
|
||||
&srtp_aes_icm_128_test_case_0, /* */
|
||||
SRTP_AES_ICM_128 /* */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the function table for this crypto engine.
|
||||
* note: the encrypt function is identical to the decrypt function
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_icm_192 = {
|
||||
srtp_aes_icm_mbedtls_alloc, /* */
|
||||
srtp_aes_icm_mbedtls_dealloc, /* */
|
||||
srtp_aes_icm_mbedtls_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_mbedtls_encrypt, /* */
|
||||
srtp_aes_icm_mbedtls_encrypt, /* */
|
||||
srtp_aes_icm_mbedtls_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_192_mbedtls_description, /* */
|
||||
&srtp_aes_icm_192_test_case_0, /* */
|
||||
SRTP_AES_ICM_192 /* */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the function table for this crypto engine.
|
||||
* note: the encrypt function is identical to the decrypt function
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_icm_256 = {
|
||||
srtp_aes_icm_mbedtls_alloc, /* */
|
||||
srtp_aes_icm_mbedtls_dealloc, /* */
|
||||
srtp_aes_icm_mbedtls_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_mbedtls_encrypt, /* */
|
||||
srtp_aes_icm_mbedtls_encrypt, /* */
|
||||
srtp_aes_icm_mbedtls_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_256_mbedtls_description, /* */
|
||||
&srtp_aes_icm_256_test_case_0, /* */
|
||||
SRTP_AES_ICM_256 /* */
|
||||
};
|
||||
@@ -1,404 +0,0 @@
|
||||
/*
|
||||
* aes_icm_nss.c
|
||||
*
|
||||
* AES Integer Counter Mode
|
||||
*
|
||||
* Richard L. Barnes
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "aes_icm_ext.h"
|
||||
#include "crypto_types.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "alloc.h"
|
||||
#include "cipher_types.h"
|
||||
#include "cipher_test_cases.h"
|
||||
|
||||
srtp_debug_module_t srtp_mod_aes_icm = {
|
||||
0, /* debugging is off by default */
|
||||
"aes icm nss" /* printable module name */
|
||||
};
|
||||
|
||||
/*
|
||||
* integer counter mode works as follows:
|
||||
*
|
||||
* 16 bits
|
||||
* <----->
|
||||
* +------+------+------+------+------+------+------+------+
|
||||
* | nonce | packet index | ctr |---+
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* |
|
||||
* +------+------+------+------+------+------+------+------+ v
|
||||
* | salt |000000|->(+)
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* |
|
||||
* +---------+
|
||||
* | encrypt |
|
||||
* +---------+
|
||||
* |
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* | keystream block |<--+
|
||||
* +------+------+------+------+------+------+------+------+
|
||||
*
|
||||
* All fields are big-endian
|
||||
*
|
||||
* ctr is the block counter, which increments from zero for
|
||||
* each packet (16 bits wide)
|
||||
*
|
||||
* packet index is distinct for each packet (48 bits wide)
|
||||
*
|
||||
* nonce can be distinct across many uses of the same key, or
|
||||
* can be a fixed value per key, or can be per-packet randomness
|
||||
* (64 bits)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This function allocates a new instance of this crypto engine.
|
||||
* The key_len parameter should be one of 30, 38, or 46 for
|
||||
* AES-128, AES-192, and AES-256 respectively. Note, this key_len
|
||||
* value is inflated, as it also accounts for the 112 bit salt
|
||||
* value. The tlen argument is for the AEAD tag length, which
|
||||
* isn't used in counter mode.
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_nss_alloc(srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *icm;
|
||||
NSSInitContext *nss;
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "allocating cipher with key length %d",
|
||||
key_len);
|
||||
|
||||
/*
|
||||
* Verify the key_len is valid for one of: AES-128/192/256
|
||||
*/
|
||||
if (key_len != SRTP_AES_ICM_128_KEY_LEN_WSALT &&
|
||||
key_len != SRTP_AES_ICM_192_KEY_LEN_WSALT &&
|
||||
key_len != SRTP_AES_ICM_256_KEY_LEN_WSALT) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* Initialize NSS equiv of NSS_NoDB_Init(NULL) */
|
||||
nss = NSS_InitContext("", "", "", "", NULL,
|
||||
NSS_INIT_READONLY | NSS_INIT_NOCERTDB |
|
||||
NSS_INIT_NOMODDB | NSS_INIT_FORCEOPEN |
|
||||
NSS_INIT_OPTIMIZESPACE);
|
||||
if (!nss) {
|
||||
return (srtp_err_status_cipher_fail);
|
||||
}
|
||||
|
||||
/* allocate memory a cipher of type aes_icm */
|
||||
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
|
||||
if (*c == NULL) {
|
||||
NSS_ShutdownContext(nss);
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
icm = (srtp_aes_icm_ctx_t *)srtp_crypto_alloc(sizeof(srtp_aes_icm_ctx_t));
|
||||
if (icm == NULL) {
|
||||
NSS_ShutdownContext(nss);
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
icm->key = NULL;
|
||||
icm->ctx = NULL;
|
||||
icm->nss = nss;
|
||||
|
||||
/* set pointers */
|
||||
(*c)->state = icm;
|
||||
|
||||
/* setup cipher parameters */
|
||||
switch (key_len) {
|
||||
case SRTP_AES_ICM_128_KEY_LEN_WSALT:
|
||||
(*c)->algorithm = SRTP_AES_ICM_128;
|
||||
(*c)->type = &srtp_aes_icm_128;
|
||||
icm->key_size = SRTP_AES_128_KEY_LEN;
|
||||
break;
|
||||
case SRTP_AES_ICM_192_KEY_LEN_WSALT:
|
||||
(*c)->algorithm = SRTP_AES_ICM_192;
|
||||
(*c)->type = &srtp_aes_icm_192;
|
||||
icm->key_size = SRTP_AES_192_KEY_LEN;
|
||||
break;
|
||||
case SRTP_AES_ICM_256_KEY_LEN_WSALT:
|
||||
(*c)->algorithm = SRTP_AES_ICM_256;
|
||||
(*c)->type = &srtp_aes_icm_256;
|
||||
icm->key_size = SRTP_AES_256_KEY_LEN;
|
||||
break;
|
||||
}
|
||||
|
||||
/* set key size */
|
||||
(*c)->key_len = key_len;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function deallocates an instance of this engine
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_nss_dealloc(srtp_cipher_t *c)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *ctx;
|
||||
|
||||
ctx = (srtp_aes_icm_ctx_t *)c->state;
|
||||
if (ctx) {
|
||||
/* free any PK11 values that have been created */
|
||||
if (ctx->key) {
|
||||
PK11_FreeSymKey(ctx->key);
|
||||
ctx->key = NULL;
|
||||
}
|
||||
|
||||
if (ctx->ctx) {
|
||||
PK11_DestroyContext(ctx->ctx, PR_TRUE);
|
||||
ctx->ctx = NULL;
|
||||
}
|
||||
|
||||
if (ctx->nss) {
|
||||
NSS_ShutdownContext(ctx->nss);
|
||||
ctx->nss = NULL;
|
||||
}
|
||||
|
||||
/* zeroize everything */
|
||||
octet_string_set_to_zero(ctx, sizeof(srtp_aes_icm_ctx_t));
|
||||
srtp_crypto_free(ctx);
|
||||
}
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(c);
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_icm_nss_context_init(...) initializes the aes_icm_context
|
||||
* using the value in key[].
|
||||
*
|
||||
* the key is the secret key
|
||||
*
|
||||
* the salt is unpredictable (but not necessarily secret) data which
|
||||
* randomizes the starting point in the keystream
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_nss_context_init(void *cv,
|
||||
const uint8_t *key)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
|
||||
/*
|
||||
* set counter and initial values to 'offset' value, being careful not to
|
||||
* go past the end of the key buffer
|
||||
*/
|
||||
v128_set_to_zero(&c->counter);
|
||||
v128_set_to_zero(&c->offset);
|
||||
memcpy(&c->counter, key + c->key_size, SRTP_SALT_LEN);
|
||||
memcpy(&c->offset, key + c->key_size, SRTP_SALT_LEN);
|
||||
|
||||
/* force last two octets of the offset to zero (for srtp compatibility) */
|
||||
c->offset.v8[SRTP_SALT_LEN] = c->offset.v8[SRTP_SALT_LEN + 1] = 0;
|
||||
c->counter.v8[SRTP_SALT_LEN] = c->counter.v8[SRTP_SALT_LEN + 1] = 0;
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "key: %s",
|
||||
srtp_octet_string_hex_string(key, c->key_size));
|
||||
debug_print(srtp_mod_aes_icm, "offset: %s", v128_hex_string(&c->offset));
|
||||
|
||||
if (c->key) {
|
||||
PK11_FreeSymKey(c->key);
|
||||
c->key = NULL;
|
||||
}
|
||||
|
||||
PK11SlotInfo *slot = PK11_GetBestSlot(CKM_AES_CTR, NULL);
|
||||
if (!slot) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
SECItem keyItem = { siBuffer, (unsigned char *)key, c->key_size };
|
||||
c->key = PK11_ImportSymKey(slot, CKM_AES_CTR, PK11_OriginUnwrap,
|
||||
CKA_ENCRYPT, &keyItem, NULL);
|
||||
PK11_FreeSlot(slot);
|
||||
|
||||
if (!c->key) {
|
||||
return srtp_err_status_cipher_fail;
|
||||
}
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_icm_set_iv(c, iv) sets the counter value to the exor of iv with
|
||||
* the offset
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_nss_set_iv(void *cv,
|
||||
uint8_t *iv,
|
||||
srtp_cipher_direction_t dir)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
v128_t nonce;
|
||||
|
||||
/* set nonce (for alignment) */
|
||||
v128_copy_octet_string(&nonce, iv);
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "setting iv: %s", v128_hex_string(&nonce));
|
||||
|
||||
v128_xor(&c->counter, &c->offset, &nonce);
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "set_counter: %s",
|
||||
v128_hex_string(&c->counter));
|
||||
|
||||
/* set up the PK11 context now that we have all the info */
|
||||
CK_AES_CTR_PARAMS param;
|
||||
param.ulCounterBits = 16;
|
||||
memcpy(param.cb, &c->counter, 16);
|
||||
|
||||
if (!c->key) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
if (c->ctx) {
|
||||
PK11_DestroyContext(c->ctx, PR_TRUE);
|
||||
}
|
||||
|
||||
SECItem paramItem = { siBuffer, (unsigned char *)¶m,
|
||||
sizeof(CK_AES_CTR_PARAMS) };
|
||||
c->ctx = PK11_CreateContextBySymKey(CKM_AES_CTR, CKA_ENCRYPT, c->key,
|
||||
¶mItem);
|
||||
if (!c->ctx) {
|
||||
return srtp_err_status_cipher_fail;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function encrypts a buffer using AES CTR mode
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* enc_len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_nss_encrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
|
||||
if (!c->ctx) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
int rv =
|
||||
PK11_CipherOp(c->ctx, buf, (int *)enc_len, *enc_len, buf, *enc_len);
|
||||
|
||||
srtp_err_status_t status = (srtp_err_status_ok);
|
||||
if (rv != SECSuccess) {
|
||||
status = (srtp_err_status_cipher_fail);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* Name of this crypto engine
|
||||
*/
|
||||
static const char srtp_aes_icm_128_nss_description[] =
|
||||
"AES-128 counter mode using NSS";
|
||||
static const char srtp_aes_icm_192_nss_description[] =
|
||||
"AES-192 counter mode using NSS";
|
||||
static const char srtp_aes_icm_256_nss_description[] =
|
||||
"AES-256 counter mode using NSS";
|
||||
|
||||
/*
|
||||
* This is the function table for this crypto engine.
|
||||
* note: the encrypt function is identical to the decrypt function
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_icm_128 = {
|
||||
srtp_aes_icm_nss_alloc, /* */
|
||||
srtp_aes_icm_nss_dealloc, /* */
|
||||
srtp_aes_icm_nss_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_nss_encrypt, /* */
|
||||
srtp_aes_icm_nss_encrypt, /* */
|
||||
srtp_aes_icm_nss_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_128_nss_description, /* */
|
||||
&srtp_aes_icm_128_test_case_0, /* */
|
||||
SRTP_AES_ICM_128 /* */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the function table for this crypto engine.
|
||||
* note: the encrypt function is identical to the decrypt function
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_icm_192 = {
|
||||
srtp_aes_icm_nss_alloc, /* */
|
||||
srtp_aes_icm_nss_dealloc, /* */
|
||||
srtp_aes_icm_nss_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_nss_encrypt, /* */
|
||||
srtp_aes_icm_nss_encrypt, /* */
|
||||
srtp_aes_icm_nss_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_192_nss_description, /* */
|
||||
&srtp_aes_icm_192_test_case_0, /* */
|
||||
SRTP_AES_ICM_192 /* */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the function table for this crypto engine.
|
||||
* note: the encrypt function is identical to the decrypt function
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_icm_256 = {
|
||||
srtp_aes_icm_nss_alloc, /* */
|
||||
srtp_aes_icm_nss_dealloc, /* */
|
||||
srtp_aes_icm_nss_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_nss_encrypt, /* */
|
||||
srtp_aes_icm_nss_encrypt, /* */
|
||||
srtp_aes_icm_nss_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_256_nss_description, /* */
|
||||
&srtp_aes_icm_256_test_case_0, /* */
|
||||
SRTP_AES_ICM_256 /* */
|
||||
};
|
||||
@@ -1,383 +0,0 @@
|
||||
/*
|
||||
* aes_icm_ossl.c
|
||||
*
|
||||
* AES Integer Counter Mode
|
||||
*
|
||||
* John A. Foley
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
* 2/24/2012: This module was modified to use CiscoSSL for AES counter
|
||||
* mode. Eddy Lem contributed the code to allow this.
|
||||
*
|
||||
* 12/20/2012: Added support for AES-192 and AES-256.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include "aes_icm_ext.h"
|
||||
#include "crypto_types.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "alloc.h"
|
||||
#include "cipher_types.h"
|
||||
#include "cipher_test_cases.h"
|
||||
|
||||
srtp_debug_module_t srtp_mod_aes_icm = {
|
||||
0, /* debugging is off by default */
|
||||
"aes icm ossl" /* printable module name */
|
||||
};
|
||||
|
||||
/*
|
||||
* integer counter mode works as follows:
|
||||
*
|
||||
* 16 bits
|
||||
* <----->
|
||||
* +------+------+------+------+------+------+------+------+
|
||||
* | nonce | packet index | ctr |---+
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* |
|
||||
* +------+------+------+------+------+------+------+------+ v
|
||||
* | salt |000000|->(+)
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* |
|
||||
* +---------+
|
||||
* | encrypt |
|
||||
* +---------+
|
||||
* |
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* | keystream block |<--+
|
||||
* +------+------+------+------+------+------+------+------+
|
||||
*
|
||||
* All fields are big-endian
|
||||
*
|
||||
* ctr is the block counter, which increments from zero for
|
||||
* each packet (16 bits wide)
|
||||
*
|
||||
* packet index is distinct for each packet (48 bits wide)
|
||||
*
|
||||
* nonce can be distinct across many uses of the same key, or
|
||||
* can be a fixed value per key, or can be per-packet randomness
|
||||
* (64 bits)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This function allocates a new instance of this crypto engine.
|
||||
* The key_len parameter should be one of 30, 38, or 46 for
|
||||
* AES-128, AES-192, and AES-256 respectively. Note, this key_len
|
||||
* value is inflated, as it also accounts for the 112 bit salt
|
||||
* value. The tlen argument is for the AEAD tag length, which
|
||||
* isn't used in counter mode.
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_openssl_alloc(srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *icm;
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "allocating cipher with key length %d",
|
||||
key_len);
|
||||
|
||||
/*
|
||||
* Verify the key_len is valid for one of: AES-128/192/256
|
||||
*/
|
||||
if (key_len != SRTP_AES_ICM_128_KEY_LEN_WSALT &&
|
||||
key_len != SRTP_AES_ICM_192_KEY_LEN_WSALT &&
|
||||
key_len != SRTP_AES_ICM_256_KEY_LEN_WSALT) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* allocate memory a cipher of type aes_icm */
|
||||
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
|
||||
if (*c == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
icm = (srtp_aes_icm_ctx_t *)srtp_crypto_alloc(sizeof(srtp_aes_icm_ctx_t));
|
||||
if (icm == NULL) {
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
icm->ctx = EVP_CIPHER_CTX_new();
|
||||
if (icm->ctx == NULL) {
|
||||
srtp_crypto_free(icm);
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* set pointers */
|
||||
(*c)->state = icm;
|
||||
|
||||
/* setup cipher parameters */
|
||||
switch (key_len) {
|
||||
case SRTP_AES_ICM_128_KEY_LEN_WSALT:
|
||||
(*c)->algorithm = SRTP_AES_ICM_128;
|
||||
(*c)->type = &srtp_aes_icm_128;
|
||||
icm->key_size = SRTP_AES_128_KEY_LEN;
|
||||
break;
|
||||
case SRTP_AES_ICM_192_KEY_LEN_WSALT:
|
||||
(*c)->algorithm = SRTP_AES_ICM_192;
|
||||
(*c)->type = &srtp_aes_icm_192;
|
||||
icm->key_size = SRTP_AES_192_KEY_LEN;
|
||||
break;
|
||||
case SRTP_AES_ICM_256_KEY_LEN_WSALT:
|
||||
(*c)->algorithm = SRTP_AES_ICM_256;
|
||||
(*c)->type = &srtp_aes_icm_256;
|
||||
icm->key_size = SRTP_AES_256_KEY_LEN;
|
||||
break;
|
||||
}
|
||||
|
||||
/* set key size */
|
||||
(*c)->key_len = key_len;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function deallocates an instance of this engine
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_openssl_dealloc(srtp_cipher_t *c)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *ctx;
|
||||
|
||||
if (c == NULL) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the EVP context
|
||||
*/
|
||||
ctx = (srtp_aes_icm_ctx_t *)c->state;
|
||||
if (ctx != NULL) {
|
||||
EVP_CIPHER_CTX_free(ctx->ctx);
|
||||
/* zeroize the key material */
|
||||
octet_string_set_to_zero(ctx, sizeof(srtp_aes_icm_ctx_t));
|
||||
srtp_crypto_free(ctx);
|
||||
}
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(c);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_icm_openssl_context_init(...) initializes the aes_icm_context
|
||||
* using the value in key[].
|
||||
*
|
||||
* the key is the secret key
|
||||
*
|
||||
* the salt is unpredictable (but not necessarily secret) data which
|
||||
* randomizes the starting point in the keystream
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_openssl_context_init(void *cv,
|
||||
const uint8_t *key)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
const EVP_CIPHER *evp;
|
||||
|
||||
/*
|
||||
* set counter and initial values to 'offset' value, being careful not to
|
||||
* go past the end of the key buffer
|
||||
*/
|
||||
v128_set_to_zero(&c->counter);
|
||||
v128_set_to_zero(&c->offset);
|
||||
memcpy(&c->counter, key + c->key_size, SRTP_SALT_LEN);
|
||||
memcpy(&c->offset, key + c->key_size, SRTP_SALT_LEN);
|
||||
|
||||
/* force last two octets of the offset to zero (for srtp compatibility) */
|
||||
c->offset.v8[SRTP_SALT_LEN] = c->offset.v8[SRTP_SALT_LEN + 1] = 0;
|
||||
c->counter.v8[SRTP_SALT_LEN] = c->counter.v8[SRTP_SALT_LEN + 1] = 0;
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "key: %s",
|
||||
srtp_octet_string_hex_string(key, c->key_size));
|
||||
debug_print(srtp_mod_aes_icm, "offset: %s", v128_hex_string(&c->offset));
|
||||
|
||||
switch (c->key_size) {
|
||||
case SRTP_AES_256_KEY_LEN:
|
||||
evp = EVP_aes_256_ctr();
|
||||
break;
|
||||
case SRTP_AES_192_KEY_LEN:
|
||||
evp = EVP_aes_192_ctr();
|
||||
break;
|
||||
case SRTP_AES_128_KEY_LEN:
|
||||
evp = EVP_aes_128_ctr();
|
||||
break;
|
||||
default:
|
||||
return srtp_err_status_bad_param;
|
||||
break;
|
||||
}
|
||||
|
||||
EVP_CIPHER_CTX_cleanup(c->ctx);
|
||||
if (!EVP_EncryptInit_ex(c->ctx, evp, NULL, key, NULL)) {
|
||||
return srtp_err_status_fail;
|
||||
} else {
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_icm_set_iv(c, iv) sets the counter value to the exor of iv with
|
||||
* the offset
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_openssl_set_iv(
|
||||
void *cv,
|
||||
uint8_t *iv,
|
||||
srtp_cipher_direction_t dir)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
v128_t nonce;
|
||||
|
||||
/* set nonce (for alignment) */
|
||||
v128_copy_octet_string(&nonce, iv);
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "setting iv: %s", v128_hex_string(&nonce));
|
||||
|
||||
v128_xor(&c->counter, &c->offset, &nonce);
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "set_counter: %s",
|
||||
v128_hex_string(&c->counter));
|
||||
|
||||
if (!EVP_EncryptInit_ex(c->ctx, NULL, NULL, NULL, c->counter.v8)) {
|
||||
return srtp_err_status_fail;
|
||||
} else {
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function encrypts a buffer using AES CTR mode
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* enc_len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_openssl_encrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
int len = 0;
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "rs0: %s", v128_hex_string(&c->counter));
|
||||
|
||||
if (!EVP_EncryptUpdate(c->ctx, buf, &len, buf, *enc_len)) {
|
||||
return srtp_err_status_cipher_fail;
|
||||
}
|
||||
*enc_len = len;
|
||||
|
||||
if (!EVP_EncryptFinal_ex(c->ctx, buf + len, &len)) {
|
||||
return srtp_err_status_cipher_fail;
|
||||
}
|
||||
*enc_len += len;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* Name of this crypto engine
|
||||
*/
|
||||
static const char srtp_aes_icm_128_openssl_description[] =
|
||||
"AES-128 counter mode using openssl";
|
||||
static const char srtp_aes_icm_192_openssl_description[] =
|
||||
"AES-192 counter mode using openssl";
|
||||
static const char srtp_aes_icm_256_openssl_description[] =
|
||||
"AES-256 counter mode using openssl";
|
||||
|
||||
/*
|
||||
* This is the function table for this crypto engine.
|
||||
* note: the encrypt function is identical to the decrypt function
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_icm_128 = {
|
||||
srtp_aes_icm_openssl_alloc, /* */
|
||||
srtp_aes_icm_openssl_dealloc, /* */
|
||||
srtp_aes_icm_openssl_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_openssl_encrypt, /* */
|
||||
srtp_aes_icm_openssl_encrypt, /* */
|
||||
srtp_aes_icm_openssl_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_128_openssl_description, /* */
|
||||
&srtp_aes_icm_128_test_case_0, /* */
|
||||
SRTP_AES_ICM_128 /* */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the function table for this crypto engine.
|
||||
* note: the encrypt function is identical to the decrypt function
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_icm_192 = {
|
||||
srtp_aes_icm_openssl_alloc, /* */
|
||||
srtp_aes_icm_openssl_dealloc, /* */
|
||||
srtp_aes_icm_openssl_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_openssl_encrypt, /* */
|
||||
srtp_aes_icm_openssl_encrypt, /* */
|
||||
srtp_aes_icm_openssl_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_192_openssl_description, /* */
|
||||
&srtp_aes_icm_192_test_case_0, /* */
|
||||
SRTP_AES_ICM_192 /* */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the function table for this crypto engine.
|
||||
* note: the encrypt function is identical to the decrypt function
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_icm_256 = {
|
||||
srtp_aes_icm_openssl_alloc, /* */
|
||||
srtp_aes_icm_openssl_dealloc, /* */
|
||||
srtp_aes_icm_openssl_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_openssl_encrypt, /* */
|
||||
srtp_aes_icm_openssl_encrypt, /* */
|
||||
srtp_aes_icm_openssl_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_256_openssl_description, /* */
|
||||
&srtp_aes_icm_256_test_case_0, /* */
|
||||
SRTP_AES_ICM_256 /* */
|
||||
};
|
||||
@@ -1,664 +0,0 @@
|
||||
/*
|
||||
* cipher.c
|
||||
*
|
||||
* cipher meta-functions
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "cipher.h"
|
||||
#include "cipher_priv.h"
|
||||
#include "crypto_types.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "alloc.h" /* for crypto_alloc(), crypto_free() */
|
||||
|
||||
srtp_debug_module_t srtp_mod_cipher = {
|
||||
0, /* debugging is off by default */
|
||||
"cipher" /* printable module name */
|
||||
};
|
||||
|
||||
srtp_err_status_t srtp_cipher_type_alloc(const srtp_cipher_type_t *ct,
|
||||
srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen)
|
||||
{
|
||||
if (!ct || !ct->alloc) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
return ((ct)->alloc((c), (key_len), (tlen)));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_dealloc(srtp_cipher_t *c)
|
||||
{
|
||||
if (!c || !c->type) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
return (((c)->type)->dealloc(c));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_init(srtp_cipher_t *c, const uint8_t *key)
|
||||
{
|
||||
if (!c || !c->type || !c->state) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
return (((c)->type)->init(((c)->state), (key)));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_set_iv(srtp_cipher_t *c,
|
||||
uint8_t *iv,
|
||||
int direction)
|
||||
{
|
||||
if (!c || !c->type || !c->state) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
return (((c)->type)->set_iv(((c)->state), iv, direction));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_output(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *num_octets_to_output)
|
||||
{
|
||||
/* zeroize the buffer */
|
||||
octet_string_set_to_zero(buffer, *num_octets_to_output);
|
||||
|
||||
/* exor keystream into buffer */
|
||||
return (((c)->type)->encrypt(((c)->state), buffer, num_octets_to_output));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_encrypt(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *num_octets_to_output)
|
||||
{
|
||||
if (!c || !c->type || !c->state) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
return (((c)->type)->encrypt(((c)->state), buffer, num_octets_to_output));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_decrypt(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *num_octets_to_output)
|
||||
{
|
||||
if (!c || !c->type || !c->state) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
return (((c)->type)->decrypt(((c)->state), buffer, num_octets_to_output));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_get_tag(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *tag_len)
|
||||
{
|
||||
if (!c || !c->type || !c->state) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
if (!((c)->type)->get_tag) {
|
||||
return (srtp_err_status_no_such_op);
|
||||
}
|
||||
|
||||
return (((c)->type)->get_tag(((c)->state), buffer, tag_len));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_set_aad(srtp_cipher_t *c,
|
||||
const uint8_t *aad,
|
||||
uint32_t aad_len)
|
||||
{
|
||||
if (!c || !c->type || !c->state) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
if (!((c)->type)->set_aad) {
|
||||
return (srtp_err_status_no_such_op);
|
||||
}
|
||||
|
||||
return (((c)->type)->set_aad(((c)->state), aad, aad_len));
|
||||
}
|
||||
|
||||
/* some bookkeeping functions */
|
||||
|
||||
int srtp_cipher_get_key_length(const srtp_cipher_t *c)
|
||||
{
|
||||
return c->key_len;
|
||||
}
|
||||
|
||||
/*
|
||||
* A trivial platform independent random source.
|
||||
* For use in test only.
|
||||
*/
|
||||
void srtp_cipher_rand_for_tests(void *dest, uint32_t len)
|
||||
{
|
||||
/* Generic C-library (rand()) version */
|
||||
/* This is a random source of last resort */
|
||||
uint8_t *dst = (uint8_t *)dest;
|
||||
while (len) {
|
||||
int val = rand();
|
||||
/* rand() returns 0-32767 (ugh) */
|
||||
/* Is this a good enough way to get random bytes?
|
||||
It is if it passes FIPS-140... */
|
||||
*dst++ = val & 0xff;
|
||||
len--;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* A trivial platform independent 32 bit random number.
|
||||
* For use in test only.
|
||||
*/
|
||||
uint32_t srtp_cipher_rand_u32_for_tests(void)
|
||||
{
|
||||
uint32_t r;
|
||||
srtp_cipher_rand_for_tests(&r, sizeof(r));
|
||||
return r;
|
||||
}
|
||||
|
||||
#define SELF_TEST_BUF_OCTETS 128
|
||||
#define NUM_RAND_TESTS 128
|
||||
#define MAX_KEY_LEN 64
|
||||
/*
|
||||
* srtp_cipher_type_test(ct, test_data) tests a cipher of type ct against
|
||||
* test cases provided in a list test_data of values of key, salt, iv,
|
||||
* plaintext, and ciphertext that is known to be good
|
||||
*/
|
||||
srtp_err_status_t srtp_cipher_type_test(
|
||||
const srtp_cipher_type_t *ct,
|
||||
const srtp_cipher_test_case_t *test_data)
|
||||
{
|
||||
const srtp_cipher_test_case_t *test_case = test_data;
|
||||
srtp_cipher_t *c;
|
||||
srtp_err_status_t status;
|
||||
uint8_t buffer[SELF_TEST_BUF_OCTETS];
|
||||
uint8_t buffer2[SELF_TEST_BUF_OCTETS];
|
||||
uint32_t tag_len;
|
||||
unsigned int len;
|
||||
int i, j, case_num = 0;
|
||||
unsigned k = 0;
|
||||
|
||||
debug_print(srtp_mod_cipher, "running self-test for cipher %s",
|
||||
ct->description);
|
||||
|
||||
/*
|
||||
* check to make sure that we have at least one test case, and
|
||||
* return an error if we don't - we need to be paranoid here
|
||||
*/
|
||||
if (test_case == NULL) {
|
||||
return srtp_err_status_cant_check;
|
||||
}
|
||||
|
||||
/*
|
||||
* loop over all test cases, perform known-answer tests of both the
|
||||
* encryption and decryption functions
|
||||
*/
|
||||
while (test_case != NULL) {
|
||||
/* allocate cipher */
|
||||
status = srtp_cipher_type_alloc(ct, &c, test_case->key_length_octets,
|
||||
test_case->tag_length_octets);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* test the encrypt function
|
||||
*/
|
||||
debug_print0(srtp_mod_cipher, "testing encryption");
|
||||
|
||||
/* initialize cipher */
|
||||
status = srtp_cipher_init(c, test_case->key);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* copy plaintext into test buffer */
|
||||
if (test_case->ciphertext_length_octets > SELF_TEST_BUF_OCTETS) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
for (k = 0; k < test_case->plaintext_length_octets; k++) {
|
||||
buffer[k] = test_case->plaintext[k];
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_cipher, "plaintext: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
buffer, test_case->plaintext_length_octets));
|
||||
|
||||
/* set the initialization vector */
|
||||
status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx,
|
||||
srtp_direction_encrypt);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
if (c->algorithm == SRTP_AES_GCM_128 ||
|
||||
c->algorithm == SRTP_AES_GCM_256) {
|
||||
debug_print(srtp_mod_cipher, "IV: %s",
|
||||
srtp_octet_string_hex_string(test_case->idx, 12));
|
||||
|
||||
/*
|
||||
* Set the AAD
|
||||
*/
|
||||
status = srtp_cipher_set_aad(c, test_case->aad,
|
||||
test_case->aad_length_octets);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
debug_print(srtp_mod_cipher, "AAD: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->aad, test_case->aad_length_octets));
|
||||
}
|
||||
|
||||
/* encrypt */
|
||||
len = test_case->plaintext_length_octets;
|
||||
status = srtp_cipher_encrypt(c, buffer, &len);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
if (c->algorithm == SRTP_AES_GCM_128 ||
|
||||
c->algorithm == SRTP_AES_GCM_256) {
|
||||
/*
|
||||
* Get the GCM tag
|
||||
*/
|
||||
status = srtp_cipher_get_tag(c, buffer + len, &tag_len);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
len += tag_len;
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_cipher, "ciphertext: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
buffer, test_case->ciphertext_length_octets));
|
||||
|
||||
/* compare the resulting ciphertext with that in the test case */
|
||||
if (len != test_case->ciphertext_length_octets) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
status = srtp_err_status_ok;
|
||||
for (k = 0; k < test_case->ciphertext_length_octets; k++) {
|
||||
if (buffer[k] != test_case->ciphertext[k]) {
|
||||
status = srtp_err_status_algo_fail;
|
||||
debug_print(srtp_mod_cipher, "test case %d failed", case_num);
|
||||
debug_print(srtp_mod_cipher, "(failure at byte %u)", k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (status) {
|
||||
debug_print(srtp_mod_cipher, "c computed: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
buffer, 2 * test_case->plaintext_length_octets));
|
||||
debug_print(srtp_mod_cipher, "c expected: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->ciphertext,
|
||||
2 * test_case->plaintext_length_octets));
|
||||
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
|
||||
/*
|
||||
* test the decrypt function
|
||||
*/
|
||||
debug_print0(srtp_mod_cipher, "testing decryption");
|
||||
|
||||
/* re-initialize cipher for decryption */
|
||||
status = srtp_cipher_init(c, test_case->key);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* copy ciphertext into test buffer */
|
||||
if (test_case->ciphertext_length_octets > SELF_TEST_BUF_OCTETS) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
for (k = 0; k < test_case->ciphertext_length_octets; k++) {
|
||||
buffer[k] = test_case->ciphertext[k];
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_cipher, "ciphertext: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
buffer, test_case->plaintext_length_octets));
|
||||
|
||||
/* set the initialization vector */
|
||||
status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx,
|
||||
srtp_direction_decrypt);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
if (c->algorithm == SRTP_AES_GCM_128 ||
|
||||
c->algorithm == SRTP_AES_GCM_256) {
|
||||
/*
|
||||
* Set the AAD
|
||||
*/
|
||||
status = srtp_cipher_set_aad(c, test_case->aad,
|
||||
test_case->aad_length_octets);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
debug_print(srtp_mod_cipher, "AAD: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->aad, test_case->aad_length_octets));
|
||||
}
|
||||
|
||||
/* decrypt */
|
||||
len = test_case->ciphertext_length_octets;
|
||||
status = srtp_cipher_decrypt(c, buffer, &len);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_cipher, "plaintext: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
buffer, test_case->plaintext_length_octets));
|
||||
|
||||
/* compare the resulting plaintext with that in the test case */
|
||||
if (len != test_case->plaintext_length_octets) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
status = srtp_err_status_ok;
|
||||
for (k = 0; k < test_case->plaintext_length_octets; k++) {
|
||||
if (buffer[k] != test_case->plaintext[k]) {
|
||||
status = srtp_err_status_algo_fail;
|
||||
debug_print(srtp_mod_cipher, "test case %d failed", case_num);
|
||||
debug_print(srtp_mod_cipher, "(failure at byte %u)", k);
|
||||
}
|
||||
}
|
||||
if (status) {
|
||||
debug_print(srtp_mod_cipher, "p computed: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
buffer, 2 * test_case->plaintext_length_octets));
|
||||
debug_print(srtp_mod_cipher, "p expected: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->plaintext,
|
||||
2 * test_case->plaintext_length_octets));
|
||||
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
|
||||
/* deallocate the cipher */
|
||||
status = srtp_cipher_dealloc(c);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* the cipher passed the test case, so move on to the next test
|
||||
* case in the list; if NULL, we'l proceed to the next test
|
||||
*/
|
||||
test_case = test_case->next_test_case;
|
||||
++case_num;
|
||||
}
|
||||
|
||||
/* now run some random invertibility tests */
|
||||
|
||||
/* allocate cipher, using paramaters from the first test case */
|
||||
test_case = test_data;
|
||||
status = srtp_cipher_type_alloc(ct, &c, test_case->key_length_octets,
|
||||
test_case->tag_length_octets);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
for (j = 0; j < NUM_RAND_TESTS; j++) {
|
||||
unsigned int length;
|
||||
unsigned int plaintext_len;
|
||||
uint8_t key[MAX_KEY_LEN];
|
||||
uint8_t iv[MAX_KEY_LEN];
|
||||
|
||||
/* choose a length at random (leaving room for IV and padding) */
|
||||
length = srtp_cipher_rand_u32_for_tests() % (SELF_TEST_BUF_OCTETS - 64);
|
||||
debug_print(srtp_mod_cipher, "random plaintext length %d\n", length);
|
||||
srtp_cipher_rand_for_tests(buffer, length);
|
||||
|
||||
debug_print(srtp_mod_cipher, "plaintext: %s",
|
||||
srtp_octet_string_hex_string(buffer, length));
|
||||
|
||||
/* copy plaintext into second buffer */
|
||||
for (i = 0; (unsigned int)i < length; i++) {
|
||||
buffer2[i] = buffer[i];
|
||||
}
|
||||
|
||||
/* choose a key at random */
|
||||
if (test_case->key_length_octets > MAX_KEY_LEN) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_cant_check;
|
||||
}
|
||||
srtp_cipher_rand_for_tests(key, test_case->key_length_octets);
|
||||
|
||||
/* chose a random initialization vector */
|
||||
srtp_cipher_rand_for_tests(iv, MAX_KEY_LEN);
|
||||
|
||||
/* initialize cipher */
|
||||
status = srtp_cipher_init(c, key);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* set initialization vector */
|
||||
status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx,
|
||||
srtp_direction_encrypt);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
if (c->algorithm == SRTP_AES_GCM_128 ||
|
||||
c->algorithm == SRTP_AES_GCM_256) {
|
||||
/*
|
||||
* Set the AAD
|
||||
*/
|
||||
status = srtp_cipher_set_aad(c, test_case->aad,
|
||||
test_case->aad_length_octets);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
debug_print(srtp_mod_cipher, "AAD: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->aad, test_case->aad_length_octets));
|
||||
}
|
||||
|
||||
/* encrypt buffer with cipher */
|
||||
plaintext_len = length;
|
||||
status = srtp_cipher_encrypt(c, buffer, &length);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
if (c->algorithm == SRTP_AES_GCM_128 ||
|
||||
c->algorithm == SRTP_AES_GCM_256) {
|
||||
/*
|
||||
* Get the GCM tag
|
||||
*/
|
||||
status = srtp_cipher_get_tag(c, buffer + length, &tag_len);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
length += tag_len;
|
||||
}
|
||||
debug_print(srtp_mod_cipher, "ciphertext: %s",
|
||||
srtp_octet_string_hex_string(buffer, length));
|
||||
|
||||
/*
|
||||
* re-initialize cipher for decryption, re-set the iv, then
|
||||
* decrypt the ciphertext
|
||||
*/
|
||||
status = srtp_cipher_init(c, key);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx,
|
||||
srtp_direction_decrypt);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
if (c->algorithm == SRTP_AES_GCM_128 ||
|
||||
c->algorithm == SRTP_AES_GCM_256) {
|
||||
/*
|
||||
* Set the AAD
|
||||
*/
|
||||
status = srtp_cipher_set_aad(c, test_case->aad,
|
||||
test_case->aad_length_octets);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
debug_print(srtp_mod_cipher, "AAD: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->aad, test_case->aad_length_octets));
|
||||
}
|
||||
status = srtp_cipher_decrypt(c, buffer, &length);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_cipher, "plaintext[2]: %s",
|
||||
srtp_octet_string_hex_string(buffer, length));
|
||||
|
||||
/* compare the resulting plaintext with the original one */
|
||||
if (length != plaintext_len) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
status = srtp_err_status_ok;
|
||||
for (k = 0; k < plaintext_len; k++) {
|
||||
if (buffer[k] != buffer2[k]) {
|
||||
status = srtp_err_status_algo_fail;
|
||||
debug_print(srtp_mod_cipher, "random test case %d failed",
|
||||
case_num);
|
||||
debug_print(srtp_mod_cipher, "(failure at byte %u)", k);
|
||||
}
|
||||
}
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
}
|
||||
|
||||
status = srtp_cipher_dealloc(c);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_cipher_type_self_test(ct) performs srtp_cipher_type_test on ct's
|
||||
* internal list of test data.
|
||||
*/
|
||||
srtp_err_status_t srtp_cipher_type_self_test(const srtp_cipher_type_t *ct)
|
||||
{
|
||||
return srtp_cipher_type_test(ct, ct->test_data);
|
||||
}
|
||||
|
||||
/*
|
||||
* cipher_bits_per_second(c, l, t) computes (an estimate of) the
|
||||
* number of bits that a cipher implementation can encrypt in a second
|
||||
*
|
||||
* c is a cipher (which MUST be allocated and initialized already), l
|
||||
* is the length in octets of the test data to be encrypted, and t is
|
||||
* the number of trials
|
||||
*
|
||||
* if an error is encountered, the value 0 is returned
|
||||
*/
|
||||
uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c,
|
||||
int octets_in_buffer,
|
||||
int num_trials)
|
||||
{
|
||||
int i;
|
||||
v128_t nonce;
|
||||
clock_t timer;
|
||||
unsigned char *enc_buf;
|
||||
unsigned int len = octets_in_buffer;
|
||||
|
||||
enc_buf = (unsigned char *)srtp_crypto_alloc(octets_in_buffer);
|
||||
if (enc_buf == NULL) {
|
||||
return 0; /* indicate bad parameters by returning null */
|
||||
}
|
||||
/* time repeated trials */
|
||||
v128_set_to_zero(&nonce);
|
||||
timer = clock();
|
||||
for (i = 0; i < num_trials; i++, nonce.v32[3] = i) {
|
||||
if (srtp_cipher_set_iv(c, (uint8_t *)&nonce, srtp_direction_encrypt) !=
|
||||
srtp_err_status_ok) {
|
||||
srtp_crypto_free(enc_buf);
|
||||
return 0;
|
||||
}
|
||||
if (srtp_cipher_encrypt(c, enc_buf, &len) != srtp_err_status_ok) {
|
||||
srtp_crypto_free(enc_buf);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
timer = clock() - timer;
|
||||
|
||||
srtp_crypto_free(enc_buf);
|
||||
|
||||
if (timer == 0) {
|
||||
/* Too fast! */
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint64_t)CLOCKS_PER_SEC * num_trials * 8 * octets_in_buffer / timer;
|
||||
}
|
||||
@@ -1,365 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2021, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "cipher_test_cases.h"
|
||||
#include <stddef.h>
|
||||
|
||||
/*
|
||||
* KAT values for AES self-test. These
|
||||
* values came from the legacy libsrtp code.
|
||||
*/
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_128_test_case_0_key[SRTP_AES_ICM_128_KEY_LEN_WSALT] = {
|
||||
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static uint8_t srtp_aes_icm_128_test_case_0_nonce[16] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_128_test_case_0_plaintext[32] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_128_test_case_0_ciphertext[32] = {
|
||||
0xe0, 0x3e, 0xad, 0x09, 0x35, 0xc9, 0x5e, 0x80,
|
||||
0xe1, 0x66, 0xb1, 0x6d, 0xd9, 0x2b, 0x4e, 0xb4,
|
||||
0xd2, 0x35, 0x13, 0x16, 0x2b, 0x02, 0xd0, 0xf7,
|
||||
0x2a, 0x43, 0xa2, 0xfe, 0x4a, 0x5f, 0x97, 0xab
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
const srtp_cipher_test_case_t srtp_aes_icm_128_test_case_0 = {
|
||||
SRTP_AES_ICM_128_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_icm_128_test_case_0_key, /* key */
|
||||
srtp_aes_icm_128_test_case_0_nonce, /* packet index */
|
||||
32, /* octets in plaintext */
|
||||
srtp_aes_icm_128_test_case_0_plaintext, /* plaintext */
|
||||
32, /* octets in ciphertext */
|
||||
srtp_aes_icm_128_test_case_0_ciphertext, /* ciphertext */
|
||||
0, /* */
|
||||
NULL, /* */
|
||||
0, /* */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/*
|
||||
* KAT values for AES-192-CTR self-test. These
|
||||
* values came from section 7 of RFC 6188.
|
||||
*/
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_192_test_case_0_key[SRTP_AES_ICM_192_KEY_LEN_WSALT] = {
|
||||
0xea, 0xb2, 0x34, 0x76, 0x4e, 0x51, 0x7b, 0x2d,
|
||||
0x3d, 0x16, 0x0d, 0x58, 0x7d, 0x8c, 0x86, 0x21,
|
||||
0x97, 0x40, 0xf6, 0x5f, 0x99, 0xb6, 0xbc, 0xf7,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static uint8_t srtp_aes_icm_192_test_case_0_nonce[16] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_192_test_case_0_plaintext[32] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_192_test_case_0_ciphertext[32] = {
|
||||
0x35, 0x09, 0x6c, 0xba, 0x46, 0x10, 0x02, 0x8d,
|
||||
0xc1, 0xb5, 0x75, 0x03, 0x80, 0x4c, 0xe3, 0x7c,
|
||||
0x5d, 0xe9, 0x86, 0x29, 0x1d, 0xcc, 0xe1, 0x61,
|
||||
0xd5, 0x16, 0x5e, 0xc4, 0x56, 0x8f, 0x5c, 0x9a
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
const srtp_cipher_test_case_t srtp_aes_icm_192_test_case_0 = {
|
||||
SRTP_AES_ICM_192_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_icm_192_test_case_0_key, /* key */
|
||||
srtp_aes_icm_192_test_case_0_nonce, /* packet index */
|
||||
32, /* octets in plaintext */
|
||||
srtp_aes_icm_192_test_case_0_plaintext, /* plaintext */
|
||||
32, /* octets in ciphertext */
|
||||
srtp_aes_icm_192_test_case_0_ciphertext, /* ciphertext */
|
||||
0, /* */
|
||||
NULL, /* */
|
||||
0, /* */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/*
|
||||
* KAT values for AES-256-CTR self-test. These
|
||||
* values came from section 7 of RFC 6188.
|
||||
*/
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_256_test_case_0_key[SRTP_AES_ICM_256_KEY_LEN_WSALT] = {
|
||||
0x57, 0xf8, 0x2f, 0xe3, 0x61, 0x3f, 0xd1, 0x70,
|
||||
0xa8, 0x5e, 0xc9, 0x3c, 0x40, 0xb1, 0xf0, 0x92,
|
||||
0x2e, 0xc4, 0xcb, 0x0d, 0xc0, 0x25, 0xb5, 0x82,
|
||||
0x72, 0x14, 0x7c, 0xc4, 0x38, 0x94, 0x4a, 0x98,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static uint8_t srtp_aes_icm_256_test_case_0_nonce[16] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_256_test_case_0_plaintext[32] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_256_test_case_0_ciphertext[32] = {
|
||||
0x92, 0xbd, 0xd2, 0x8a, 0x93, 0xc3, 0xf5, 0x25,
|
||||
0x11, 0xc6, 0x77, 0xd0, 0x8b, 0x55, 0x15, 0xa4,
|
||||
0x9d, 0xa7, 0x1b, 0x23, 0x78, 0xa8, 0x54, 0xf6,
|
||||
0x70, 0x50, 0x75, 0x6d, 0xed, 0x16, 0x5b, 0xac
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
const srtp_cipher_test_case_t srtp_aes_icm_256_test_case_0 = {
|
||||
SRTP_AES_ICM_256_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_icm_256_test_case_0_key, /* key */
|
||||
srtp_aes_icm_256_test_case_0_nonce, /* packet index */
|
||||
32, /* octets in plaintext */
|
||||
srtp_aes_icm_256_test_case_0_plaintext, /* plaintext */
|
||||
32, /* octets in ciphertext */
|
||||
srtp_aes_icm_256_test_case_0_ciphertext, /* ciphertext */
|
||||
0, /* */
|
||||
NULL, /* */
|
||||
0, /* */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/*
|
||||
* KAT values for AES self-test. These
|
||||
* values we're derived from independent test code
|
||||
* using OpenSSL.
|
||||
*/
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_128_test_case_0_key[SRTP_AES_GCM_128_KEY_LEN_WSALT] = {
|
||||
0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
|
||||
0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0a, 0x0b, 0x0c,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static uint8_t srtp_aes_gcm_128_test_case_0_iv[12] = {
|
||||
0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
|
||||
0xde, 0xca, 0xf8, 0x88
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_128_test_case_0_plaintext[60] = {
|
||||
0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
|
||||
0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
|
||||
0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
|
||||
0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
|
||||
0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
|
||||
0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
|
||||
0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
|
||||
0xba, 0x63, 0x7b, 0x39
|
||||
};
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_128_test_case_0_aad[20] = {
|
||||
0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
|
||||
0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
|
||||
0xab, 0xad, 0xda, 0xd2
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_128_test_case_0_ciphertext[76] = {
|
||||
0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
|
||||
0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
|
||||
0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
|
||||
0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
|
||||
0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
|
||||
0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
|
||||
0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
|
||||
0x3d, 0x58, 0xe0, 0x91,
|
||||
/* the last 16 bytes are the tag */
|
||||
0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb,
|
||||
0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static const srtp_cipher_test_case_t srtp_aes_gcm_128_test_case_0a = {
|
||||
SRTP_AES_GCM_128_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_gcm_128_test_case_0_key, /* key */
|
||||
srtp_aes_gcm_128_test_case_0_iv, /* packet index */
|
||||
60, /* octets in plaintext */
|
||||
srtp_aes_gcm_128_test_case_0_plaintext, /* plaintext */
|
||||
68, /* octets in ciphertext */
|
||||
srtp_aes_gcm_128_test_case_0_ciphertext, /* ciphertext + tag */
|
||||
20, /* octets in AAD */
|
||||
srtp_aes_gcm_128_test_case_0_aad, /* AAD */
|
||||
8, /* */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
const srtp_cipher_test_case_t srtp_aes_gcm_128_test_case_0 = {
|
||||
SRTP_AES_GCM_128_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_gcm_128_test_case_0_key, /* key */
|
||||
srtp_aes_gcm_128_test_case_0_iv, /* packet index */
|
||||
60, /* octets in plaintext */
|
||||
srtp_aes_gcm_128_test_case_0_plaintext, /* plaintext */
|
||||
76, /* octets in ciphertext */
|
||||
srtp_aes_gcm_128_test_case_0_ciphertext, /* ciphertext + tag */
|
||||
20, /* octets in AAD */
|
||||
srtp_aes_gcm_128_test_case_0_aad, /* AAD */
|
||||
16, /* */
|
||||
&srtp_aes_gcm_128_test_case_0a /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_256_test_case_0_key[SRTP_AES_GCM_256_KEY_LEN_WSALT] = {
|
||||
0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
|
||||
0xa5, 0x59, 0x09, 0xc5, 0x54, 0x66, 0x93, 0x1c,
|
||||
0xaf, 0xf5, 0x26, 0x9a, 0x21, 0xd5, 0x14, 0xb2,
|
||||
0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0a, 0x0b, 0x0c,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static uint8_t srtp_aes_gcm_256_test_case_0_iv[12] = {
|
||||
0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
|
||||
0xde, 0xca, 0xf8, 0x88
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_256_test_case_0_plaintext[60] = {
|
||||
0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
|
||||
0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
|
||||
0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
|
||||
0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
|
||||
0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
|
||||
0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
|
||||
0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
|
||||
0xba, 0x63, 0x7b, 0x39
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_256_test_case_0_aad[20] = {
|
||||
0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
|
||||
0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
|
||||
0xab, 0xad, 0xda, 0xd2
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_256_test_case_0_ciphertext[76] = {
|
||||
0x0b, 0x11, 0xcf, 0xaf, 0x68, 0x4d, 0xae, 0x46,
|
||||
0xc7, 0x90, 0xb8, 0x8e, 0xb7, 0x6a, 0x76, 0x2a,
|
||||
0x94, 0x82, 0xca, 0xab, 0x3e, 0x39, 0xd7, 0x86,
|
||||
0x1b, 0xc7, 0x93, 0xed, 0x75, 0x7f, 0x23, 0x5a,
|
||||
0xda, 0xfd, 0xd3, 0xe2, 0x0e, 0x80, 0x87, 0xa9,
|
||||
0x6d, 0xd7, 0xe2, 0x6a, 0x7d, 0x5f, 0xb4, 0x80,
|
||||
0xef, 0xef, 0xc5, 0x29, 0x12, 0xd1, 0xaa, 0x10,
|
||||
0x09, 0xc9, 0x86, 0xc1,
|
||||
/* the last 16 bytes are the tag */
|
||||
0x45, 0xbc, 0x03, 0xe6, 0xe1, 0xac, 0x0a, 0x9f,
|
||||
0x81, 0xcb, 0x8e, 0x5b, 0x46, 0x65, 0x63, 0x1d,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static const srtp_cipher_test_case_t srtp_aes_gcm_256_test_case_0a = {
|
||||
SRTP_AES_GCM_256_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_gcm_256_test_case_0_key, /* key */
|
||||
srtp_aes_gcm_256_test_case_0_iv, /* packet index */
|
||||
60, /* octets in plaintext */
|
||||
srtp_aes_gcm_256_test_case_0_plaintext, /* plaintext */
|
||||
68, /* octets in ciphertext */
|
||||
srtp_aes_gcm_256_test_case_0_ciphertext, /* ciphertext + tag */
|
||||
20, /* octets in AAD */
|
||||
srtp_aes_gcm_256_test_case_0_aad, /* AAD */
|
||||
8, /* */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
const srtp_cipher_test_case_t srtp_aes_gcm_256_test_case_0 = {
|
||||
SRTP_AES_GCM_256_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_gcm_256_test_case_0_key, /* key */
|
||||
srtp_aes_gcm_256_test_case_0_iv, /* packet index */
|
||||
60, /* octets in plaintext */
|
||||
srtp_aes_gcm_256_test_case_0_plaintext, /* plaintext */
|
||||
76, /* octets in ciphertext */
|
||||
srtp_aes_gcm_256_test_case_0_ciphertext, /* ciphertext + tag */
|
||||
20, /* octets in AAD */
|
||||
srtp_aes_gcm_256_test_case_0_aad, /* AAD */
|
||||
16, /* */
|
||||
&srtp_aes_gcm_256_test_case_0a /* pointer to next testcase */
|
||||
};
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2021, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CHIPHER_TEST_CASES_H
|
||||
#define CHIPHER_TEST_CASES_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "cipher.h"
|
||||
|
||||
extern const srtp_cipher_test_case_t srtp_aes_icm_128_test_case_0;
|
||||
extern const srtp_cipher_test_case_t srtp_aes_icm_192_test_case_0;
|
||||
extern const srtp_cipher_test_case_t srtp_aes_icm_256_test_case_0;
|
||||
|
||||
extern const srtp_cipher_test_case_t srtp_aes_gcm_128_test_case_0;
|
||||
extern const srtp_cipher_test_case_t srtp_aes_gcm_256_test_case_0;
|
||||
|
||||
#endif
|
||||
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
* null_cipher.c
|
||||
*
|
||||
* A null cipher implementation. This cipher leaves the plaintext
|
||||
* unchanged.
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "datatypes.h"
|
||||
#include "null_cipher.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "alloc.h"
|
||||
#include "cipher_types.h"
|
||||
|
||||
static srtp_err_status_t srtp_null_cipher_alloc(srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen)
|
||||
{
|
||||
extern const srtp_cipher_type_t srtp_null_cipher;
|
||||
|
||||
debug_print(srtp_mod_cipher, "allocating cipher with key length %d",
|
||||
key_len);
|
||||
|
||||
/* allocate memory a cipher of type null_cipher */
|
||||
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
|
||||
if (*c == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* set pointers */
|
||||
(*c)->algorithm = SRTP_NULL_CIPHER;
|
||||
(*c)->type = &srtp_null_cipher;
|
||||
(*c)->state = (void *)0x1; /* The null cipher does not maintain state */
|
||||
|
||||
/* set key size */
|
||||
(*c)->key_len = key_len;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_cipher_dealloc(srtp_cipher_t *c)
|
||||
{
|
||||
extern const srtp_cipher_type_t srtp_null_cipher;
|
||||
|
||||
/* zeroize entire state*/
|
||||
octet_string_set_to_zero(c, sizeof(srtp_cipher_t));
|
||||
|
||||
/* free memory of type null_cipher */
|
||||
srtp_crypto_free(c);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_cipher_init(void *cv, const uint8_t *key)
|
||||
{
|
||||
/* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */
|
||||
|
||||
debug_print0(srtp_mod_cipher, "initializing null cipher");
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_cipher_set_iv(void *cv,
|
||||
uint8_t *iv,
|
||||
srtp_cipher_direction_t dir)
|
||||
{
|
||||
/* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_cipher_encrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *bytes_to_encr)
|
||||
{
|
||||
/* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static const char srtp_null_cipher_description[] = "null cipher";
|
||||
|
||||
static const srtp_cipher_test_case_t srtp_null_cipher_test_0 = {
|
||||
0, /* octets in key */
|
||||
NULL, /* key */
|
||||
0, /* packet index */
|
||||
0, /* octets in plaintext */
|
||||
NULL, /* plaintext */
|
||||
0, /* octets in plaintext */
|
||||
NULL, /* ciphertext */
|
||||
0, /* */
|
||||
NULL, /* */
|
||||
0, /* */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/*
|
||||
* note: the decrypt function is idential to the encrypt function
|
||||
*/
|
||||
|
||||
const srtp_cipher_type_t srtp_null_cipher = {
|
||||
srtp_null_cipher_alloc, /* */
|
||||
srtp_null_cipher_dealloc, /* */
|
||||
srtp_null_cipher_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_null_cipher_encrypt, /* */
|
||||
srtp_null_cipher_encrypt, /* */
|
||||
srtp_null_cipher_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_null_cipher_description, /* */
|
||||
&srtp_null_cipher_test_0, /* */
|
||||
SRTP_NULL_CIPHER /* */
|
||||
};
|
||||
@@ -1,193 +0,0 @@
|
||||
/*
|
||||
* auth.c
|
||||
*
|
||||
* some bookkeeping functions for authentication functions
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "auth.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "datatypes.h" /* for octet_string */
|
||||
|
||||
/* the debug module for authentiation */
|
||||
|
||||
srtp_debug_module_t srtp_mod_auth = {
|
||||
0, /* debugging is off by default */
|
||||
"auth func" /* printable name for module */
|
||||
};
|
||||
|
||||
int srtp_auth_get_key_length(const srtp_auth_t *a)
|
||||
{
|
||||
return a->key_len;
|
||||
}
|
||||
|
||||
int srtp_auth_get_tag_length(const srtp_auth_t *a)
|
||||
{
|
||||
return a->out_len;
|
||||
}
|
||||
|
||||
int srtp_auth_get_prefix_length(const srtp_auth_t *a)
|
||||
{
|
||||
return a->prefix_len;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_auth_type_test() tests an auth function of type ct against
|
||||
* test cases provided in a list test_data of values of key, data, and tag
|
||||
* that is known to be good
|
||||
*/
|
||||
|
||||
/* should be big enough for most occasions */
|
||||
#define SELF_TEST_TAG_BUF_OCTETS 32
|
||||
|
||||
srtp_err_status_t srtp_auth_type_test(const srtp_auth_type_t *at,
|
||||
const srtp_auth_test_case_t *test_data)
|
||||
{
|
||||
const srtp_auth_test_case_t *test_case = test_data;
|
||||
srtp_auth_t *a;
|
||||
srtp_err_status_t status;
|
||||
uint8_t tag[SELF_TEST_TAG_BUF_OCTETS];
|
||||
int i, case_num = 0;
|
||||
|
||||
debug_print(srtp_mod_auth, "running self-test for auth function %s",
|
||||
at->description);
|
||||
|
||||
/*
|
||||
* check to make sure that we have at least one test case, and
|
||||
* return an error if we don't - we need to be paranoid here
|
||||
*/
|
||||
if (test_case == NULL) {
|
||||
return srtp_err_status_cant_check;
|
||||
}
|
||||
|
||||
/* loop over all test cases */
|
||||
while (test_case != NULL) {
|
||||
/* check test case parameters */
|
||||
if (test_case->tag_length_octets > SELF_TEST_TAG_BUF_OCTETS) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* allocate auth */
|
||||
status = srtp_auth_type_alloc(at, &a, test_case->key_length_octets,
|
||||
test_case->tag_length_octets);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* initialize auth */
|
||||
status = srtp_auth_init(a, test_case->key);
|
||||
if (status) {
|
||||
srtp_auth_dealloc(a);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = srtp_auth_start(a);
|
||||
if (status) {
|
||||
srtp_auth_dealloc(a);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* zeroize tag then compute */
|
||||
octet_string_set_to_zero(tag, test_case->tag_length_octets);
|
||||
status = srtp_auth_compute(a, test_case->data,
|
||||
test_case->data_length_octets, tag);
|
||||
if (status) {
|
||||
srtp_auth_dealloc(a);
|
||||
return status;
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_auth, "key: %s",
|
||||
srtp_octet_string_hex_string(test_case->key,
|
||||
test_case->key_length_octets));
|
||||
debug_print(srtp_mod_auth, "data: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->data, test_case->data_length_octets));
|
||||
debug_print(
|
||||
srtp_mod_auth, "tag computed: %s",
|
||||
srtp_octet_string_hex_string(tag, test_case->tag_length_octets));
|
||||
debug_print(srtp_mod_auth, "tag expected: %s",
|
||||
srtp_octet_string_hex_string(test_case->tag,
|
||||
test_case->tag_length_octets));
|
||||
|
||||
/* check the result */
|
||||
status = srtp_err_status_ok;
|
||||
for (i = 0; i < test_case->tag_length_octets; i++) {
|
||||
if (tag[i] != test_case->tag[i]) {
|
||||
status = srtp_err_status_algo_fail;
|
||||
debug_print(srtp_mod_auth, "test case %d failed", case_num);
|
||||
debug_print(srtp_mod_auth, " (mismatch at octet %d)", i);
|
||||
}
|
||||
}
|
||||
if (status) {
|
||||
srtp_auth_dealloc(a);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
|
||||
/* deallocate the auth function */
|
||||
status = srtp_auth_dealloc(a);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* the auth function passed the test case, so move on to the next test
|
||||
* case in the list; if NULL, we'll quit and return an OK
|
||||
*/
|
||||
test_case = test_case->next_test_case;
|
||||
++case_num;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_auth_type_self_test(at) performs srtp_auth_type_test on at's internal
|
||||
* list of test data.
|
||||
*/
|
||||
|
||||
srtp_err_status_t srtp_auth_type_self_test(const srtp_auth_type_t *at)
|
||||
{
|
||||
return srtp_auth_type_test(at, at->test_data);
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2021, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "auth_test_cases.h"
|
||||
#include <stddef.h>
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_hmac_test_case_0_key[20] = {
|
||||
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
||||
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
||||
0x0b, 0x0b, 0x0b, 0x0b
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_hmac_test_case_0_data[8] = {
|
||||
0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65 /* "Hi There" */
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_hmac_test_case_0_tag[20] = {
|
||||
0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64,
|
||||
0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e,
|
||||
0xf1, 0x46, 0xbe, 0x00
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
const srtp_auth_test_case_t srtp_hmac_test_case_0 = {
|
||||
sizeof(srtp_hmac_test_case_0_key), /* octets in key */
|
||||
srtp_hmac_test_case_0_key, /* key */
|
||||
sizeof(srtp_hmac_test_case_0_data), /* octets in data */
|
||||
srtp_hmac_test_case_0_data, /* data */
|
||||
sizeof(srtp_hmac_test_case_0_tag), /* octets in tag */
|
||||
srtp_hmac_test_case_0_tag, /* tag */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2021, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AUTH_TEST_CASES_H
|
||||
#define AUTH_TEST_CASES_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "auth.h"
|
||||
|
||||
extern const srtp_auth_test_case_t srtp_hmac_test_case_0;
|
||||
|
||||
#endif
|
||||
@@ -1,249 +0,0 @@
|
||||
/*
|
||||
* hmac.c
|
||||
*
|
||||
* implementation of hmac srtp_auth_type_t
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "hmac.h"
|
||||
#include "alloc.h"
|
||||
#include "cipher_types.h"
|
||||
#include "auth_test_cases.h"
|
||||
|
||||
/* the debug module for authentiation */
|
||||
|
||||
srtp_debug_module_t srtp_mod_hmac = {
|
||||
0, /* debugging is off by default */
|
||||
"hmac sha-1" /* printable name for module */
|
||||
};
|
||||
|
||||
static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a,
|
||||
int key_len,
|
||||
int out_len)
|
||||
{
|
||||
extern const srtp_auth_type_t srtp_hmac;
|
||||
uint8_t *pointer;
|
||||
|
||||
debug_print(srtp_mod_hmac, "allocating auth func with key length %d",
|
||||
key_len);
|
||||
debug_print(srtp_mod_hmac, " tag length %d",
|
||||
out_len);
|
||||
|
||||
/*
|
||||
* check key length - note that we don't support keys larger
|
||||
* than 20 bytes yet
|
||||
*/
|
||||
if (key_len > 20) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* check output length - should be less than 20 bytes */
|
||||
if (out_len > 20) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* allocate memory for auth and srtp_hmac_ctx_t structures */
|
||||
pointer = (uint8_t *)srtp_crypto_alloc(sizeof(srtp_hmac_ctx_t) +
|
||||
sizeof(srtp_auth_t));
|
||||
if (pointer == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* set pointers */
|
||||
*a = (srtp_auth_t *)pointer;
|
||||
(*a)->type = &srtp_hmac;
|
||||
(*a)->state = pointer + sizeof(srtp_auth_t);
|
||||
(*a)->out_len = out_len;
|
||||
(*a)->key_len = key_len;
|
||||
(*a)->prefix_len = 0;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_dealloc(srtp_auth_t *a)
|
||||
{
|
||||
/* zeroize entire state*/
|
||||
octet_string_set_to_zero(a, sizeof(srtp_hmac_ctx_t) + sizeof(srtp_auth_t));
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(a);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_init(void *statev,
|
||||
const uint8_t *key,
|
||||
int key_len)
|
||||
{
|
||||
srtp_hmac_ctx_t *state = (srtp_hmac_ctx_t *)statev;
|
||||
int i;
|
||||
uint8_t ipad[64];
|
||||
|
||||
/*
|
||||
* check key length - note that we don't support keys larger
|
||||
* than 20 bytes yet
|
||||
*/
|
||||
if (key_len > 20) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/*
|
||||
* set values of ipad and opad by exoring the key into the
|
||||
* appropriate constant values
|
||||
*/
|
||||
for (i = 0; i < key_len; i++) {
|
||||
ipad[i] = key[i] ^ 0x36;
|
||||
state->opad[i] = key[i] ^ 0x5c;
|
||||
}
|
||||
/* set the rest of ipad, opad to constant values */
|
||||
for (; i < 64; i++) {
|
||||
ipad[i] = 0x36;
|
||||
((uint8_t *)state->opad)[i] = 0x5c;
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_hmac, "ipad: %s",
|
||||
srtp_octet_string_hex_string(ipad, 64));
|
||||
|
||||
/* initialize sha1 context */
|
||||
srtp_sha1_init(&state->init_ctx);
|
||||
|
||||
/* hash ipad ^ key */
|
||||
srtp_sha1_update(&state->init_ctx, ipad, 64);
|
||||
memcpy(&state->ctx, &state->init_ctx, sizeof(srtp_sha1_ctx_t));
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_start(void *statev)
|
||||
{
|
||||
srtp_hmac_ctx_t *state = (srtp_hmac_ctx_t *)statev;
|
||||
|
||||
memcpy(&state->ctx, &state->init_ctx, sizeof(srtp_sha1_ctx_t));
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_update(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets)
|
||||
{
|
||||
srtp_hmac_ctx_t *state = (srtp_hmac_ctx_t *)statev;
|
||||
|
||||
debug_print(srtp_mod_hmac, "input: %s",
|
||||
srtp_octet_string_hex_string(message, msg_octets));
|
||||
|
||||
/* hash message into sha1 context */
|
||||
srtp_sha1_update(&state->ctx, message, msg_octets);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_compute(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets,
|
||||
int tag_len,
|
||||
uint8_t *result)
|
||||
{
|
||||
srtp_hmac_ctx_t *state = (srtp_hmac_ctx_t *)statev;
|
||||
uint32_t hash_value[5];
|
||||
uint32_t H[5];
|
||||
int i;
|
||||
|
||||
/* check tag length, return error if we can't provide the value expected */
|
||||
if (tag_len > 20) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* hash message, copy output into H */
|
||||
srtp_hmac_update(state, message, msg_octets);
|
||||
srtp_sha1_final(&state->ctx, H);
|
||||
|
||||
/*
|
||||
* note that we don't need to debug_print() the input, since the
|
||||
* function hmac_update() already did that for us
|
||||
*/
|
||||
debug_print(srtp_mod_hmac, "intermediate state: %s",
|
||||
srtp_octet_string_hex_string((uint8_t *)H, 20));
|
||||
|
||||
/* re-initialize hash context */
|
||||
srtp_sha1_init(&state->ctx);
|
||||
|
||||
/* hash opad ^ key */
|
||||
srtp_sha1_update(&state->ctx, (uint8_t *)state->opad, 64);
|
||||
|
||||
/* hash the result of the inner hash */
|
||||
srtp_sha1_update(&state->ctx, (uint8_t *)H, 20);
|
||||
|
||||
/* the result is returned in the array hash_value[] */
|
||||
srtp_sha1_final(&state->ctx, hash_value);
|
||||
|
||||
/* copy hash_value to *result */
|
||||
for (i = 0; i < tag_len; i++) {
|
||||
result[i] = ((uint8_t *)hash_value)[i];
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_hmac, "output: %s",
|
||||
srtp_octet_string_hex_string((uint8_t *)hash_value, tag_len));
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static const char srtp_hmac_description[] =
|
||||
"hmac sha-1 authentication function";
|
||||
|
||||
/*
|
||||
* srtp_auth_type_t hmac is the hmac metaobject
|
||||
*/
|
||||
|
||||
const srtp_auth_type_t srtp_hmac = {
|
||||
srtp_hmac_alloc, /* */
|
||||
srtp_hmac_dealloc, /* */
|
||||
srtp_hmac_init, /* */
|
||||
srtp_hmac_compute, /* */
|
||||
srtp_hmac_update, /* */
|
||||
srtp_hmac_start, /* */
|
||||
srtp_hmac_description, /* */
|
||||
&srtp_hmac_test_case_0, /* */
|
||||
SRTP_HMAC_SHA1 /* */
|
||||
};
|
||||
@@ -1,221 +0,0 @@
|
||||
/*
|
||||
* hmac_mbedtls.c
|
||||
*
|
||||
* Implementation of hmac srtp_auth_type_t that leverages Mbedtls
|
||||
*
|
||||
* YongCheng Yang
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "auth.h"
|
||||
#include "alloc.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "auth_test_cases.h"
|
||||
#include <mbedtls/md.h>
|
||||
|
||||
#define SHA1_DIGEST_SIZE 20
|
||||
|
||||
/* the debug module for authentiation */
|
||||
|
||||
srtp_debug_module_t srtp_mod_hmac = {
|
||||
0, /* debugging is off by default */
|
||||
"hmac sha-1 mbedtls" /* printable name for module */
|
||||
};
|
||||
|
||||
static srtp_err_status_t srtp_hmac_mbedtls_alloc(srtp_auth_t **a,
|
||||
int key_len,
|
||||
int out_len)
|
||||
{
|
||||
extern const srtp_auth_type_t srtp_hmac;
|
||||
|
||||
debug_print(srtp_mod_hmac, "allocating auth func with key length %d",
|
||||
key_len);
|
||||
debug_print(srtp_mod_hmac, " tag length %d",
|
||||
out_len);
|
||||
|
||||
/* check output length - should be less than 20 bytes */
|
||||
if (key_len > SHA1_DIGEST_SIZE) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
/* check output length - should be less than 20 bytes */
|
||||
if (out_len > SHA1_DIGEST_SIZE) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
*a = (srtp_auth_t *)srtp_crypto_alloc(sizeof(srtp_auth_t));
|
||||
if (*a == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
// allocate the buffer of mbedtls context.
|
||||
(*a)->state = srtp_crypto_alloc(sizeof(mbedtls_md_context_t));
|
||||
if ((*a)->state == NULL) {
|
||||
srtp_crypto_free(*a);
|
||||
*a = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
mbedtls_md_init((mbedtls_md_context_t *)(*a)->state);
|
||||
|
||||
/* set pointers */
|
||||
(*a)->type = &srtp_hmac;
|
||||
(*a)->out_len = out_len;
|
||||
(*a)->key_len = key_len;
|
||||
(*a)->prefix_len = 0;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_mbedtls_dealloc(srtp_auth_t *a)
|
||||
{
|
||||
mbedtls_md_context_t *hmac_ctx;
|
||||
hmac_ctx = (mbedtls_md_context_t *)a->state;
|
||||
mbedtls_md_free(hmac_ctx);
|
||||
srtp_crypto_free(hmac_ctx);
|
||||
/* zeroize entire state*/
|
||||
octet_string_set_to_zero(a, sizeof(srtp_auth_t));
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(a);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_mbedtls_start(void *statev)
|
||||
{
|
||||
mbedtls_md_context_t *state = (mbedtls_md_context_t *)statev;
|
||||
if (mbedtls_md_hmac_reset(state) != 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_mbedtls_init(void *statev,
|
||||
const uint8_t *key,
|
||||
int key_len)
|
||||
{
|
||||
mbedtls_md_context_t *state = (mbedtls_md_context_t *)statev;
|
||||
const mbedtls_md_info_t *info = NULL;
|
||||
|
||||
info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA1);
|
||||
if (info == NULL)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
if (mbedtls_md_setup(state, info, 1) != 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
debug_print(srtp_mod_hmac, "mbedtls setup, name: %s",
|
||||
mbedtls_md_get_name(info));
|
||||
debug_print(srtp_mod_hmac, "mbedtls setup, size: %d",
|
||||
mbedtls_md_get_size(info));
|
||||
|
||||
if (mbedtls_md_hmac_starts(state, key, key_len) != 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_mbedtls_update(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets)
|
||||
{
|
||||
mbedtls_md_context_t *state = (mbedtls_md_context_t *)statev;
|
||||
|
||||
debug_print(srtp_mod_hmac, "input: %s",
|
||||
srtp_octet_string_hex_string(message, msg_octets));
|
||||
|
||||
if (mbedtls_md_hmac_update(state, message, msg_octets) != 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_mbedtls_compute(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets,
|
||||
int tag_len,
|
||||
uint8_t *result)
|
||||
{
|
||||
mbedtls_md_context_t *state = (mbedtls_md_context_t *)statev;
|
||||
uint8_t hash_value[SHA1_DIGEST_SIZE];
|
||||
int i;
|
||||
|
||||
/* check tag length, return error if we can't provide the value expected */
|
||||
if (tag_len > SHA1_DIGEST_SIZE) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* hash message, copy output into H */
|
||||
if (mbedtls_md_hmac_update(statev, message, msg_octets) != 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
if (mbedtls_md_hmac_finish(state, hash_value) != 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
/* copy hash_value to *result */
|
||||
for (i = 0; i < tag_len; i++) {
|
||||
result[i] = hash_value[i];
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_hmac, "output: %s",
|
||||
srtp_octet_string_hex_string(hash_value, tag_len));
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/* end test case 0 */
|
||||
|
||||
static const char srtp_hmac_mbedtls_description[] =
|
||||
"hmac sha-1 authentication function using mbedtls";
|
||||
|
||||
/*
|
||||
* srtp_auth_type_t hmac is the hmac metaobject
|
||||
*/
|
||||
|
||||
const srtp_auth_type_t srtp_hmac = {
|
||||
srtp_hmac_mbedtls_alloc, /* */
|
||||
srtp_hmac_mbedtls_dealloc, /* */
|
||||
srtp_hmac_mbedtls_init, /* */
|
||||
srtp_hmac_mbedtls_compute, /* */
|
||||
srtp_hmac_mbedtls_update, /* */
|
||||
srtp_hmac_mbedtls_start, /* */
|
||||
srtp_hmac_mbedtls_description, /* */
|
||||
&srtp_hmac_test_case_0, /* */
|
||||
SRTP_HMAC_SHA1 /* */
|
||||
};
|
||||
@@ -1,290 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "auth.h"
|
||||
#include "alloc.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "auth_test_cases.h"
|
||||
|
||||
#define NSS_PKCS11_2_0_COMPAT 1
|
||||
|
||||
#include <nss.h>
|
||||
#include <pk11pub.h>
|
||||
|
||||
#define SHA1_DIGEST_SIZE 20
|
||||
|
||||
/* the debug module for authentiation */
|
||||
|
||||
srtp_debug_module_t srtp_mod_hmac = {
|
||||
0, /* debugging is off by default */
|
||||
"hmac sha-1 nss" /* printable name for module */
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
NSSInitContext *nss;
|
||||
PK11SymKey *key;
|
||||
PK11Context *ctx;
|
||||
} srtp_hmac_nss_ctx_t;
|
||||
|
||||
static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a,
|
||||
int key_len,
|
||||
int out_len)
|
||||
{
|
||||
extern const srtp_auth_type_t srtp_hmac;
|
||||
srtp_hmac_nss_ctx_t *hmac;
|
||||
NSSInitContext *nss;
|
||||
|
||||
debug_print(srtp_mod_hmac, "allocating auth func with key length %d",
|
||||
key_len);
|
||||
debug_print(srtp_mod_hmac, " tag length %d",
|
||||
out_len);
|
||||
|
||||
/* check output length - should be less than 20 bytes */
|
||||
if (out_len > SHA1_DIGEST_SIZE) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* Initialize NSS equiv of NSS_NoDB_Init(NULL) */
|
||||
nss = NSS_InitContext("", "", "", "", NULL,
|
||||
NSS_INIT_READONLY | NSS_INIT_NOCERTDB |
|
||||
NSS_INIT_NOMODDB | NSS_INIT_FORCEOPEN |
|
||||
NSS_INIT_OPTIMIZESPACE);
|
||||
if (!nss) {
|
||||
return srtp_err_status_auth_fail;
|
||||
}
|
||||
|
||||
*a = (srtp_auth_t *)srtp_crypto_alloc(sizeof(srtp_auth_t));
|
||||
if (*a == NULL) {
|
||||
NSS_ShutdownContext(nss);
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
hmac =
|
||||
(srtp_hmac_nss_ctx_t *)srtp_crypto_alloc(sizeof(srtp_hmac_nss_ctx_t));
|
||||
if (hmac == NULL) {
|
||||
NSS_ShutdownContext(nss);
|
||||
srtp_crypto_free(*a);
|
||||
*a = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
hmac->nss = nss;
|
||||
hmac->key = NULL;
|
||||
hmac->ctx = NULL;
|
||||
|
||||
/* set pointers */
|
||||
(*a)->state = hmac;
|
||||
(*a)->type = &srtp_hmac;
|
||||
(*a)->out_len = out_len;
|
||||
(*a)->key_len = key_len;
|
||||
(*a)->prefix_len = 0;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_dealloc(srtp_auth_t *a)
|
||||
{
|
||||
srtp_hmac_nss_ctx_t *hmac;
|
||||
|
||||
hmac = (srtp_hmac_nss_ctx_t *)a->state;
|
||||
if (hmac) {
|
||||
/* free any PK11 values that have been created */
|
||||
if (hmac->key) {
|
||||
PK11_FreeSymKey(hmac->key);
|
||||
hmac->key = NULL;
|
||||
}
|
||||
|
||||
if (hmac->ctx) {
|
||||
PK11_DestroyContext(hmac->ctx, PR_TRUE);
|
||||
hmac->ctx = NULL;
|
||||
}
|
||||
|
||||
if (hmac->nss) {
|
||||
NSS_ShutdownContext(hmac->nss);
|
||||
hmac->nss = NULL;
|
||||
}
|
||||
|
||||
/* zeroize everything */
|
||||
octet_string_set_to_zero(hmac, sizeof(srtp_hmac_nss_ctx_t));
|
||||
srtp_crypto_free(hmac);
|
||||
}
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(a);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_start(void *statev)
|
||||
{
|
||||
srtp_hmac_nss_ctx_t *hmac;
|
||||
hmac = (srtp_hmac_nss_ctx_t *)statev;
|
||||
|
||||
if (PK11_DigestBegin(hmac->ctx) != SECSuccess) {
|
||||
return srtp_err_status_auth_fail;
|
||||
}
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_init(void *statev,
|
||||
const uint8_t *key,
|
||||
int key_len)
|
||||
{
|
||||
srtp_hmac_nss_ctx_t *hmac;
|
||||
hmac = (srtp_hmac_nss_ctx_t *)statev;
|
||||
PK11SymKey *sym_key;
|
||||
PK11Context *ctx;
|
||||
|
||||
if (hmac->ctx) {
|
||||
PK11_DestroyContext(hmac->ctx, PR_TRUE);
|
||||
hmac->ctx = NULL;
|
||||
}
|
||||
|
||||
if (hmac->key) {
|
||||
PK11_FreeSymKey(hmac->key);
|
||||
hmac->key = NULL;
|
||||
}
|
||||
|
||||
PK11SlotInfo *slot = PK11_GetBestSlot(CKM_SHA_1_HMAC, NULL);
|
||||
if (!slot) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
SECItem key_item = { siBuffer, (unsigned char *)key, key_len };
|
||||
sym_key = PK11_ImportSymKey(slot, CKM_SHA_1_HMAC, PK11_OriginUnwrap,
|
||||
CKA_SIGN, &key_item, NULL);
|
||||
PK11_FreeSlot(slot);
|
||||
|
||||
if (!sym_key) {
|
||||
return srtp_err_status_auth_fail;
|
||||
}
|
||||
|
||||
SECItem param_item = { siBuffer, NULL, 0 };
|
||||
ctx = PK11_CreateContextBySymKey(CKM_SHA_1_HMAC, CKA_SIGN, sym_key,
|
||||
¶m_item);
|
||||
if (!ctx) {
|
||||
PK11_FreeSymKey(sym_key);
|
||||
return srtp_err_status_auth_fail;
|
||||
}
|
||||
|
||||
hmac->key = sym_key;
|
||||
hmac->ctx = ctx;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_update(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets)
|
||||
{
|
||||
srtp_hmac_nss_ctx_t *hmac;
|
||||
hmac = (srtp_hmac_nss_ctx_t *)statev;
|
||||
|
||||
debug_print(srtp_mod_hmac, "input: %s",
|
||||
srtp_octet_string_hex_string(message, msg_octets));
|
||||
|
||||
if (PK11_DigestOp(hmac->ctx, message, msg_octets) != SECSuccess) {
|
||||
return srtp_err_status_auth_fail;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_compute(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets,
|
||||
int tag_len,
|
||||
uint8_t *result)
|
||||
{
|
||||
srtp_hmac_nss_ctx_t *hmac;
|
||||
hmac = (srtp_hmac_nss_ctx_t *)statev;
|
||||
uint8_t hash_value[SHA1_DIGEST_SIZE];
|
||||
int i;
|
||||
unsigned int len;
|
||||
|
||||
debug_print(srtp_mod_hmac, "input: %s",
|
||||
srtp_octet_string_hex_string(message, msg_octets));
|
||||
|
||||
/* check tag length, return error if we can't provide the value expected */
|
||||
if (tag_len > SHA1_DIGEST_SIZE) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
if (PK11_DigestOp(hmac->ctx, message, msg_octets) != SECSuccess) {
|
||||
return srtp_err_status_auth_fail;
|
||||
}
|
||||
|
||||
if (PK11_DigestFinal(hmac->ctx, hash_value, &len, SHA1_DIGEST_SIZE) !=
|
||||
SECSuccess) {
|
||||
return srtp_err_status_auth_fail;
|
||||
}
|
||||
|
||||
if (len < tag_len)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
/* copy hash_value to *result */
|
||||
for (i = 0; i < tag_len; i++) {
|
||||
result[i] = hash_value[i];
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_hmac, "output: %s",
|
||||
srtp_octet_string_hex_string(hash_value, tag_len));
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static const char srtp_hmac_description[] =
|
||||
"hmac sha-1 authentication function";
|
||||
|
||||
/*
|
||||
* srtp_auth_type_t hmac is the hmac metaobject
|
||||
*/
|
||||
|
||||
const srtp_auth_type_t srtp_hmac = {
|
||||
srtp_hmac_alloc, /* */
|
||||
srtp_hmac_dealloc, /* */
|
||||
srtp_hmac_init, /* */
|
||||
srtp_hmac_compute, /* */
|
||||
srtp_hmac_update, /* */
|
||||
srtp_hmac_start, /* */
|
||||
srtp_hmac_description, /* */
|
||||
&srtp_hmac_test_case_0, /* */
|
||||
SRTP_HMAC_SHA1 /* */
|
||||
};
|
||||
@@ -1,242 +0,0 @@
|
||||
/*
|
||||
* hmac_ossl.c
|
||||
*
|
||||
* Implementation of hmac srtp_auth_type_t that leverages OpenSSL
|
||||
*
|
||||
* John A. Foley
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "auth.h"
|
||||
#include "alloc.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "auth_test_cases.h"
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/hmac.h>
|
||||
|
||||
#define SHA1_DIGEST_SIZE 20
|
||||
|
||||
/* the debug module for authentiation */
|
||||
|
||||
srtp_debug_module_t srtp_mod_hmac = {
|
||||
0, /* debugging is off by default */
|
||||
"hmac sha-1 openssl" /* printable name for module */
|
||||
};
|
||||
|
||||
static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a,
|
||||
int key_len,
|
||||
int out_len)
|
||||
{
|
||||
extern const srtp_auth_type_t srtp_hmac;
|
||||
|
||||
debug_print(srtp_mod_hmac, "allocating auth func with key length %d",
|
||||
key_len);
|
||||
debug_print(srtp_mod_hmac, " tag length %d",
|
||||
out_len);
|
||||
|
||||
/* check output length - should be less than 20 bytes */
|
||||
if (out_len > SHA1_DIGEST_SIZE) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* OpenSSL 1.1.0 made HMAC_CTX an opaque structure, which must be allocated
|
||||
using HMAC_CTX_new. But this function doesn't exist in OpenSSL 1.0.x. */
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L || LIBRESSL_VERSION_NUMBER
|
||||
{
|
||||
/* allocate memory for auth and HMAC_CTX structures */
|
||||
uint8_t *pointer;
|
||||
HMAC_CTX *new_hmac_ctx;
|
||||
pointer = (uint8_t *)srtp_crypto_alloc(sizeof(HMAC_CTX) +
|
||||
sizeof(srtp_auth_t));
|
||||
if (pointer == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
*a = (srtp_auth_t *)pointer;
|
||||
(*a)->state = pointer + sizeof(srtp_auth_t);
|
||||
new_hmac_ctx = (HMAC_CTX *)((*a)->state);
|
||||
|
||||
HMAC_CTX_init(new_hmac_ctx);
|
||||
}
|
||||
|
||||
#else
|
||||
*a = (srtp_auth_t *)srtp_crypto_alloc(sizeof(srtp_auth_t));
|
||||
if (*a == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
(*a)->state = HMAC_CTX_new();
|
||||
if ((*a)->state == NULL) {
|
||||
srtp_crypto_free(*a);
|
||||
*a = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* set pointers */
|
||||
(*a)->type = &srtp_hmac;
|
||||
(*a)->out_len = out_len;
|
||||
(*a)->key_len = key_len;
|
||||
(*a)->prefix_len = 0;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_dealloc(srtp_auth_t *a)
|
||||
{
|
||||
HMAC_CTX *hmac_ctx;
|
||||
|
||||
hmac_ctx = (HMAC_CTX *)a->state;
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L || LIBRESSL_VERSION_NUMBER
|
||||
HMAC_CTX_cleanup(hmac_ctx);
|
||||
|
||||
/* zeroize entire state*/
|
||||
octet_string_set_to_zero(a, sizeof(HMAC_CTX) + sizeof(srtp_auth_t));
|
||||
|
||||
#else
|
||||
HMAC_CTX_free(hmac_ctx);
|
||||
|
||||
/* zeroize entire state*/
|
||||
octet_string_set_to_zero(a, sizeof(srtp_auth_t));
|
||||
#endif
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(a);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_start(void *statev)
|
||||
{
|
||||
HMAC_CTX *state = (HMAC_CTX *)statev;
|
||||
|
||||
if (HMAC_Init_ex(state, NULL, 0, NULL, NULL) == 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_init(void *statev,
|
||||
const uint8_t *key,
|
||||
int key_len)
|
||||
{
|
||||
HMAC_CTX *state = (HMAC_CTX *)statev;
|
||||
|
||||
if (HMAC_Init_ex(state, key, key_len, EVP_sha1(), NULL) == 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_update(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets)
|
||||
{
|
||||
HMAC_CTX *state = (HMAC_CTX *)statev;
|
||||
|
||||
debug_print(srtp_mod_hmac, "input: %s",
|
||||
srtp_octet_string_hex_string(message, msg_octets));
|
||||
|
||||
if (HMAC_Update(state, message, msg_octets) == 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_compute(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets,
|
||||
int tag_len,
|
||||
uint8_t *result)
|
||||
{
|
||||
HMAC_CTX *state = (HMAC_CTX *)statev;
|
||||
uint8_t hash_value[SHA1_DIGEST_SIZE];
|
||||
int i;
|
||||
unsigned int len;
|
||||
|
||||
debug_print(srtp_mod_hmac, "input: %s",
|
||||
srtp_octet_string_hex_string(message, msg_octets));
|
||||
|
||||
/* check tag length, return error if we can't provide the value expected */
|
||||
if (tag_len > SHA1_DIGEST_SIZE) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* hash message, copy output into H */
|
||||
if (HMAC_Update(state, message, msg_octets) == 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
if (HMAC_Final(state, hash_value, &len) == 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
if (len < tag_len)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
/* copy hash_value to *result */
|
||||
for (i = 0; i < tag_len; i++) {
|
||||
result[i] = hash_value[i];
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_hmac, "output: %s",
|
||||
srtp_octet_string_hex_string(hash_value, tag_len));
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static const char srtp_hmac_description[] =
|
||||
"hmac sha-1 authentication function";
|
||||
|
||||
/*
|
||||
* srtp_auth_type_t hmac is the hmac metaobject
|
||||
*/
|
||||
|
||||
const srtp_auth_type_t srtp_hmac = {
|
||||
srtp_hmac_alloc, /* */
|
||||
srtp_hmac_dealloc, /* */
|
||||
srtp_hmac_init, /* */
|
||||
srtp_hmac_compute, /* */
|
||||
srtp_hmac_update, /* */
|
||||
srtp_hmac_start, /* */
|
||||
srtp_hmac_description, /* */
|
||||
&srtp_hmac_test_case_0, /* */
|
||||
SRTP_HMAC_SHA1 /* */
|
||||
};
|
||||
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* null_auth.c
|
||||
*
|
||||
* implements the do-nothing auth algorithm
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "null_auth.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "alloc.h"
|
||||
#include "cipher_types.h"
|
||||
|
||||
static srtp_err_status_t srtp_null_auth_alloc(srtp_auth_t **a,
|
||||
int key_len,
|
||||
int out_len)
|
||||
{
|
||||
extern const srtp_auth_type_t srtp_null_auth;
|
||||
uint8_t *pointer;
|
||||
|
||||
debug_print(srtp_mod_auth, "allocating auth func with key length %d",
|
||||
key_len);
|
||||
debug_print(srtp_mod_auth, " tag length %d",
|
||||
out_len);
|
||||
|
||||
/* allocate memory for auth and srtp_null_auth_ctx_t structures */
|
||||
pointer = (uint8_t *)srtp_crypto_alloc(sizeof(srtp_null_auth_ctx_t) +
|
||||
sizeof(srtp_auth_t));
|
||||
if (pointer == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* set pointers */
|
||||
*a = (srtp_auth_t *)pointer;
|
||||
(*a)->type = &srtp_null_auth;
|
||||
(*a)->state = pointer + sizeof(srtp_auth_t);
|
||||
(*a)->out_len = out_len;
|
||||
(*a)->prefix_len = out_len;
|
||||
(*a)->key_len = key_len;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_auth_dealloc(srtp_auth_t *a)
|
||||
{
|
||||
extern const srtp_auth_type_t srtp_null_auth;
|
||||
|
||||
/* zeroize entire state*/
|
||||
octet_string_set_to_zero(a, sizeof(srtp_null_auth_ctx_t) +
|
||||
sizeof(srtp_auth_t));
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(a);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_auth_init(void *statev,
|
||||
const uint8_t *key,
|
||||
int key_len)
|
||||
{
|
||||
/* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
|
||||
/* accept any length of key, and do nothing */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_auth_compute(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets,
|
||||
int tag_len,
|
||||
uint8_t *result)
|
||||
{
|
||||
/* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_auth_update(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets)
|
||||
{
|
||||
/* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_auth_start(void *statev)
|
||||
{
|
||||
/* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_auth_type_t - defines description, test case, and null_auth
|
||||
* metaobject
|
||||
*/
|
||||
|
||||
/* begin test case 0 */
|
||||
|
||||
static const srtp_auth_test_case_t srtp_null_auth_test_case_0 = {
|
||||
0, /* octets in key */
|
||||
NULL, /* key */
|
||||
0, /* octets in data */
|
||||
NULL, /* data */
|
||||
0, /* octets in tag */
|
||||
NULL, /* tag */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/* end test case 0 */
|
||||
|
||||
static const char srtp_null_auth_description[] = "null authentication function";
|
||||
|
||||
const srtp_auth_type_t srtp_null_auth = {
|
||||
srtp_null_auth_alloc, /* */
|
||||
srtp_null_auth_dealloc, /* */
|
||||
srtp_null_auth_init, /* */
|
||||
srtp_null_auth_compute, /* */
|
||||
srtp_null_auth_update, /* */
|
||||
srtp_null_auth_start, /* */
|
||||
srtp_null_auth_description, /* */
|
||||
&srtp_null_auth_test_case_0, /* */
|
||||
SRTP_NULL_AUTH /* */
|
||||
};
|
||||
@@ -1,463 +0,0 @@
|
||||
/*
|
||||
* sha1.c
|
||||
*
|
||||
* an implementation of the Secure Hash Algorithm v.1 (SHA-1),
|
||||
* specified in FIPS 180-1
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "sha1.h"
|
||||
|
||||
srtp_debug_module_t srtp_mod_sha1 = {
|
||||
0, /* debugging is off by default */
|
||||
"sha-1" /* printable module name */
|
||||
};
|
||||
|
||||
/* SN == Rotate left N bits */
|
||||
#define S1(X) ((X << 1) | (X >> 31))
|
||||
#define S5(X) ((X << 5) | (X >> 27))
|
||||
#define S30(X) ((X << 30) | (X >> 2))
|
||||
|
||||
#define f0(B, C, D) ((B & C) | (~B & D))
|
||||
#define f1(B, C, D) (B ^ C ^ D)
|
||||
#define f2(B, C, D) ((B & C) | (B & D) | (C & D))
|
||||
#define f3(B, C, D) (B ^ C ^ D)
|
||||
|
||||
/*
|
||||
* nota bene: the variable K0 appears in the curses library, so we
|
||||
* give longer names to these variables to avoid spurious warnings
|
||||
* on systems that uses curses
|
||||
*/
|
||||
|
||||
uint32_t SHA_K0 = 0x5A827999; /* Kt for 0 <= t <= 19 */
|
||||
uint32_t SHA_K1 = 0x6ED9EBA1; /* Kt for 20 <= t <= 39 */
|
||||
uint32_t SHA_K2 = 0x8F1BBCDC; /* Kt for 40 <= t <= 59 */
|
||||
uint32_t SHA_K3 = 0xCA62C1D6; /* Kt for 60 <= t <= 79 */
|
||||
|
||||
/*
|
||||
* srtp_sha1_core(M, H) computes the core compression function, where M is
|
||||
* the next part of the message (in network byte order) and H is the
|
||||
* intermediate state { H0, H1, ...} (in host byte order)
|
||||
*
|
||||
* this function does not do any of the padding required in the
|
||||
* complete SHA1 function
|
||||
*
|
||||
* this function is used in the SEAL 3.0 key setup routines
|
||||
* (crypto/cipher/seal.c)
|
||||
*/
|
||||
|
||||
void srtp_sha1_core(const uint32_t M[16], uint32_t hash_value[5])
|
||||
{
|
||||
uint32_t H0;
|
||||
uint32_t H1;
|
||||
uint32_t H2;
|
||||
uint32_t H3;
|
||||
uint32_t H4;
|
||||
uint32_t W[80];
|
||||
uint32_t A, B, C, D, E, TEMP;
|
||||
int t;
|
||||
|
||||
/* copy hash_value into H0, H1, H2, H3, H4 */
|
||||
H0 = hash_value[0];
|
||||
H1 = hash_value[1];
|
||||
H2 = hash_value[2];
|
||||
H3 = hash_value[3];
|
||||
H4 = hash_value[4];
|
||||
|
||||
/* copy/xor message into array */
|
||||
|
||||
W[0] = be32_to_cpu(M[0]);
|
||||
W[1] = be32_to_cpu(M[1]);
|
||||
W[2] = be32_to_cpu(M[2]);
|
||||
W[3] = be32_to_cpu(M[3]);
|
||||
W[4] = be32_to_cpu(M[4]);
|
||||
W[5] = be32_to_cpu(M[5]);
|
||||
W[6] = be32_to_cpu(M[6]);
|
||||
W[7] = be32_to_cpu(M[7]);
|
||||
W[8] = be32_to_cpu(M[8]);
|
||||
W[9] = be32_to_cpu(M[9]);
|
||||
W[10] = be32_to_cpu(M[10]);
|
||||
W[11] = be32_to_cpu(M[11]);
|
||||
W[12] = be32_to_cpu(M[12]);
|
||||
W[13] = be32_to_cpu(M[13]);
|
||||
W[14] = be32_to_cpu(M[14]);
|
||||
W[15] = be32_to_cpu(M[15]);
|
||||
TEMP = W[13] ^ W[8] ^ W[2] ^ W[0];
|
||||
W[16] = S1(TEMP);
|
||||
TEMP = W[14] ^ W[9] ^ W[3] ^ W[1];
|
||||
W[17] = S1(TEMP);
|
||||
TEMP = W[15] ^ W[10] ^ W[4] ^ W[2];
|
||||
W[18] = S1(TEMP);
|
||||
TEMP = W[16] ^ W[11] ^ W[5] ^ W[3];
|
||||
W[19] = S1(TEMP);
|
||||
TEMP = W[17] ^ W[12] ^ W[6] ^ W[4];
|
||||
W[20] = S1(TEMP);
|
||||
TEMP = W[18] ^ W[13] ^ W[7] ^ W[5];
|
||||
W[21] = S1(TEMP);
|
||||
TEMP = W[19] ^ W[14] ^ W[8] ^ W[6];
|
||||
W[22] = S1(TEMP);
|
||||
TEMP = W[20] ^ W[15] ^ W[9] ^ W[7];
|
||||
W[23] = S1(TEMP);
|
||||
TEMP = W[21] ^ W[16] ^ W[10] ^ W[8];
|
||||
W[24] = S1(TEMP);
|
||||
TEMP = W[22] ^ W[17] ^ W[11] ^ W[9];
|
||||
W[25] = S1(TEMP);
|
||||
TEMP = W[23] ^ W[18] ^ W[12] ^ W[10];
|
||||
W[26] = S1(TEMP);
|
||||
TEMP = W[24] ^ W[19] ^ W[13] ^ W[11];
|
||||
W[27] = S1(TEMP);
|
||||
TEMP = W[25] ^ W[20] ^ W[14] ^ W[12];
|
||||
W[28] = S1(TEMP);
|
||||
TEMP = W[26] ^ W[21] ^ W[15] ^ W[13];
|
||||
W[29] = S1(TEMP);
|
||||
TEMP = W[27] ^ W[22] ^ W[16] ^ W[14];
|
||||
W[30] = S1(TEMP);
|
||||
TEMP = W[28] ^ W[23] ^ W[17] ^ W[15];
|
||||
W[31] = S1(TEMP);
|
||||
|
||||
/* process the remainder of the array */
|
||||
for (t = 32; t < 80; t++) {
|
||||
TEMP = W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16];
|
||||
W[t] = S1(TEMP);
|
||||
}
|
||||
|
||||
A = H0;
|
||||
B = H1;
|
||||
C = H2;
|
||||
D = H3;
|
||||
E = H4;
|
||||
|
||||
for (t = 0; t < 20; t++) {
|
||||
TEMP = S5(A) + f0(B, C, D) + E + W[t] + SHA_K0;
|
||||
E = D;
|
||||
D = C;
|
||||
C = S30(B);
|
||||
B = A;
|
||||
A = TEMP;
|
||||
}
|
||||
for (; t < 40; t++) {
|
||||
TEMP = S5(A) + f1(B, C, D) + E + W[t] + SHA_K1;
|
||||
E = D;
|
||||
D = C;
|
||||
C = S30(B);
|
||||
B = A;
|
||||
A = TEMP;
|
||||
}
|
||||
for (; t < 60; t++) {
|
||||
TEMP = S5(A) + f2(B, C, D) + E + W[t] + SHA_K2;
|
||||
E = D;
|
||||
D = C;
|
||||
C = S30(B);
|
||||
B = A;
|
||||
A = TEMP;
|
||||
}
|
||||
for (; t < 80; t++) {
|
||||
TEMP = S5(A) + f3(B, C, D) + E + W[t] + SHA_K3;
|
||||
E = D;
|
||||
D = C;
|
||||
C = S30(B);
|
||||
B = A;
|
||||
A = TEMP;
|
||||
}
|
||||
|
||||
hash_value[0] = H0 + A;
|
||||
hash_value[1] = H1 + B;
|
||||
hash_value[2] = H2 + C;
|
||||
hash_value[3] = H3 + D;
|
||||
hash_value[4] = H4 + E;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void srtp_sha1_init(srtp_sha1_ctx_t *ctx)
|
||||
{
|
||||
/* initialize state vector */
|
||||
ctx->H[0] = 0x67452301;
|
||||
ctx->H[1] = 0xefcdab89;
|
||||
ctx->H[2] = 0x98badcfe;
|
||||
ctx->H[3] = 0x10325476;
|
||||
ctx->H[4] = 0xc3d2e1f0;
|
||||
|
||||
/* indicate that message buffer is empty */
|
||||
ctx->octets_in_buffer = 0;
|
||||
|
||||
/* reset message bit-count to zero */
|
||||
ctx->num_bits_in_msg = 0;
|
||||
}
|
||||
|
||||
void srtp_sha1_update(srtp_sha1_ctx_t *ctx,
|
||||
const uint8_t *msg,
|
||||
int octets_in_msg)
|
||||
{
|
||||
int i;
|
||||
uint8_t *buf = (uint8_t *)ctx->M;
|
||||
|
||||
/* update message bit-count */
|
||||
ctx->num_bits_in_msg += octets_in_msg * 8;
|
||||
|
||||
/* loop over 16-word blocks of M */
|
||||
while (octets_in_msg > 0) {
|
||||
if (octets_in_msg + ctx->octets_in_buffer >= 64) {
|
||||
/*
|
||||
* copy words of M into msg buffer until that buffer is full,
|
||||
* converting them into host byte order as needed
|
||||
*/
|
||||
octets_in_msg -= (64 - ctx->octets_in_buffer);
|
||||
for (i = ctx->octets_in_buffer; i < 64; i++) {
|
||||
buf[i] = *msg++;
|
||||
}
|
||||
ctx->octets_in_buffer = 0;
|
||||
|
||||
/* process a whole block */
|
||||
|
||||
debug_print0(srtp_mod_sha1, "(update) running srtp_sha1_core()");
|
||||
|
||||
srtp_sha1_core(ctx->M, ctx->H);
|
||||
|
||||
} else {
|
||||
debug_print0(srtp_mod_sha1,
|
||||
"(update) not running srtp_sha1_core()");
|
||||
|
||||
for (i = ctx->octets_in_buffer;
|
||||
i < (ctx->octets_in_buffer + octets_in_msg); i++) {
|
||||
buf[i] = *msg++;
|
||||
}
|
||||
ctx->octets_in_buffer += octets_in_msg;
|
||||
octets_in_msg = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_sha1_final(ctx, output) computes the result for ctx and copies it
|
||||
* into the twenty octets located at *output
|
||||
*/
|
||||
|
||||
void srtp_sha1_final(srtp_sha1_ctx_t *ctx, uint32_t output[5])
|
||||
{
|
||||
uint32_t A, B, C, D, E, TEMP;
|
||||
uint32_t W[80];
|
||||
int i, t;
|
||||
|
||||
/*
|
||||
* process the remaining octets_in_buffer, padding and terminating as
|
||||
* necessary
|
||||
*/
|
||||
{
|
||||
int tail = ctx->octets_in_buffer % 4;
|
||||
|
||||
/* copy/xor message into array */
|
||||
for (i = 0; i < (ctx->octets_in_buffer + 3) / 4; i++) {
|
||||
W[i] = be32_to_cpu(ctx->M[i]);
|
||||
}
|
||||
|
||||
/* set the high bit of the octet immediately following the message */
|
||||
switch (tail) {
|
||||
case (3):
|
||||
W[i - 1] = (be32_to_cpu(ctx->M[i - 1]) & 0xffffff00) | 0x80;
|
||||
W[i] = 0x0;
|
||||
break;
|
||||
case (2):
|
||||
W[i - 1] = (be32_to_cpu(ctx->M[i - 1]) & 0xffff0000) | 0x8000;
|
||||
W[i] = 0x0;
|
||||
break;
|
||||
case (1):
|
||||
W[i - 1] = (be32_to_cpu(ctx->M[i - 1]) & 0xff000000) | 0x800000;
|
||||
W[i] = 0x0;
|
||||
break;
|
||||
case (0):
|
||||
W[i] = 0x80000000;
|
||||
break;
|
||||
}
|
||||
|
||||
/* zeroize remaining words */
|
||||
for (i++; i < 15; i++) {
|
||||
W[i] = 0x0;
|
||||
}
|
||||
|
||||
/*
|
||||
* if there is room at the end of the word array, then set the
|
||||
* last word to the bit-length of the message; otherwise, set that
|
||||
* word to zero and then we need to do one more run of the
|
||||
* compression algo.
|
||||
*/
|
||||
if (ctx->octets_in_buffer < 56) {
|
||||
W[15] = ctx->num_bits_in_msg;
|
||||
} else if (ctx->octets_in_buffer < 60) {
|
||||
W[15] = 0x0;
|
||||
}
|
||||
|
||||
/* process the word array */
|
||||
for (t = 16; t < 80; t++) {
|
||||
TEMP = W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16];
|
||||
W[t] = S1(TEMP);
|
||||
}
|
||||
|
||||
A = ctx->H[0];
|
||||
B = ctx->H[1];
|
||||
C = ctx->H[2];
|
||||
D = ctx->H[3];
|
||||
E = ctx->H[4];
|
||||
|
||||
for (t = 0; t < 20; t++) {
|
||||
TEMP = S5(A) + f0(B, C, D) + E + W[t] + SHA_K0;
|
||||
E = D;
|
||||
D = C;
|
||||
C = S30(B);
|
||||
B = A;
|
||||
A = TEMP;
|
||||
}
|
||||
for (; t < 40; t++) {
|
||||
TEMP = S5(A) + f1(B, C, D) + E + W[t] + SHA_K1;
|
||||
E = D;
|
||||
D = C;
|
||||
C = S30(B);
|
||||
B = A;
|
||||
A = TEMP;
|
||||
}
|
||||
for (; t < 60; t++) {
|
||||
TEMP = S5(A) + f2(B, C, D) + E + W[t] + SHA_K2;
|
||||
E = D;
|
||||
D = C;
|
||||
C = S30(B);
|
||||
B = A;
|
||||
A = TEMP;
|
||||
}
|
||||
for (; t < 80; t++) {
|
||||
TEMP = S5(A) + f3(B, C, D) + E + W[t] + SHA_K3;
|
||||
E = D;
|
||||
D = C;
|
||||
C = S30(B);
|
||||
B = A;
|
||||
A = TEMP;
|
||||
}
|
||||
|
||||
ctx->H[0] += A;
|
||||
ctx->H[1] += B;
|
||||
ctx->H[2] += C;
|
||||
ctx->H[3] += D;
|
||||
ctx->H[4] += E;
|
||||
}
|
||||
|
||||
debug_print0(srtp_mod_sha1, "(final) running srtp_sha1_core()");
|
||||
|
||||
if (ctx->octets_in_buffer >= 56) {
|
||||
debug_print0(srtp_mod_sha1, "(final) running srtp_sha1_core() again");
|
||||
|
||||
/* we need to do one final run of the compression algo */
|
||||
|
||||
/*
|
||||
* set initial part of word array to zeros, and set the
|
||||
* final part to the number of bits in the message
|
||||
*/
|
||||
for (i = 0; i < 15; i++) {
|
||||
W[i] = 0x0;
|
||||
}
|
||||
W[15] = ctx->num_bits_in_msg;
|
||||
|
||||
/* process the word array */
|
||||
for (t = 16; t < 80; t++) {
|
||||
TEMP = W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16];
|
||||
W[t] = S1(TEMP);
|
||||
}
|
||||
|
||||
A = ctx->H[0];
|
||||
B = ctx->H[1];
|
||||
C = ctx->H[2];
|
||||
D = ctx->H[3];
|
||||
E = ctx->H[4];
|
||||
|
||||
for (t = 0; t < 20; t++) {
|
||||
TEMP = S5(A) + f0(B, C, D) + E + W[t] + SHA_K0;
|
||||
E = D;
|
||||
D = C;
|
||||
C = S30(B);
|
||||
B = A;
|
||||
A = TEMP;
|
||||
}
|
||||
for (; t < 40; t++) {
|
||||
TEMP = S5(A) + f1(B, C, D) + E + W[t] + SHA_K1;
|
||||
E = D;
|
||||
D = C;
|
||||
C = S30(B);
|
||||
B = A;
|
||||
A = TEMP;
|
||||
}
|
||||
for (; t < 60; t++) {
|
||||
TEMP = S5(A) + f2(B, C, D) + E + W[t] + SHA_K2;
|
||||
E = D;
|
||||
D = C;
|
||||
C = S30(B);
|
||||
B = A;
|
||||
A = TEMP;
|
||||
}
|
||||
for (; t < 80; t++) {
|
||||
TEMP = S5(A) + f3(B, C, D) + E + W[t] + SHA_K3;
|
||||
E = D;
|
||||
D = C;
|
||||
C = S30(B);
|
||||
B = A;
|
||||
A = TEMP;
|
||||
}
|
||||
|
||||
ctx->H[0] += A;
|
||||
ctx->H[1] += B;
|
||||
ctx->H[2] += C;
|
||||
ctx->H[3] += D;
|
||||
ctx->H[4] += E;
|
||||
}
|
||||
|
||||
/* copy result into output buffer */
|
||||
output[0] = be32_to_cpu(ctx->H[0]);
|
||||
output[1] = be32_to_cpu(ctx->H[1]);
|
||||
output[2] = be32_to_cpu(ctx->H[2]);
|
||||
output[3] = be32_to_cpu(ctx->H[3]);
|
||||
output[4] = be32_to_cpu(ctx->H[4]);
|
||||
|
||||
/* indicate that message buffer in context is empty */
|
||||
ctx->octets_in_buffer = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* aes.h
|
||||
*
|
||||
* header file for the AES block cipher
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AES_H
|
||||
#define AES_H
|
||||
|
||||
#include "datatypes.h"
|
||||
#include "err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* aes internals */
|
||||
|
||||
typedef struct {
|
||||
v128_t round[15];
|
||||
int num_rounds;
|
||||
} srtp_aes_expanded_key_t;
|
||||
|
||||
srtp_err_status_t srtp_aes_expand_encryption_key(
|
||||
const uint8_t *key,
|
||||
int key_len,
|
||||
srtp_aes_expanded_key_t *expanded_key);
|
||||
|
||||
srtp_err_status_t srtp_aes_expand_decryption_key(
|
||||
const uint8_t *key,
|
||||
int key_len,
|
||||
srtp_aes_expanded_key_t *expanded_key);
|
||||
|
||||
void srtp_aes_encrypt(v128_t *plaintext,
|
||||
const srtp_aes_expanded_key_t *exp_key);
|
||||
|
||||
void srtp_aes_decrypt(v128_t *plaintext,
|
||||
const srtp_aes_expanded_key_t *exp_key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AES_H */
|
||||
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* aes_gcm.h
|
||||
*
|
||||
* Header for AES Galois Counter Mode.
|
||||
*
|
||||
* John A. Foley
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AES_GCM_H
|
||||
#define AES_GCM_H
|
||||
|
||||
#include "cipher.h"
|
||||
#include "srtp.h"
|
||||
#include "datatypes.h"
|
||||
|
||||
#ifdef OPENSSL
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/aes.h>
|
||||
|
||||
typedef struct {
|
||||
int key_size;
|
||||
int tag_len;
|
||||
EVP_CIPHER_CTX *ctx;
|
||||
srtp_cipher_direction_t dir;
|
||||
} srtp_aes_gcm_ctx_t;
|
||||
|
||||
#endif /* OPENSSL */
|
||||
|
||||
#ifdef MBEDTLS
|
||||
#define MAX_AD_SIZE 2048
|
||||
#include <mbedtls/aes.h>
|
||||
#include <mbedtls/gcm.h>
|
||||
|
||||
typedef struct {
|
||||
int key_size;
|
||||
int tag_len;
|
||||
int aad_size;
|
||||
int iv_len;
|
||||
uint8_t iv[12];
|
||||
uint8_t tag[16];
|
||||
uint8_t aad[MAX_AD_SIZE];
|
||||
mbedtls_gcm_context *ctx;
|
||||
srtp_cipher_direction_t dir;
|
||||
} srtp_aes_gcm_ctx_t;
|
||||
|
||||
#endif /* MBEDTLS */
|
||||
|
||||
#ifdef NSS
|
||||
|
||||
#define NSS_PKCS11_2_0_COMPAT 1
|
||||
|
||||
#include <nss.h>
|
||||
#include <pk11pub.h>
|
||||
|
||||
#define MAX_AD_SIZE 2048
|
||||
|
||||
typedef struct {
|
||||
int key_size;
|
||||
int tag_size;
|
||||
srtp_cipher_direction_t dir;
|
||||
NSSInitContext *nss;
|
||||
PK11SymKey *key;
|
||||
uint8_t iv[12];
|
||||
uint8_t aad[MAX_AD_SIZE];
|
||||
int aad_size;
|
||||
CK_GCM_PARAMS params;
|
||||
uint8_t tag[16];
|
||||
} srtp_aes_gcm_ctx_t;
|
||||
|
||||
#endif /* NSS */
|
||||
|
||||
#endif /* AES_GCM_H */
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* aes_icm.h
|
||||
*
|
||||
* Header for AES Integer Counter Mode.
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AES_ICM_H
|
||||
#define AES_ICM_H
|
||||
|
||||
#include "aes.h"
|
||||
#include "cipher.h"
|
||||
|
||||
typedef struct {
|
||||
v128_t counter; /* holds the counter value */
|
||||
v128_t offset; /* initial offset value */
|
||||
v128_t keystream_buffer; /* buffers bytes of keystream */
|
||||
srtp_aes_expanded_key_t expanded_key; /* the cipher key */
|
||||
int bytes_in_buffer; /* number of unused bytes in buffer */
|
||||
int key_size; /* AES key size + 14 byte SALT */
|
||||
} srtp_aes_icm_ctx_t;
|
||||
|
||||
#endif /* AES_ICM_H */
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* aes_icm.h
|
||||
*
|
||||
* Header for AES Integer Counter Mode.
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AES_ICM_H
|
||||
#define AES_ICM_H
|
||||
|
||||
#include "cipher.h"
|
||||
#include "datatypes.h"
|
||||
|
||||
#ifdef OPENSSL
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/aes.h>
|
||||
|
||||
typedef struct {
|
||||
v128_t counter; /* holds the counter value */
|
||||
v128_t offset; /* initial offset value */
|
||||
int key_size;
|
||||
EVP_CIPHER_CTX *ctx;
|
||||
} srtp_aes_icm_ctx_t;
|
||||
|
||||
#endif /* OPENSSL */
|
||||
|
||||
#ifdef MBEDTLS
|
||||
|
||||
#include <mbedtls/aes.h>
|
||||
typedef struct {
|
||||
v128_t counter; /* holds the counter value */
|
||||
v128_t offset; /* initial offset value */
|
||||
v128_t stream_block;
|
||||
size_t nc_off;
|
||||
int key_size;
|
||||
mbedtls_aes_context *ctx;
|
||||
} srtp_aes_icm_ctx_t;
|
||||
|
||||
#endif /* MBEDTLS */
|
||||
|
||||
#ifdef NSS
|
||||
|
||||
#define NSS_PKCS11_2_0_COMPAT 1
|
||||
|
||||
#include <nss.h>
|
||||
#include <pk11pub.h>
|
||||
|
||||
typedef struct {
|
||||
v128_t counter;
|
||||
v128_t offset;
|
||||
int key_size;
|
||||
uint8_t iv[16];
|
||||
NSSInitContext *nss;
|
||||
PK11SymKey *key;
|
||||
PK11Context *ctx;
|
||||
} srtp_aes_icm_ctx_t;
|
||||
|
||||
#endif /* NSS */
|
||||
|
||||
#endif /* AES_ICM_H */
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* alloc.h
|
||||
*
|
||||
* interface to memory allocation and deallocation, with optional debugging
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_ALLOC_H
|
||||
#define CRYPTO_ALLOC_H
|
||||
|
||||
#include "datatypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* srtp_crypto_alloc
|
||||
*
|
||||
* Allocates a block of memory of given size. The memory will be
|
||||
* initialized to zero's. Free the memory with a call to srtp_crypto_free.
|
||||
*
|
||||
* returns pointer to memory on success or else NULL
|
||||
*/
|
||||
void *srtp_crypto_alloc(size_t size);
|
||||
|
||||
/*
|
||||
* srtp_crypto_free
|
||||
*
|
||||
* Frees the block of memory ptr previously allocated with
|
||||
* srtp_crypto_alloc
|
||||
*/
|
||||
void srtp_crypto_free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CRYPTO_ALLOC_H */
|
||||
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
* auth.h
|
||||
*
|
||||
* common interface to authentication functions
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRTP_AUTH_H
|
||||
#define SRTP_AUTH_H
|
||||
|
||||
#include "srtp.h"
|
||||
#include "crypto_types.h" /* for values of auth_type_id_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef const struct srtp_auth_type_t *srtp_auth_type_pointer;
|
||||
typedef struct srtp_auth_t *srtp_auth_pointer_t;
|
||||
|
||||
typedef srtp_err_status_t (*srtp_auth_alloc_func)(srtp_auth_pointer_t *ap,
|
||||
int key_len,
|
||||
int out_len);
|
||||
|
||||
typedef srtp_err_status_t (*srtp_auth_init_func)(void *state,
|
||||
const uint8_t *key,
|
||||
int key_len);
|
||||
|
||||
typedef srtp_err_status_t (*srtp_auth_dealloc_func)(srtp_auth_pointer_t ap);
|
||||
|
||||
typedef srtp_err_status_t (*srtp_auth_compute_func)(void *state,
|
||||
const uint8_t *buffer,
|
||||
int octets_to_auth,
|
||||
int tag_len,
|
||||
uint8_t *tag);
|
||||
|
||||
typedef srtp_err_status_t (*srtp_auth_update_func)(void *state,
|
||||
const uint8_t *buffer,
|
||||
int octets_to_auth);
|
||||
|
||||
typedef srtp_err_status_t (*srtp_auth_start_func)(void *state);
|
||||
|
||||
/* some syntactic sugar on these function types */
|
||||
#define srtp_auth_type_alloc(at, a, klen, outlen) \
|
||||
((at)->alloc((a), (klen), (outlen)))
|
||||
|
||||
#define srtp_auth_init(a, key) \
|
||||
(((a)->type)->init((a)->state, (key), ((a)->key_len)))
|
||||
|
||||
#define srtp_auth_compute(a, buf, len, res) \
|
||||
(((a)->type)->compute((a)->state, (buf), (len), (a)->out_len, (res)))
|
||||
|
||||
#define srtp_auth_update(a, buf, len) \
|
||||
(((a)->type)->update((a)->state, (buf), (len)))
|
||||
|
||||
#define srtp_auth_start(a) (((a)->type)->start((a)->state))
|
||||
|
||||
#define srtp_auth_dealloc(c) (((c)->type)->dealloc(c))
|
||||
|
||||
/* functions to get information about a particular auth_t */
|
||||
int srtp_auth_get_key_length(const struct srtp_auth_t *a);
|
||||
|
||||
int srtp_auth_get_tag_length(const struct srtp_auth_t *a);
|
||||
|
||||
int srtp_auth_get_prefix_length(const struct srtp_auth_t *a);
|
||||
|
||||
/*
|
||||
* srtp_auth_test_case_t is a (list of) key/message/tag values that are
|
||||
* known to be correct for a particular cipher. this data can be used
|
||||
* to test an implementation in an on-the-fly self test of the
|
||||
* correctness of the implementation. (see the srtp_auth_type_self_test()
|
||||
* function below)
|
||||
*/
|
||||
typedef struct srtp_auth_test_case_t {
|
||||
int key_length_octets; /* octets in key */
|
||||
const uint8_t *key; /* key */
|
||||
int data_length_octets; /* octets in data */
|
||||
const uint8_t *data; /* data */
|
||||
int tag_length_octets; /* octets in tag */
|
||||
const uint8_t *tag; /* tag */
|
||||
const struct srtp_auth_test_case_t
|
||||
*next_test_case; /* pointer to next testcase */
|
||||
} srtp_auth_test_case_t;
|
||||
|
||||
/* srtp_auth_type_t */
|
||||
typedef struct srtp_auth_type_t {
|
||||
srtp_auth_alloc_func alloc;
|
||||
srtp_auth_dealloc_func dealloc;
|
||||
srtp_auth_init_func init;
|
||||
srtp_auth_compute_func compute;
|
||||
srtp_auth_update_func update;
|
||||
srtp_auth_start_func start;
|
||||
const char *description;
|
||||
const srtp_auth_test_case_t *test_data;
|
||||
srtp_auth_type_id_t id;
|
||||
} srtp_auth_type_t;
|
||||
|
||||
typedef struct srtp_auth_t {
|
||||
const srtp_auth_type_t *type;
|
||||
void *state;
|
||||
int out_len; /* length of output tag in octets */
|
||||
int key_len; /* length of key in octets */
|
||||
int prefix_len; /* length of keystream prefix */
|
||||
} srtp_auth_t;
|
||||
|
||||
/*
|
||||
* srtp_auth_type_self_test() tests an auth_type against test cases
|
||||
* provided in an array of values of key/message/tag that is known to
|
||||
* be good
|
||||
*/
|
||||
srtp_err_status_t srtp_auth_type_self_test(const srtp_auth_type_t *at);
|
||||
|
||||
/*
|
||||
* srtp_auth_type_test() tests an auth_type against external test cases
|
||||
* provided in an array of values of key/message/tag that is known to
|
||||
* be good
|
||||
*/
|
||||
srtp_err_status_t srtp_auth_type_test(const srtp_auth_type_t *at,
|
||||
const srtp_auth_test_case_t *test_data);
|
||||
|
||||
/*
|
||||
* srtp_replace_auth_type(ct, id)
|
||||
*
|
||||
* replaces srtp's kernel's auth type implementation for the auth_type id
|
||||
* with a new one passed in externally. The new auth type must pass all the
|
||||
* existing auth_type's self tests as well as its own.
|
||||
*/
|
||||
srtp_err_status_t srtp_replace_auth_type(const srtp_auth_type_t *ct,
|
||||
srtp_auth_type_id_t id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SRTP_AUTH_H */
|
||||
@@ -1,248 +0,0 @@
|
||||
/*
|
||||
* cipher.h
|
||||
*
|
||||
* common interface to ciphers
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRTP_CIPHER_H
|
||||
#define SRTP_CIPHER_H
|
||||
|
||||
#include "srtp.h"
|
||||
#include "crypto_types.h" /* for values of cipher_type_id_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* srtp_cipher_direction_t defines a particular cipher operation.
|
||||
*
|
||||
* A srtp_cipher_direction_t is an enum that describes a particular cipher
|
||||
* operation, i.e. encryption or decryption. For some ciphers, this
|
||||
* distinction does not matter, but for others, it is essential.
|
||||
*/
|
||||
typedef enum {
|
||||
srtp_direction_encrypt, /**< encryption (convert plaintext to ciphertext) */
|
||||
srtp_direction_decrypt, /**< decryption (convert ciphertext to plaintext) */
|
||||
srtp_direction_any /**< encryption or decryption */
|
||||
} srtp_cipher_direction_t;
|
||||
|
||||
/*
|
||||
* the srtp_cipher_pointer_t definition is needed
|
||||
* as srtp_cipher_t is not yet defined
|
||||
*/
|
||||
typedef struct srtp_cipher_t *srtp_cipher_pointer_t;
|
||||
|
||||
/*
|
||||
* a srtp_cipher_alloc_func_t allocates (but does not initialize) a
|
||||
* srtp_cipher_t
|
||||
*/
|
||||
typedef srtp_err_status_t (*srtp_cipher_alloc_func_t)(srtp_cipher_pointer_t *cp,
|
||||
int key_len,
|
||||
int tag_len);
|
||||
|
||||
/*
|
||||
* a srtp_cipher_init_func_t [re-]initializes a cipher_t with a given key
|
||||
*/
|
||||
typedef srtp_err_status_t (*srtp_cipher_init_func_t)(void *state,
|
||||
const uint8_t *key);
|
||||
|
||||
/* a srtp_cipher_dealloc_func_t de-allocates a cipher_t */
|
||||
typedef srtp_err_status_t (*srtp_cipher_dealloc_func_t)(
|
||||
srtp_cipher_pointer_t cp);
|
||||
|
||||
/*
|
||||
* a srtp_cipher_set_aad_func_t processes the AAD data for AEAD ciphers
|
||||
*/
|
||||
typedef srtp_err_status_t (*srtp_cipher_set_aad_func_t)(void *state,
|
||||
const uint8_t *aad,
|
||||
uint32_t aad_len);
|
||||
|
||||
/* a srtp_cipher_encrypt_func_t encrypts data in-place */
|
||||
typedef srtp_err_status_t (*srtp_cipher_encrypt_func_t)(
|
||||
void *state,
|
||||
uint8_t *buffer,
|
||||
unsigned int *octets_to_encrypt);
|
||||
|
||||
/* a srtp_cipher_decrypt_func_t decrypts data in-place */
|
||||
typedef srtp_err_status_t (*srtp_cipher_decrypt_func_t)(
|
||||
void *state,
|
||||
uint8_t *buffer,
|
||||
unsigned int *octets_to_decrypt);
|
||||
|
||||
/*
|
||||
* a srtp_cipher_set_iv_func_t function sets the current initialization vector
|
||||
*/
|
||||
typedef srtp_err_status_t (*srtp_cipher_set_iv_func_t)(
|
||||
void *state,
|
||||
uint8_t *iv,
|
||||
srtp_cipher_direction_t direction);
|
||||
|
||||
/*
|
||||
* a cipher_get_tag_func_t function is used to get the authentication
|
||||
* tag that was calculated by an AEAD cipher.
|
||||
*/
|
||||
typedef srtp_err_status_t (*srtp_cipher_get_tag_func_t)(void *state,
|
||||
uint8_t *tag,
|
||||
uint32_t *len);
|
||||
|
||||
/*
|
||||
* srtp_cipher_test_case_t is a (list of) key, salt, plaintext, ciphertext,
|
||||
* and aad values that are known to be correct for a
|
||||
* particular cipher. this data can be used to test an implementation
|
||||
* in an on-the-fly self test of the correctness of the implementation.
|
||||
* (see the srtp_cipher_type_self_test() function below)
|
||||
*/
|
||||
typedef struct srtp_cipher_test_case_t {
|
||||
int key_length_octets; /* octets in key */
|
||||
const uint8_t *key; /* key */
|
||||
uint8_t *idx; /* packet index */
|
||||
unsigned int plaintext_length_octets; /* octets in plaintext */
|
||||
const uint8_t *plaintext; /* plaintext */
|
||||
unsigned int ciphertext_length_octets; /* octets in plaintext */
|
||||
const uint8_t *ciphertext; /* ciphertext */
|
||||
int aad_length_octets; /* octets in AAD */
|
||||
const uint8_t *aad; /* AAD */
|
||||
int tag_length_octets; /* Length of AEAD tag */
|
||||
const struct srtp_cipher_test_case_t
|
||||
*next_test_case; /* pointer to next testcase */
|
||||
} srtp_cipher_test_case_t;
|
||||
|
||||
/* srtp_cipher_type_t defines the 'metadata' for a particular cipher type */
|
||||
typedef struct srtp_cipher_type_t {
|
||||
srtp_cipher_alloc_func_t alloc;
|
||||
srtp_cipher_dealloc_func_t dealloc;
|
||||
srtp_cipher_init_func_t init;
|
||||
srtp_cipher_set_aad_func_t set_aad;
|
||||
srtp_cipher_encrypt_func_t encrypt;
|
||||
srtp_cipher_encrypt_func_t decrypt;
|
||||
srtp_cipher_set_iv_func_t set_iv;
|
||||
srtp_cipher_get_tag_func_t get_tag;
|
||||
const char *description;
|
||||
const srtp_cipher_test_case_t *test_data;
|
||||
srtp_cipher_type_id_t id;
|
||||
} srtp_cipher_type_t;
|
||||
|
||||
/*
|
||||
* srtp_cipher_t defines an instantiation of a particular cipher, with fixed
|
||||
* key length, key and salt values
|
||||
*/
|
||||
typedef struct srtp_cipher_t {
|
||||
const srtp_cipher_type_t *type;
|
||||
void *state;
|
||||
int key_len;
|
||||
int algorithm;
|
||||
} srtp_cipher_t;
|
||||
|
||||
/* some bookkeeping functions */
|
||||
int srtp_cipher_get_key_length(const srtp_cipher_t *c);
|
||||
|
||||
/*
|
||||
* srtp_cipher_type_self_test() tests a cipher against test cases provided in
|
||||
* an array of values of key/srtp_xtd_seq_num_t/plaintext/ciphertext
|
||||
* that is known to be good
|
||||
*/
|
||||
srtp_err_status_t srtp_cipher_type_self_test(const srtp_cipher_type_t *ct);
|
||||
|
||||
/*
|
||||
* srtp_cipher_type_test() tests a cipher against external test cases provided
|
||||
* in
|
||||
* an array of values of key/srtp_xtd_seq_num_t/plaintext/ciphertext
|
||||
* that is known to be good
|
||||
*/
|
||||
srtp_err_status_t srtp_cipher_type_test(
|
||||
const srtp_cipher_type_t *ct,
|
||||
const srtp_cipher_test_case_t *test_data);
|
||||
|
||||
/*
|
||||
* srtp_cipher_bits_per_second(c, l, t) computes (an estimate of) the
|
||||
* number of bits that a cipher implementation can encrypt in a second
|
||||
*
|
||||
* c is a cipher (which MUST be allocated and initialized already), l
|
||||
* is the length in octets of the test data to be encrypted, and t is
|
||||
* the number of trials
|
||||
*
|
||||
* if an error is encountered, then the value 0 is returned
|
||||
*/
|
||||
uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c,
|
||||
int octets_in_buffer,
|
||||
int num_trials);
|
||||
|
||||
srtp_err_status_t srtp_cipher_type_alloc(const srtp_cipher_type_t *ct,
|
||||
srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen);
|
||||
srtp_err_status_t srtp_cipher_dealloc(srtp_cipher_t *c);
|
||||
srtp_err_status_t srtp_cipher_init(srtp_cipher_t *c, const uint8_t *key);
|
||||
srtp_err_status_t srtp_cipher_set_iv(srtp_cipher_t *c,
|
||||
uint8_t *iv,
|
||||
int direction);
|
||||
srtp_err_status_t srtp_cipher_output(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *num_octets_to_output);
|
||||
srtp_err_status_t srtp_cipher_encrypt(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *num_octets_to_output);
|
||||
srtp_err_status_t srtp_cipher_decrypt(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *num_octets_to_output);
|
||||
srtp_err_status_t srtp_cipher_get_tag(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *tag_len);
|
||||
srtp_err_status_t srtp_cipher_set_aad(srtp_cipher_t *c,
|
||||
const uint8_t *aad,
|
||||
uint32_t aad_len);
|
||||
|
||||
/*
|
||||
* srtp_replace_cipher_type(ct, id)
|
||||
*
|
||||
* replaces srtp's existing cipher implementation for the cipher_type id
|
||||
* with a new one passed in externally. The new cipher must pass all the
|
||||
* existing cipher_type's self tests as well as its own.
|
||||
*/
|
||||
srtp_err_status_t srtp_replace_cipher_type(const srtp_cipher_type_t *ct,
|
||||
srtp_cipher_type_id_t id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SRTP_CIPHER_H */
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRTP_CIHPER_PRIV_H
|
||||
#define SRTP_CIHPER_PRIV_H
|
||||
|
||||
#include "cipher.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* A trivial platform independent random source.
|
||||
* For use in test only.
|
||||
*/
|
||||
void srtp_cipher_rand_for_tests(void *dest, uint32_t len);
|
||||
|
||||
/*
|
||||
* A trivial platform independent 32 bit random number.
|
||||
* For use in test only.
|
||||
*/
|
||||
uint32_t srtp_cipher_rand_u32_for_tests(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SRTP_CIPHER_PRIV_H */
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CIHPER_TYPES_H
|
||||
#define CIHPER_TYPES_H
|
||||
|
||||
#include "cipher.h"
|
||||
#include "auth.h"
|
||||
|
||||
/*
|
||||
* cipher types that can be included in the kernel
|
||||
*/
|
||||
|
||||
extern const srtp_cipher_type_t srtp_null_cipher;
|
||||
extern const srtp_cipher_type_t srtp_aes_icm_128;
|
||||
extern const srtp_cipher_type_t srtp_aes_icm_256;
|
||||
#ifdef GCM
|
||||
extern const srtp_cipher_type_t srtp_aes_icm_192;
|
||||
extern const srtp_cipher_type_t srtp_aes_gcm_128;
|
||||
extern const srtp_cipher_type_t srtp_aes_gcm_256;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* auth func types that can be included in the kernel
|
||||
*/
|
||||
|
||||
extern const srtp_auth_type_t srtp_null_auth;
|
||||
extern const srtp_auth_type_t srtp_hmac;
|
||||
|
||||
/*
|
||||
* other generic debug modules that can be included in the kernel
|
||||
*/
|
||||
|
||||
extern srtp_debug_module_t srtp_mod_auth;
|
||||
extern srtp_debug_module_t srtp_mod_cipher;
|
||||
extern srtp_debug_module_t srtp_mod_alloc;
|
||||
|
||||
/* debug modules for cipher types */
|
||||
extern srtp_debug_module_t srtp_mod_aes_icm;
|
||||
|
||||
#if defined(OPENSSL) || defined(MBEDTLS) || defined(NSS)
|
||||
extern srtp_debug_module_t srtp_mod_aes_gcm;
|
||||
#endif
|
||||
|
||||
/* debug modules for auth types */
|
||||
extern srtp_debug_module_t srtp_mod_hmac;
|
||||
#endif
|
||||
@@ -1,215 +0,0 @@
|
||||
/*
|
||||
* crypto_kernel.h
|
||||
*
|
||||
* header for the cryptographic kernel
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_KERNEL
|
||||
#define CRYPTO_KERNEL
|
||||
|
||||
#include "cipher.h"
|
||||
#include "auth.h"
|
||||
#include "err.h"
|
||||
#include "crypto_types.h"
|
||||
#include "key.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* crypto_kernel_state_t defines the possible states:
|
||||
*
|
||||
* insecure - not yet initialized
|
||||
* secure - initialized and passed self-tests
|
||||
*/
|
||||
typedef enum {
|
||||
srtp_crypto_kernel_state_insecure,
|
||||
srtp_crypto_kernel_state_secure
|
||||
} srtp_crypto_kernel_state_t;
|
||||
|
||||
/*
|
||||
* linked list of cipher types
|
||||
*/
|
||||
typedef struct srtp_kernel_cipher_type {
|
||||
srtp_cipher_type_id_t id;
|
||||
const srtp_cipher_type_t *cipher_type;
|
||||
struct srtp_kernel_cipher_type *next;
|
||||
} srtp_kernel_cipher_type_t;
|
||||
|
||||
/*
|
||||
* linked list of auth types
|
||||
*/
|
||||
typedef struct srtp_kernel_auth_type {
|
||||
srtp_auth_type_id_t id;
|
||||
const srtp_auth_type_t *auth_type;
|
||||
struct srtp_kernel_auth_type *next;
|
||||
} srtp_kernel_auth_type_t;
|
||||
|
||||
/*
|
||||
* linked list of debug modules
|
||||
*/
|
||||
typedef struct srtp_kernel_debug_module {
|
||||
srtp_debug_module_t *mod;
|
||||
struct srtp_kernel_debug_module *next;
|
||||
} srtp_kernel_debug_module_t;
|
||||
|
||||
/*
|
||||
* crypto_kernel_t is the data structure for the crypto kernel
|
||||
*
|
||||
* note that there is *exactly one* instance of this data type,
|
||||
* a global variable defined in crypto_kernel.c
|
||||
*/
|
||||
typedef struct {
|
||||
srtp_crypto_kernel_state_t state; /* current state of kernel */
|
||||
srtp_kernel_cipher_type_t *cipher_type_list; /* list of all cipher types */
|
||||
srtp_kernel_auth_type_t *auth_type_list; /* list of all auth func types */
|
||||
srtp_kernel_debug_module_t
|
||||
*debug_module_list; /* list of all debug modules */
|
||||
} srtp_crypto_kernel_t;
|
||||
|
||||
/*
|
||||
* srtp_crypto_kernel_t external api
|
||||
*/
|
||||
|
||||
/*
|
||||
* The function srtp_crypto_kernel_init() initialized the crypto kernel and
|
||||
* runs the self-test operations on the random number generators and
|
||||
* crypto algorithms. Possible return values are:
|
||||
*
|
||||
* srtp_err_status_ok initialization successful
|
||||
* <other> init failure
|
||||
*
|
||||
* If any value other than srtp_err_status_ok is returned, the
|
||||
* crypto_kernel MUST NOT be used.
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_init(void);
|
||||
|
||||
/*
|
||||
* The function srtp_crypto_kernel_shutdown() de-initializes the
|
||||
* crypto_kernel, zeroizes keys and other cryptographic material, and
|
||||
* deallocates any dynamically allocated memory. Possible return
|
||||
* values are:
|
||||
*
|
||||
* srtp_err_status_ok shutdown successful
|
||||
* <other> shutdown failure
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_shutdown(void);
|
||||
|
||||
/*
|
||||
* The function srtp_crypto_kernel_stats() checks the the crypto_kernel,
|
||||
* running tests on the ciphers, auth funcs, and rng, and prints out a
|
||||
* status report. Possible return values are:
|
||||
*
|
||||
* srtp_err_status_ok all tests were passed
|
||||
* <other> a test failed
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_status(void);
|
||||
|
||||
/*
|
||||
* srtp_crypto_kernel_list_debug_modules() outputs a list of debugging modules
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_list_debug_modules(void);
|
||||
|
||||
/*
|
||||
* srtp_crypto_kernel_load_cipher_type()
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_load_cipher_type(
|
||||
const srtp_cipher_type_t *ct,
|
||||
srtp_cipher_type_id_t id);
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_load_auth_type(const srtp_auth_type_t *ct,
|
||||
srtp_auth_type_id_t id);
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_load_debug_module(
|
||||
srtp_debug_module_t *new_dm);
|
||||
|
||||
/*
|
||||
* srtp_crypto_kernel_alloc_cipher(id, cp, key_len);
|
||||
*
|
||||
* allocates a cipher of type id at location *cp, with key length
|
||||
* key_len octets. Return values are:
|
||||
*
|
||||
* srtp_err_status_ok no problems
|
||||
* srtp_err_status_alloc_fail an allocation failure occured
|
||||
* srtp_err_status_fail couldn't find cipher with identifier 'id'
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_alloc_cipher(srtp_cipher_type_id_t id,
|
||||
srtp_cipher_pointer_t *cp,
|
||||
int key_len,
|
||||
int tag_len);
|
||||
|
||||
/*
|
||||
* srtp_crypto_kernel_alloc_auth(id, ap, key_len, tag_len);
|
||||
*
|
||||
* allocates an auth function of type id at location *ap, with key
|
||||
* length key_len octets and output tag length of tag_len. Return
|
||||
* values are:
|
||||
*
|
||||
* srtp_err_status_ok no problems
|
||||
* srtp_err_status_alloc_fail an allocation failure occured
|
||||
* srtp_err_status_fail couldn't find auth with identifier 'id'
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_alloc_auth(srtp_auth_type_id_t id,
|
||||
srtp_auth_pointer_t *ap,
|
||||
int key_len,
|
||||
int tag_len);
|
||||
|
||||
/*
|
||||
* srtp_crypto_kernel_set_debug_module(mod_name, v)
|
||||
*
|
||||
* sets dynamic debugging to the value v (0 for off, 1 for on) for the
|
||||
* debug module with the name mod_name
|
||||
*
|
||||
* returns srtp_err_status_ok on success, srtp_err_status_fail otherwise
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_set_debug_module(const char *mod_name,
|
||||
int v);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CRYPTO_KERNEL */
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* crypto_types.h
|
||||
*
|
||||
* constants for cipher types and auth func types
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRTP_CRYPTO_TYPES_H
|
||||
#define SRTP_CRYPTO_TYPES_H
|
||||
|
||||
/*
|
||||
* The null cipher performs no encryption.
|
||||
*
|
||||
* The SRTP_NULL_CIPHER leaves its inputs unaltered, during both the
|
||||
* encryption and decryption operations. This cipher can be chosen
|
||||
* to indicate that no encryption is to be performed.
|
||||
*/
|
||||
#define SRTP_NULL_CIPHER 0
|
||||
|
||||
/*
|
||||
* AES-128 Integer Counter Mode (AES ICM)
|
||||
*
|
||||
* AES-128 ICM is the variant of counter mode that is used by
|
||||
* Secure RTP. This cipher uses a 16-octet key concatenated with a
|
||||
* 14-octet offset (or salt) value.
|
||||
*/
|
||||
#define SRTP_AES_ICM_128 1
|
||||
|
||||
/*
|
||||
* AES-192 Integer Counter Mode (AES ICM)
|
||||
*
|
||||
* AES-128 ICM is the variant of counter mode that is used by
|
||||
* Secure RTP. This cipher uses a 24-octet key concatenated with a
|
||||
* 14-octet offset (or salt) value.
|
||||
*/
|
||||
#define SRTP_AES_ICM_192 4
|
||||
|
||||
/*
|
||||
* AES-256 Integer Counter Mode (AES ICM)
|
||||
*
|
||||
* AES-128 ICM is the variant of counter mode that is used by
|
||||
* Secure RTP. This cipher uses a 32-octet key concatenated with a
|
||||
* 14-octet offset (or salt) value.
|
||||
*/
|
||||
#define SRTP_AES_ICM_256 5
|
||||
|
||||
/*
|
||||
* AES-128_GCM Galois Counter Mode (AES GCM)
|
||||
*
|
||||
* AES-128 GCM is the variant of galois counter mode that is used by
|
||||
* Secure RTP. This cipher uses a 16-octet key.
|
||||
*/
|
||||
#define SRTP_AES_GCM_128 6
|
||||
|
||||
/*
|
||||
* AES-256_GCM Galois Counter Mode (AES GCM)
|
||||
*
|
||||
* AES-256 GCM is the variant of galois counter mode that is used by
|
||||
* Secure RTP. This cipher uses a 32-octet key.
|
||||
*/
|
||||
#define SRTP_AES_GCM_256 7
|
||||
|
||||
/*
|
||||
* The null authentication function performs no authentication.
|
||||
*
|
||||
* The NULL_AUTH function does nothing, and can be selected to indicate
|
||||
* that authentication should not be performed.
|
||||
*/
|
||||
#define SRTP_NULL_AUTH 0
|
||||
|
||||
/*
|
||||
* HMAC-SHA1
|
||||
*
|
||||
* SRTP_HMAC_SHA1 implements the Hash-based MAC using the NIST Secure
|
||||
* Hash Algorithm version 1 (SHA1).
|
||||
*/
|
||||
#define SRTP_HMAC_SHA1 3
|
||||
|
||||
#endif /* SRTP_CRYPTO_TYPES_H */
|
||||
@@ -1,244 +0,0 @@
|
||||
/*
|
||||
* datatypes.h
|
||||
*
|
||||
* data types for bit vectors and finite fields
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DATATYPES_H
|
||||
#define DATATYPES_H
|
||||
|
||||
#include "integers.h" /* definitions of uint32_t, et cetera */
|
||||
#include "alloc.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#elif defined HAVE_WINSOCK2_H
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#error "Platform not recognized"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef union {
|
||||
uint8_t v8[16];
|
||||
uint16_t v16[8];
|
||||
uint32_t v32[4];
|
||||
uint64_t v64[2];
|
||||
} v128_t;
|
||||
|
||||
#define MAX_PRINT_STRING_LEN 1024
|
||||
|
||||
char *srtp_octet_string_hex_string(const void *str, int length);
|
||||
|
||||
char *v128_bit_string(v128_t *x);
|
||||
|
||||
char *v128_hex_string(v128_t *x);
|
||||
|
||||
void v128_copy_octet_string(v128_t *x, const uint8_t s[16]);
|
||||
|
||||
void v128_left_shift(v128_t *x, int shift_index);
|
||||
|
||||
/*
|
||||
* the following macros define the data manipulation functions
|
||||
*
|
||||
*/
|
||||
|
||||
#define v128_set_to_zero(x) \
|
||||
((x)->v32[0] = 0, (x)->v32[1] = 0, (x)->v32[2] = 0, (x)->v32[3] = 0)
|
||||
|
||||
#define v128_copy(x, y) \
|
||||
((x)->v32[0] = (y)->v32[0], (x)->v32[1] = (y)->v32[1], \
|
||||
(x)->v32[2] = (y)->v32[2], (x)->v32[3] = (y)->v32[3])
|
||||
|
||||
#define v128_xor(z, x, y) \
|
||||
((z)->v32[0] = (x)->v32[0] ^ (y)->v32[0], \
|
||||
(z)->v32[1] = (x)->v32[1] ^ (y)->v32[1], \
|
||||
(z)->v32[2] = (x)->v32[2] ^ (y)->v32[2], \
|
||||
(z)->v32[3] = (x)->v32[3] ^ (y)->v32[3])
|
||||
|
||||
/* ok for NO_64BIT_MATH if it can compare uint64_t's (even as structures) */
|
||||
#ifdef NO_64BIT_MATH
|
||||
#define v128_xor_eq(z, x) \
|
||||
((z)->v32[0] ^= (x)->v32[0], (z)->v32[1] ^= (x)->v32[1], \
|
||||
(z)->v32[2] ^= (x)->v32[2], (z)->v32[3] ^= (x)->v32[3])
|
||||
#else
|
||||
#define v128_xor_eq(z, x) \
|
||||
((z)->v64[0] ^= (x)->v64[0], (z)->v64[1] ^= (x)->v64[1])
|
||||
#endif
|
||||
|
||||
/* NOTE! This assumes an odd ordering! */
|
||||
/* This will not be compatible directly with math on some processors */
|
||||
/* bit 0 is first 32-bit word, low order bit. in little-endian, that's
|
||||
the first byte of the first 32-bit word. In big-endian, that's
|
||||
the 3rd byte of the first 32-bit word */
|
||||
/* The get/set bit code is used by the replay code ONLY, and it doesn't
|
||||
really care which bit is which. AES does care which bit is which, but
|
||||
doesn't use the 128-bit get/set or 128-bit shifts */
|
||||
|
||||
#define v128_get_bit(x, bit) (((((x)->v32[(bit) >> 5]) >> ((bit)&31)) & 1))
|
||||
|
||||
#define v128_set_bit(x, bit) \
|
||||
((((x)->v32[(bit) >> 5]) |= ((uint32_t)1 << ((bit)&31))))
|
||||
|
||||
#define v128_clear_bit(x, bit) \
|
||||
((((x)->v32[(bit) >> 5]) &= ~((uint32_t)1 << ((bit)&31))))
|
||||
|
||||
/*
|
||||
* srtp_octet_string_is_eq(a, b, len) returns 1 if the length len strings
|
||||
* a and b are not equal. It returns 0 otherwise. The running time of the
|
||||
* comparison depends only on len, making this safe to use for (e.g.)
|
||||
* verifying authentication tags.
|
||||
*/
|
||||
|
||||
int srtp_octet_string_is_eq(uint8_t *a, uint8_t *b, int len);
|
||||
|
||||
/*
|
||||
* A portable way to zero out memory as recommended by
|
||||
* https://cryptocoding.net/index.php/Coding_rules#Clean_memory_of_secret_data
|
||||
* This is used to zero memory when OPENSSL_cleanse() is not available.
|
||||
*/
|
||||
void srtp_cleanse(void *s, size_t len);
|
||||
|
||||
/*
|
||||
* Functions as a wrapper that delegates to either srtp_cleanse() or
|
||||
* OPENSSL_cleanse() if available to zero memory.
|
||||
*/
|
||||
void octet_string_set_to_zero(void *s, size_t len);
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
|
||||
/*
|
||||
* Convert big endian integers to CPU byte order.
|
||||
*/
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
/* Nothing to do. */
|
||||
#define be32_to_cpu(x) (x)
|
||||
#define be64_to_cpu(x) (x)
|
||||
#elif defined(HAVE_BYTESWAP_H)
|
||||
/* We have (hopefully) optimized versions in byteswap.h */
|
||||
#include <byteswap.h>
|
||||
#define be32_to_cpu(x) bswap_32((x))
|
||||
#define be64_to_cpu(x) bswap_64((x))
|
||||
#else /* WORDS_BIGENDIAN */
|
||||
|
||||
#if defined(__GNUC__) && defined(HAVE_X86)
|
||||
/* Fall back. */
|
||||
static inline uint32_t be32_to_cpu(uint32_t v)
|
||||
{
|
||||
/* optimized for x86. */
|
||||
asm("bswap %0" : "=r"(v) : "0"(v));
|
||||
return v;
|
||||
}
|
||||
#else /* HAVE_X86 */
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#elif defined HAVE_WINSOCK2_H
|
||||
#include <winsock2.h>
|
||||
#endif /* HAVE_NETINET_IN_H */
|
||||
#define be32_to_cpu(x) ntohl((x))
|
||||
#endif /* HAVE_X86 */
|
||||
|
||||
static inline uint64_t be64_to_cpu(uint64_t v)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
/* use the make64 functions to do 64-bit math */
|
||||
v = make64(htonl(low32(v)), htonl(high32(v)));
|
||||
#else /* NO_64BIT_MATH */
|
||||
/* use the native 64-bit math */
|
||||
v = (uint64_t)((be32_to_cpu((uint32_t)(v >> 32))) |
|
||||
(((uint64_t)be32_to_cpu((uint32_t)v)) << 32));
|
||||
#endif /* NO_64BIT_MATH */
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif /* WORDS_BIGENDIAN */
|
||||
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
/*
|
||||
* functions manipulating bitvector_t
|
||||
*
|
||||
* A bitvector_t consists of an array of words and an integer
|
||||
* representing the number of significant bits stored in the array.
|
||||
* The bits are packed as follows: the least significant bit is that
|
||||
* of word[0], while the most significant bit is the nth most
|
||||
* significant bit of word[m], where length = bits_per_word * m + n.
|
||||
*
|
||||
*/
|
||||
|
||||
#define bits_per_word 32
|
||||
#define bytes_per_word 4
|
||||
|
||||
typedef struct {
|
||||
uint32_t length;
|
||||
uint32_t *word;
|
||||
} bitvector_t;
|
||||
|
||||
#define bitvector_get_bit(v, bit_index) \
|
||||
(((((v)->word[((bit_index) >> 5)]) >> ((bit_index)&31)) & 1))
|
||||
|
||||
#define bitvector_set_bit(v, bit_index) \
|
||||
((((v)->word[((bit_index) >> 5)] |= ((uint32_t)1 << ((bit_index)&31)))))
|
||||
|
||||
#define bitvector_get_length(v) (((v)->length))
|
||||
|
||||
int bitvector_alloc(bitvector_t *v, unsigned long length);
|
||||
|
||||
void bitvector_dealloc(bitvector_t *v);
|
||||
|
||||
void bitvector_set_to_zero(bitvector_t *x);
|
||||
|
||||
void bitvector_left_shift(bitvector_t *x, int index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DATATYPES_H */
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* err.h
|
||||
*
|
||||
* error status codes
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ERR_H
|
||||
#define ERR_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "srtp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup Error Error Codes
|
||||
*
|
||||
* Error status codes are represented by the enumeration srtp_err_status_t.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
srtp_err_level_error,
|
||||
srtp_err_level_warning,
|
||||
srtp_err_level_info,
|
||||
srtp_err_level_debug
|
||||
} srtp_err_reporting_level_t;
|
||||
|
||||
/*
|
||||
* err_reporting_init prepares the error system. If
|
||||
* ERR_REPORTING_STDOUT is defined, it will log to stdout.
|
||||
*
|
||||
*/
|
||||
|
||||
srtp_err_status_t srtp_err_reporting_init(void);
|
||||
|
||||
typedef void(srtp_err_report_handler_func_t)(srtp_err_reporting_level_t level,
|
||||
const char *msg);
|
||||
|
||||
srtp_err_status_t srtp_install_err_report_handler(
|
||||
srtp_err_report_handler_func_t func);
|
||||
|
||||
/*
|
||||
* srtp_err_report reports a 'printf' formatted error
|
||||
* string, followed by a an arg list. The level argument
|
||||
* is one of srtp_err_reporting_level_t.
|
||||
*
|
||||
* Errors will be reported to stdout, if ERR_REPORTING_STDOUT
|
||||
* is defined.
|
||||
*
|
||||
*/
|
||||
|
||||
void srtp_err_report(srtp_err_reporting_level_t level, const char *format, ...);
|
||||
|
||||
/*
|
||||
* debug_module_t defines a debug module
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
int on; /* 1 if debugging is on, 0 if it is off */
|
||||
const char *name; /* printable name for debug module */
|
||||
} srtp_debug_module_t;
|
||||
|
||||
#ifdef ENABLE_DEBUG_LOGGING
|
||||
|
||||
#define debug_print0(mod, format) \
|
||||
srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name)
|
||||
#define debug_print(mod, format, arg) \
|
||||
srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg)
|
||||
#define debug_print2(mod, format, arg1, arg2) \
|
||||
srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, \
|
||||
arg1, arg2)
|
||||
|
||||
#else
|
||||
|
||||
#define debug_print0(mod, format) \
|
||||
if (mod.on) \
|
||||
srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name)
|
||||
#define debug_print(mod, format, arg) \
|
||||
if (mod.on) \
|
||||
srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg)
|
||||
#define debug_print2(mod, format, arg1, arg2) \
|
||||
if (mod.on) \
|
||||
srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, \
|
||||
arg1, arg2)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ERR_H */
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* hmac.h
|
||||
*
|
||||
* interface to hmac srtp_auth_type_t
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HMAC_H
|
||||
#define HMAC_H
|
||||
|
||||
#include "auth.h"
|
||||
#include "sha1.h"
|
||||
|
||||
typedef struct {
|
||||
uint8_t opad[64];
|
||||
srtp_sha1_ctx_t ctx;
|
||||
srtp_sha1_ctx_t init_ctx;
|
||||
} srtp_hmac_ctx_t;
|
||||
|
||||
#endif /* HMAC_H */
|
||||
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* integers.h
|
||||
*
|
||||
* defines integer types (or refers to their definitions)
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef INTEGERS_H
|
||||
#define INTEGERS_H
|
||||
|
||||
/* use standard integer definitions, if they're available */
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_INT_TYPES_H
|
||||
#include <sys/int_types.h> /* this exists on Sun OS */
|
||||
#endif
|
||||
#ifdef HAVE_MACHINE_TYPES_H
|
||||
#include <machine/types.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Can we do 64 bit integers? */
|
||||
#if !defined(HAVE_UINT64_T)
|
||||
#if SIZEOF_UNSIGNED_LONG == 8
|
||||
typedef unsigned long uint64_t;
|
||||
#elif SIZEOF_UNSIGNED_LONG_LONG == 8
|
||||
typedef unsigned long long uint64_t;
|
||||
#else
|
||||
#define NO_64BIT_MATH 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Reasonable defaults for 32 bit machines - you may need to
|
||||
* edit these definitions for your own machine. */
|
||||
#ifndef HAVE_UINT8_T
|
||||
typedef unsigned char uint8_t;
|
||||
#endif
|
||||
#ifndef HAVE_UINT16_T
|
||||
typedef unsigned short int uint16_t;
|
||||
#endif
|
||||
#ifndef HAVE_UINT32_T
|
||||
typedef unsigned int uint32_t;
|
||||
#endif
|
||||
#ifndef HAVE_INT32_T
|
||||
typedef int int32_t;
|
||||
#endif
|
||||
|
||||
#if defined(NO_64BIT_MATH) && defined(HAVE_CONFIG_H)
|
||||
typedef double uint64_t;
|
||||
/* assert that sizeof(double) == 8 */
|
||||
extern uint64_t make64(uint32_t high, uint32_t low);
|
||||
extern uint32_t high32(uint64_t value);
|
||||
extern uint32_t low32(uint64_t value);
|
||||
#endif
|
||||
|
||||
/* These macros are to load and store 32-bit values from un-aligned
|
||||
addresses. This is required for processors that do not allow unaligned
|
||||
loads. */
|
||||
#ifdef ALIGNMENT_32BIT_REQUIRED
|
||||
/* Note that if it's in a variable, you can memcpy it */
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define PUT_32(addr, value) \
|
||||
{ \
|
||||
((unsigned char *)(addr))[0] = (value >> 24); \
|
||||
((unsigned char *)(addr))[1] = (value >> 16) & 0xff; \
|
||||
((unsigned char *)(addr))[2] = (value >> 8) & 0xff; \
|
||||
((unsigned char *)(addr))[3] = (value)&0xff; \
|
||||
}
|
||||
#define GET_32(addr) \
|
||||
((((unsigned char *)(addr))[0] << 24) | \
|
||||
(((unsigned char *)(addr))[1] << 16) | \
|
||||
(((unsigned char *)(addr))[2] << 8) | (((unsigned char *)(addr))[3]))
|
||||
#else
|
||||
#define PUT_32(addr, value) \
|
||||
{ \
|
||||
((unsigned char *)(addr))[3] = (value >> 24); \
|
||||
((unsigned char *)(addr))[2] = (value >> 16) & 0xff; \
|
||||
((unsigned char *)(addr))[1] = (value >> 8) & 0xff; \
|
||||
((unsigned char *)(addr))[0] = (value)&0xff; \
|
||||
}
|
||||
#define GET_32(addr) \
|
||||
((((unsigned char *)(addr))[3] << 24) | \
|
||||
(((unsigned char *)(addr))[2] << 16) | \
|
||||
(((unsigned char *)(addr))[1] << 8) | (((unsigned char *)(addr))[0]))
|
||||
#endif // WORDS_BIGENDIAN
|
||||
#else
|
||||
#define PUT_32(addr, value) *(((uint32_t *) (addr)) = (value)
|
||||
#define GET_32(addr) (*(((uint32_t *) (addr)))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* INTEGERS_H */
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* key.h
|
||||
*
|
||||
* key usage limits enforcement
|
||||
*
|
||||
* David A. Mcgrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef KEY_H
|
||||
#define KEY_H
|
||||
|
||||
#include "rdbx.h" /* for srtp_xtd_seq_num_t */
|
||||
#include "err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct srtp_key_limit_ctx_t *srtp_key_limit_t;
|
||||
|
||||
typedef enum {
|
||||
srtp_key_event_normal,
|
||||
srtp_key_event_soft_limit,
|
||||
srtp_key_event_hard_limit
|
||||
} srtp_key_event_t;
|
||||
|
||||
srtp_err_status_t srtp_key_limit_set(srtp_key_limit_t key,
|
||||
const srtp_xtd_seq_num_t s);
|
||||
|
||||
srtp_err_status_t srtp_key_limit_clone(srtp_key_limit_t original,
|
||||
srtp_key_limit_t *new_key);
|
||||
|
||||
srtp_key_event_t srtp_key_limit_update(srtp_key_limit_t key);
|
||||
|
||||
typedef enum {
|
||||
srtp_key_state_normal,
|
||||
srtp_key_state_past_soft_limit,
|
||||
srtp_key_state_expired
|
||||
} srtp_key_state_t;
|
||||
|
||||
typedef struct srtp_key_limit_ctx_t {
|
||||
srtp_xtd_seq_num_t num_left;
|
||||
srtp_key_state_t state;
|
||||
} srtp_key_limit_ctx_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* KEY_H */
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* null-auth.h
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NULL_AUTH_H
|
||||
#define NULL_AUTH_H
|
||||
|
||||
#include "auth.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char foo;
|
||||
} srtp_null_auth_ctx_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NULL_AUTH_H */
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* null-cipher.h
|
||||
*
|
||||
* header file for the null cipher
|
||||
*
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NULL_CIPHER_H
|
||||
#define NULL_CIPHER_H
|
||||
|
||||
#include "datatypes.h"
|
||||
#include "cipher.h"
|
||||
|
||||
typedef struct {
|
||||
char foo; /* empty, for now */
|
||||
} srtp_null_cipher_ctx_t;
|
||||
|
||||
#endif /* NULL_CIPHER_H */
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* replay-database.h
|
||||
*
|
||||
* interface for a replay database for packet security
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef REPLAY_DB_H
|
||||
#define REPLAY_DB_H
|
||||
|
||||
#include "integers.h" /* for uint32_t */
|
||||
#include "datatypes.h" /* for v128_t */
|
||||
#include "err.h" /* for srtp_err_status_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* if the ith least significant bit is one, then the packet index
|
||||
* window_end-i is in the database
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
uint32_t window_start; /* packet index of the first bit in bitmask */
|
||||
v128_t bitmask;
|
||||
} srtp_rdb_t;
|
||||
|
||||
/*
|
||||
* srtp_rdb_init
|
||||
*
|
||||
* initalizes rdb
|
||||
*
|
||||
* returns srtp_err_status_ok on success, srtp_err_status_t_fail otherwise
|
||||
*/
|
||||
srtp_err_status_t srtp_rdb_init(srtp_rdb_t *rdb);
|
||||
|
||||
/*
|
||||
* srtp_rdb_check
|
||||
*
|
||||
* checks to see if index appears in rdb
|
||||
*
|
||||
* returns srtp_err_status_fail if the index already appears in rdb,
|
||||
* returns srtp_err_status_ok otherwise
|
||||
*/
|
||||
srtp_err_status_t srtp_rdb_check(const srtp_rdb_t *rdb, uint32_t rdb_index);
|
||||
|
||||
/*
|
||||
* srtp_rdb_add_index
|
||||
*
|
||||
* adds index to srtp_rdb_t (and does *not* check if index appears in db)
|
||||
*
|
||||
* returns srtp_err_status_ok on success, srtp_err_status_fail otherwise
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_rdb_add_index(srtp_rdb_t *rdb, uint32_t rdb_index);
|
||||
|
||||
/*
|
||||
* the functions srtp_rdb_increment() and srtp_rdb_get_value() are for use by
|
||||
* senders, not receivers - DO NOT use these functions on the same
|
||||
* srtp_rdb_t upon which srtp_rdb_add_index is used!
|
||||
*/
|
||||
|
||||
/*
|
||||
* srtp_rdb_increment(db) increments the sequence number in db, if it is
|
||||
* not too high
|
||||
*
|
||||
* return values:
|
||||
*
|
||||
* srtp_err_status_ok no problem
|
||||
* srtp_err_status_key_expired sequence number too high
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_rdb_increment(srtp_rdb_t *rdb);
|
||||
|
||||
/*
|
||||
* srtp_rdb_get_value(db) returns the current sequence number of db
|
||||
*/
|
||||
uint32_t srtp_rdb_get_value(const srtp_rdb_t *rdb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* REPLAY_DB_H */
|
||||
@@ -1,209 +0,0 @@
|
||||
/*
|
||||
* rdbx.h
|
||||
*
|
||||
* replay database with extended packet indices, using a rollover counter
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RDBX_H
|
||||
#define RDBX_H
|
||||
|
||||
#include "datatypes.h"
|
||||
#include "err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* #define ROC_TEST */
|
||||
|
||||
#ifndef ROC_TEST
|
||||
|
||||
typedef uint16_t srtp_sequence_number_t; /* 16 bit sequence number */
|
||||
typedef uint32_t srtp_rollover_counter_t; /* 32 bit rollover counter */
|
||||
|
||||
#else /* use small seq_num and roc datatypes for testing purposes */
|
||||
|
||||
typedef unsigned char srtp_sequence_number_t; /* 8 bit sequence number */
|
||||
typedef uint16_t srtp_rollover_counter_t; /* 16 bit rollover counter */
|
||||
|
||||
#endif
|
||||
|
||||
#define seq_num_median (1 << (8 * sizeof(srtp_sequence_number_t) - 1))
|
||||
#define seq_num_max (1 << (8 * sizeof(srtp_sequence_number_t)))
|
||||
|
||||
/*
|
||||
* An rtp_xtd_seq_num_t is a 64-bit unsigned integer used as an 'extended'
|
||||
* sequence number.
|
||||
*/
|
||||
typedef uint64_t srtp_xtd_seq_num_t;
|
||||
|
||||
/*
|
||||
* An srtp_rdbx_t is a replay database with extended range; it uses an
|
||||
* xtd_seq_num_t and a bitmask of recently received indices.
|
||||
*/
|
||||
typedef struct {
|
||||
srtp_xtd_seq_num_t index;
|
||||
bitvector_t bitmask;
|
||||
} srtp_rdbx_t;
|
||||
|
||||
/*
|
||||
* srtp_rdbx_init(rdbx_ptr, ws)
|
||||
*
|
||||
* initializes the rdbx pointed to by its argument with the window size ws,
|
||||
* setting the rollover counter and sequence number to zero
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_init(srtp_rdbx_t *rdbx, unsigned long ws);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_dealloc(rdbx_ptr)
|
||||
*
|
||||
* frees memory associated with the rdbx
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_dealloc(srtp_rdbx_t *rdbx);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_estimate_index(rdbx, guess, s)
|
||||
*
|
||||
* given an rdbx and a sequence number s (from a newly arrived packet),
|
||||
* sets the contents of *guess to contain the best guess of the packet
|
||||
* index to which s corresponds, and returns the difference between
|
||||
* *guess and the locally stored synch info
|
||||
*/
|
||||
int32_t srtp_rdbx_estimate_index(const srtp_rdbx_t *rdbx,
|
||||
srtp_xtd_seq_num_t *guess,
|
||||
srtp_sequence_number_t s);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_check(rdbx, delta);
|
||||
*
|
||||
* srtp_rdbx_check(&r, delta) checks to see if the xtd_seq_num_t
|
||||
* which is at rdbx->window_start + delta is in the rdb
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_check(const srtp_rdbx_t *rdbx, int difference);
|
||||
|
||||
/*
|
||||
* srtp_replay_add_index(rdbx, delta)
|
||||
*
|
||||
* adds the srtp_xtd_seq_num_t at rdbx->window_start + delta to replay_db
|
||||
* (and does *not* check if that xtd_seq_num_t appears in db)
|
||||
*
|
||||
* this function should be called *only* after replay_check has
|
||||
* indicated that the index does not appear in the rdbx, and a mutex
|
||||
* should protect the rdbx between these calls if necessary.
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_add_index(srtp_rdbx_t *rdbx, int delta);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_set_roc(rdbx, roc) initalizes the srtp_rdbx_t at the location rdbx
|
||||
* to have the rollover counter value roc. If that value is less than
|
||||
* the current rollover counter value, then the function returns
|
||||
* srtp_err_status_replay_old; otherwise, srtp_err_status_ok is returned.
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_set_roc(srtp_rdbx_t *rdbx, uint32_t roc);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_get_packet_index(rdbx) returns the value of the rollover counter
|
||||
* for
|
||||
* the srtp_rdbx_t pointed to by rdbx
|
||||
*
|
||||
*/
|
||||
srtp_xtd_seq_num_t srtp_rdbx_get_packet_index(const srtp_rdbx_t *rdbx);
|
||||
|
||||
/*
|
||||
* srtp_xtd_seq_num_t functions - these are *internal* functions of rdbx, and
|
||||
* shouldn't be used to manipulate rdbx internal values. use the rdbx
|
||||
* api instead!
|
||||
*/
|
||||
|
||||
/*
|
||||
* srtp_rdbx_get_ws(rdbx_ptr)
|
||||
*
|
||||
* gets the window size which was used to initialize the rdbx
|
||||
*/
|
||||
unsigned long srtp_rdbx_get_window_size(const srtp_rdbx_t *rdbx);
|
||||
|
||||
/* index_init(&pi) initializes a packet index pi (sets it to zero) */
|
||||
void srtp_index_init(srtp_xtd_seq_num_t *pi);
|
||||
|
||||
/* index_advance(&pi, s) advances a xtd_seq_num_t forward by s */
|
||||
void srtp_index_advance(srtp_xtd_seq_num_t *pi, srtp_sequence_number_t s);
|
||||
|
||||
/*
|
||||
* srtp_index_guess(local, guess, s)
|
||||
*
|
||||
* given a srtp_xtd_seq_num_t local (which represents the highest
|
||||
* known-to-be-good index) and a sequence number s (from a newly
|
||||
* arrived packet), sets the contents of *guess to contain the best
|
||||
* guess of the packet index to which s corresponds, and returns the
|
||||
* difference between *guess and *local
|
||||
*/
|
||||
int32_t srtp_index_guess(const srtp_xtd_seq_num_t *local,
|
||||
srtp_xtd_seq_num_t *guess,
|
||||
srtp_sequence_number_t s);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_get_roc(rdbx)
|
||||
*
|
||||
* Get the current rollover counter
|
||||
*
|
||||
*/
|
||||
uint32_t srtp_rdbx_get_roc(const srtp_rdbx_t *rdbx);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_set_roc_seq(rdbx, roc, seq) initalizes the srtp_rdbx_t at the
|
||||
* location rdbx to have the rollover counter value roc and packet sequence
|
||||
* number seq. If the new rollover counter value is less than the current
|
||||
* rollover counter value, then the function returns
|
||||
* srtp_err_status_replay_old, otherwise, srtp_err_status_ok is returned.
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_set_roc_seq(srtp_rdbx_t *rdbx,
|
||||
uint32_t roc,
|
||||
uint16_t seq);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RDBX_H */
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* sha1.h
|
||||
*
|
||||
* interface to the Secure Hash Algorithm v.1 (SHA-1), specified in
|
||||
* FIPS 180-1
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SHA1_H
|
||||
#define SHA1_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "err.h"
|
||||
#include "datatypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint32_t H[5]; /* state vector */
|
||||
uint32_t M[16]; /* message buffer */
|
||||
int octets_in_buffer; /* octets of message in buffer */
|
||||
uint32_t num_bits_in_msg; /* total number of bits in message */
|
||||
} srtp_sha1_ctx_t;
|
||||
|
||||
/*
|
||||
* srtp_sha1_init(&ctx) initializes the SHA1 context ctx
|
||||
*
|
||||
* srtp_sha1_update(&ctx, msg, len) hashes the len octets starting at msg
|
||||
* into the SHA1 context
|
||||
*
|
||||
* srtp_sha1_final(&ctx, output) performs the final processing of the SHA1
|
||||
* context and writes the result to the 20 octets at output
|
||||
*
|
||||
*/
|
||||
void srtp_sha1_init(srtp_sha1_ctx_t *ctx);
|
||||
|
||||
void srtp_sha1_update(srtp_sha1_ctx_t *ctx,
|
||||
const uint8_t *M,
|
||||
int octets_in_msg);
|
||||
|
||||
void srtp_sha1_final(srtp_sha1_ctx_t *ctx, uint32_t output[5]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SHA1_H */
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* alloc.c
|
||||
*
|
||||
* memory allocation and deallocation
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "alloc.h"
|
||||
#include "crypto_kernel.h"
|
||||
|
||||
/* the debug module for memory allocation */
|
||||
|
||||
srtp_debug_module_t srtp_mod_alloc = {
|
||||
0, /* debugging is off by default */
|
||||
"alloc" /* printable name for module */
|
||||
};
|
||||
|
||||
/*
|
||||
* Nota bene: the debugging statements for srtp_crypto_alloc() and
|
||||
* srtp_crypto_free() have identical prefixes, which include the addresses
|
||||
* of the memory locations on which they are operating. This fact can
|
||||
* be used to locate memory leaks, by turning on memory debugging,
|
||||
* grepping for 'alloc', then matching alloc and free calls by
|
||||
* address.
|
||||
*/
|
||||
|
||||
#if defined(HAVE_STDLIB_H)
|
||||
|
||||
void *srtp_crypto_alloc(size_t size)
|
||||
{
|
||||
void *ptr;
|
||||
|
||||
if (!size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr = calloc(1, size);
|
||||
|
||||
if (ptr) {
|
||||
debug_print(srtp_mod_alloc, "(location: %p) allocated", ptr);
|
||||
} else {
|
||||
debug_print(srtp_mod_alloc, "allocation failed (asked for %zu bytes)\n",
|
||||
size);
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void srtp_crypto_free(void *ptr)
|
||||
{
|
||||
debug_print(srtp_mod_alloc, "(location: %p) freed", ptr);
|
||||
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
#else /* we need to define our own memory allocation routines */
|
||||
|
||||
#error no memory allocation defined yet
|
||||
|
||||
#endif
|
||||
@@ -1,559 +0,0 @@
|
||||
/*
|
||||
* crypto_kernel.c
|
||||
*
|
||||
* header for the cryptographic kernel
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "alloc.h"
|
||||
|
||||
#include "crypto_kernel.h"
|
||||
#include "cipher_types.h"
|
||||
|
||||
/* the debug module for the crypto_kernel */
|
||||
|
||||
srtp_debug_module_t srtp_mod_crypto_kernel = {
|
||||
0, /* debugging is off by default */
|
||||
"crypto kernel" /* printable name for module */
|
||||
};
|
||||
|
||||
/* crypto_kernel is a global variable, the only one of its datatype */
|
||||
|
||||
srtp_crypto_kernel_t crypto_kernel = {
|
||||
srtp_crypto_kernel_state_insecure, /* start off in insecure state */
|
||||
NULL, /* no cipher types yet */
|
||||
NULL, /* no auth types yet */
|
||||
NULL /* no debug modules yet */
|
||||
};
|
||||
|
||||
#define MAX_RNG_TRIALS 25
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_init()
|
||||
{
|
||||
srtp_err_status_t status;
|
||||
|
||||
/* check the security state */
|
||||
if (crypto_kernel.state == srtp_crypto_kernel_state_secure) {
|
||||
/*
|
||||
* we're already in the secure state, but we've been asked to
|
||||
* re-initialize, so we just re-run the self-tests and then return
|
||||
*/
|
||||
return srtp_crypto_kernel_status();
|
||||
}
|
||||
|
||||
/* initialize error reporting system */
|
||||
status = srtp_err_reporting_init();
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* load debug modules */
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_crypto_kernel);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_auth);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_cipher);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_alloc);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* load cipher types */
|
||||
status = srtp_crypto_kernel_load_cipher_type(&srtp_null_cipher,
|
||||
SRTP_NULL_CIPHER);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_cipher_type(&srtp_aes_icm_128,
|
||||
SRTP_AES_ICM_128);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_cipher_type(&srtp_aes_icm_256,
|
||||
SRTP_AES_ICM_256);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_aes_icm);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
#ifdef GCM
|
||||
status = srtp_crypto_kernel_load_cipher_type(&srtp_aes_icm_192,
|
||||
SRTP_AES_ICM_192);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_cipher_type(&srtp_aes_gcm_128,
|
||||
SRTP_AES_GCM_128);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_cipher_type(&srtp_aes_gcm_256,
|
||||
SRTP_AES_GCM_256);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_aes_gcm);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* load auth func types */
|
||||
status = srtp_crypto_kernel_load_auth_type(&srtp_null_auth, SRTP_NULL_AUTH);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_auth_type(&srtp_hmac, SRTP_HMAC_SHA1);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_hmac);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* change state to secure */
|
||||
crypto_kernel.state = srtp_crypto_kernel_state_secure;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_status()
|
||||
{
|
||||
srtp_err_status_t status;
|
||||
srtp_kernel_cipher_type_t *ctype = crypto_kernel.cipher_type_list;
|
||||
srtp_kernel_auth_type_t *atype = crypto_kernel.auth_type_list;
|
||||
|
||||
/* for each cipher type, describe and test */
|
||||
while (ctype != NULL) {
|
||||
srtp_err_report(srtp_err_level_info, "cipher: %s\n",
|
||||
ctype->cipher_type->description);
|
||||
srtp_err_report(srtp_err_level_info, " self-test: ");
|
||||
status = srtp_cipher_type_self_test(ctype->cipher_type);
|
||||
if (status) {
|
||||
srtp_err_report(srtp_err_level_error, "failed with error code %d\n",
|
||||
status);
|
||||
exit(status);
|
||||
}
|
||||
srtp_err_report(srtp_err_level_info, "passed\n");
|
||||
ctype = ctype->next;
|
||||
}
|
||||
|
||||
/* for each auth type, describe and test */
|
||||
while (atype != NULL) {
|
||||
srtp_err_report(srtp_err_level_info, "auth func: %s\n",
|
||||
atype->auth_type->description);
|
||||
srtp_err_report(srtp_err_level_info, " self-test: ");
|
||||
status = srtp_auth_type_self_test(atype->auth_type);
|
||||
if (status) {
|
||||
srtp_err_report(srtp_err_level_error, "failed with error code %d\n",
|
||||
status);
|
||||
exit(status);
|
||||
}
|
||||
srtp_err_report(srtp_err_level_info, "passed\n");
|
||||
atype = atype->next;
|
||||
}
|
||||
|
||||
srtp_crypto_kernel_list_debug_modules();
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_list_debug_modules()
|
||||
{
|
||||
srtp_kernel_debug_module_t *dm = crypto_kernel.debug_module_list;
|
||||
|
||||
/* describe each debug module */
|
||||
srtp_err_report(srtp_err_level_info, "debug modules loaded:\n");
|
||||
while (dm != NULL) {
|
||||
srtp_err_report(srtp_err_level_info, " %s ", dm->mod->name);
|
||||
if (dm->mod->on) {
|
||||
srtp_err_report(srtp_err_level_info, "(on)\n");
|
||||
} else {
|
||||
srtp_err_report(srtp_err_level_info, "(off)\n");
|
||||
}
|
||||
dm = dm->next;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_shutdown()
|
||||
{
|
||||
/*
|
||||
* free dynamic memory used in crypto_kernel at present
|
||||
*/
|
||||
|
||||
/* walk down cipher type list, freeing memory */
|
||||
while (crypto_kernel.cipher_type_list != NULL) {
|
||||
srtp_kernel_cipher_type_t *ctype = crypto_kernel.cipher_type_list;
|
||||
crypto_kernel.cipher_type_list = ctype->next;
|
||||
debug_print(srtp_mod_crypto_kernel, "freeing memory for cipher %s",
|
||||
ctype->cipher_type->description);
|
||||
srtp_crypto_free(ctype);
|
||||
}
|
||||
|
||||
/* walk down authetication module list, freeing memory */
|
||||
while (crypto_kernel.auth_type_list != NULL) {
|
||||
srtp_kernel_auth_type_t *atype = crypto_kernel.auth_type_list;
|
||||
crypto_kernel.auth_type_list = atype->next;
|
||||
debug_print(srtp_mod_crypto_kernel,
|
||||
"freeing memory for authentication %s",
|
||||
atype->auth_type->description);
|
||||
srtp_crypto_free(atype);
|
||||
}
|
||||
|
||||
/* walk down debug module list, freeing memory */
|
||||
while (crypto_kernel.debug_module_list != NULL) {
|
||||
srtp_kernel_debug_module_t *kdm = crypto_kernel.debug_module_list;
|
||||
crypto_kernel.debug_module_list = kdm->next;
|
||||
debug_print(srtp_mod_crypto_kernel,
|
||||
"freeing memory for debug module %s", kdm->mod->name);
|
||||
srtp_crypto_free(kdm);
|
||||
}
|
||||
|
||||
/* return to insecure state */
|
||||
crypto_kernel.state = srtp_crypto_kernel_state_insecure;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static inline srtp_err_status_t srtp_crypto_kernel_do_load_cipher_type(
|
||||
const srtp_cipher_type_t *new_ct,
|
||||
srtp_cipher_type_id_t id,
|
||||
int replace)
|
||||
{
|
||||
srtp_kernel_cipher_type_t *ctype;
|
||||
srtp_kernel_cipher_type_t *new_ctype = NULL;
|
||||
srtp_err_status_t status;
|
||||
|
||||
/* defensive coding */
|
||||
if (new_ct == NULL) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
if (new_ct->id != id) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* check cipher type by running self-test */
|
||||
status = srtp_cipher_type_self_test(new_ct);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* walk down list, checking if this type is in the list already */
|
||||
ctype = crypto_kernel.cipher_type_list;
|
||||
while (ctype != NULL) {
|
||||
if (id == ctype->id) {
|
||||
if (!replace) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
status =
|
||||
srtp_cipher_type_test(new_ct, ctype->cipher_type->test_data);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
new_ctype = ctype;
|
||||
break;
|
||||
} else if (new_ct == ctype->cipher_type) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
ctype = ctype->next;
|
||||
}
|
||||
|
||||
/* if not found, put new_ct at the head of the list */
|
||||
if (ctype == NULL) {
|
||||
/* allocate memory */
|
||||
new_ctype = (srtp_kernel_cipher_type_t *)srtp_crypto_alloc(
|
||||
sizeof(srtp_kernel_cipher_type_t));
|
||||
if (new_ctype == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
new_ctype->next = crypto_kernel.cipher_type_list;
|
||||
|
||||
/* set head of list to new cipher type */
|
||||
crypto_kernel.cipher_type_list = new_ctype;
|
||||
}
|
||||
|
||||
/* set fields */
|
||||
new_ctype->cipher_type = new_ct;
|
||||
new_ctype->id = id;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_load_cipher_type(
|
||||
const srtp_cipher_type_t *new_ct,
|
||||
srtp_cipher_type_id_t id)
|
||||
{
|
||||
return srtp_crypto_kernel_do_load_cipher_type(new_ct, id, 0);
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_replace_cipher_type(const srtp_cipher_type_t *new_ct,
|
||||
srtp_cipher_type_id_t id)
|
||||
{
|
||||
return srtp_crypto_kernel_do_load_cipher_type(new_ct, id, 1);
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_do_load_auth_type(
|
||||
const srtp_auth_type_t *new_at,
|
||||
srtp_auth_type_id_t id,
|
||||
int replace)
|
||||
{
|
||||
srtp_kernel_auth_type_t *atype;
|
||||
srtp_kernel_auth_type_t *new_atype = NULL;
|
||||
srtp_err_status_t status;
|
||||
|
||||
/* defensive coding */
|
||||
if (new_at == NULL) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
if (new_at->id != id) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* check auth type by running self-test */
|
||||
status = srtp_auth_type_self_test(new_at);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* walk down list, checking if this type is in the list already */
|
||||
atype = crypto_kernel.auth_type_list;
|
||||
while (atype != NULL) {
|
||||
if (id == atype->id) {
|
||||
if (!replace) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
status = srtp_auth_type_test(new_at, atype->auth_type->test_data);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
new_atype = atype;
|
||||
break;
|
||||
} else if (new_at == atype->auth_type) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
atype = atype->next;
|
||||
}
|
||||
|
||||
/* if not found, put new_at at the head of the list */
|
||||
if (atype == NULL) {
|
||||
/* allocate memory */
|
||||
new_atype = (srtp_kernel_auth_type_t *)srtp_crypto_alloc(
|
||||
sizeof(srtp_kernel_auth_type_t));
|
||||
if (new_atype == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
new_atype->next = crypto_kernel.auth_type_list;
|
||||
/* set head of list to new auth type */
|
||||
crypto_kernel.auth_type_list = new_atype;
|
||||
}
|
||||
|
||||
/* set fields */
|
||||
new_atype->auth_type = new_at;
|
||||
new_atype->id = id;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_load_auth_type(
|
||||
const srtp_auth_type_t *new_at,
|
||||
srtp_auth_type_id_t id)
|
||||
{
|
||||
return srtp_crypto_kernel_do_load_auth_type(new_at, id, 0);
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_replace_auth_type(const srtp_auth_type_t *new_at,
|
||||
srtp_auth_type_id_t id)
|
||||
{
|
||||
return srtp_crypto_kernel_do_load_auth_type(new_at, id, 1);
|
||||
}
|
||||
|
||||
const srtp_cipher_type_t *srtp_crypto_kernel_get_cipher_type(
|
||||
srtp_cipher_type_id_t id)
|
||||
{
|
||||
srtp_kernel_cipher_type_t *ctype;
|
||||
|
||||
/* walk down list, looking for id */
|
||||
ctype = crypto_kernel.cipher_type_list;
|
||||
while (ctype != NULL) {
|
||||
if (id == ctype->id) {
|
||||
return ctype->cipher_type;
|
||||
}
|
||||
ctype = ctype->next;
|
||||
}
|
||||
|
||||
/* haven't found the right one, indicate failure by returning NULL */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_alloc_cipher(srtp_cipher_type_id_t id,
|
||||
srtp_cipher_pointer_t *cp,
|
||||
int key_len,
|
||||
int tag_len)
|
||||
{
|
||||
const srtp_cipher_type_t *ct;
|
||||
|
||||
/*
|
||||
* if the crypto_kernel is not yet initialized, we refuse to allocate
|
||||
* any ciphers - this is a bit extra-paranoid
|
||||
*/
|
||||
if (crypto_kernel.state != srtp_crypto_kernel_state_secure) {
|
||||
return srtp_err_status_init_fail;
|
||||
}
|
||||
|
||||
ct = srtp_crypto_kernel_get_cipher_type(id);
|
||||
if (!ct) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
return ((ct)->alloc(cp, key_len, tag_len));
|
||||
}
|
||||
|
||||
const srtp_auth_type_t *srtp_crypto_kernel_get_auth_type(srtp_auth_type_id_t id)
|
||||
{
|
||||
srtp_kernel_auth_type_t *atype;
|
||||
|
||||
/* walk down list, looking for id */
|
||||
atype = crypto_kernel.auth_type_list;
|
||||
while (atype != NULL) {
|
||||
if (id == atype->id) {
|
||||
return atype->auth_type;
|
||||
}
|
||||
atype = atype->next;
|
||||
}
|
||||
|
||||
/* haven't found the right one, indicate failure by returning NULL */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_alloc_auth(srtp_auth_type_id_t id,
|
||||
srtp_auth_pointer_t *ap,
|
||||
int key_len,
|
||||
int tag_len)
|
||||
{
|
||||
const srtp_auth_type_t *at;
|
||||
|
||||
/*
|
||||
* if the crypto_kernel is not yet initialized, we refuse to allocate
|
||||
* any auth functions - this is a bit extra-paranoid
|
||||
*/
|
||||
if (crypto_kernel.state != srtp_crypto_kernel_state_secure) {
|
||||
return srtp_err_status_init_fail;
|
||||
}
|
||||
|
||||
at = srtp_crypto_kernel_get_auth_type(id);
|
||||
if (!at) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
return ((at)->alloc(ap, key_len, tag_len));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_load_debug_module(
|
||||
srtp_debug_module_t *new_dm)
|
||||
{
|
||||
srtp_kernel_debug_module_t *kdm, *new;
|
||||
|
||||
/* defensive coding */
|
||||
if (new_dm == NULL || new_dm->name == NULL) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* walk down list, checking if this type is in the list already */
|
||||
kdm = crypto_kernel.debug_module_list;
|
||||
while (kdm != NULL) {
|
||||
if (strncmp(new_dm->name, kdm->mod->name, 64) == 0) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
kdm = kdm->next;
|
||||
}
|
||||
|
||||
/* put new_dm at the head of the list */
|
||||
/* allocate memory */
|
||||
new = (srtp_kernel_debug_module_t *)srtp_crypto_alloc(
|
||||
sizeof(srtp_kernel_debug_module_t));
|
||||
if (new == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* set fields */
|
||||
new->mod = new_dm;
|
||||
new->next = crypto_kernel.debug_module_list;
|
||||
|
||||
/* set head of list to new cipher type */
|
||||
crypto_kernel.debug_module_list = new;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_set_debug_module(const char *name, int on)
|
||||
{
|
||||
srtp_kernel_debug_module_t *kdm;
|
||||
|
||||
/* walk down list, checking if this type is in the list already */
|
||||
kdm = crypto_kernel.debug_module_list;
|
||||
while (kdm != NULL) {
|
||||
if (strncmp(name, kdm->mod->name, 64) == 0) {
|
||||
kdm->mod->on = on;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
kdm = kdm->next;
|
||||
}
|
||||
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* err.c
|
||||
*
|
||||
* error status reporting functions
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "err.h"
|
||||
#include "datatypes.h"
|
||||
#include <string.h>
|
||||
|
||||
/* srtp_err_file is the FILE to which errors are reported */
|
||||
|
||||
static FILE *srtp_err_file = NULL;
|
||||
|
||||
srtp_err_status_t srtp_err_reporting_init()
|
||||
{
|
||||
#ifdef ERR_REPORTING_STDOUT
|
||||
srtp_err_file = stdout;
|
||||
#elif defined(ERR_REPORTING_FILE)
|
||||
/* open file for error reporting */
|
||||
srtp_err_file = fopen(ERR_REPORTING_FILE, "w");
|
||||
if (srtp_err_file == NULL) {
|
||||
return srtp_err_status_init_fail;
|
||||
}
|
||||
#endif
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_report_handler_func_t *srtp_err_report_handler = NULL;
|
||||
|
||||
srtp_err_status_t srtp_install_err_report_handler(
|
||||
srtp_err_report_handler_func_t func)
|
||||
{
|
||||
srtp_err_report_handler = func;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
void srtp_err_report(srtp_err_reporting_level_t level, const char *format, ...)
|
||||
{
|
||||
char msg[512];
|
||||
va_list args;
|
||||
if (srtp_err_file != NULL) {
|
||||
va_start(args, format);
|
||||
vfprintf(srtp_err_file, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
if (srtp_err_report_handler != NULL) {
|
||||
va_start(args, format);
|
||||
if (vsnprintf(msg, sizeof(msg), format, args) > 0) {
|
||||
/* strip trailing \n, callback should not have one */
|
||||
size_t l = strlen(msg);
|
||||
if (l && msg[l - 1] == '\n') {
|
||||
msg[l - 1] = '\0';
|
||||
}
|
||||
srtp_err_report_handler(level, msg);
|
||||
/*
|
||||
* NOTE, need to be carefull, there is a potential that
|
||||
* octet_string_set_to_zero() could
|
||||
* call srtp_err_report() in the future, leading to recursion
|
||||
*/
|
||||
octet_string_set_to_zero(msg, sizeof(msg));
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* key.c
|
||||
*
|
||||
* key usage limits enforcement
|
||||
*
|
||||
* David A. Mcgrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "key.h"
|
||||
|
||||
#define soft_limit 0x10000
|
||||
|
||||
srtp_err_status_t srtp_key_limit_set(srtp_key_limit_t key,
|
||||
const srtp_xtd_seq_num_t s)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
if (high32(s) == 0 && low32(s) < soft_limit) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
#else
|
||||
if (s < soft_limit) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
#endif
|
||||
key->num_left = s;
|
||||
key->state = srtp_key_state_normal;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_key_limit_clone(srtp_key_limit_t original,
|
||||
srtp_key_limit_t *new_key)
|
||||
{
|
||||
if (original == NULL) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
*new_key = original;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_key_event_t srtp_key_limit_update(srtp_key_limit_t key)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
if (low32(key->num_left) == 0) {
|
||||
// carry
|
||||
key->num_left =
|
||||
make64(high32(key->num_left) - 1, low32(key->num_left) - 1);
|
||||
} else {
|
||||
// no carry
|
||||
key->num_left = make64(high32(key->num_left), low32(key->num_left) - 1);
|
||||
}
|
||||
if (high32(key->num_left) != 0 || low32(key->num_left) >= soft_limit) {
|
||||
return srtp_key_event_normal; /* we're above the soft limit */
|
||||
}
|
||||
#else
|
||||
key->num_left--;
|
||||
if (key->num_left >= soft_limit) {
|
||||
return srtp_key_event_normal; /* we're above the soft limit */
|
||||
}
|
||||
#endif
|
||||
if (key->state == srtp_key_state_normal) {
|
||||
/* we just passed the soft limit, so change the state */
|
||||
key->state = srtp_key_state_past_soft_limit;
|
||||
}
|
||||
#ifdef NO_64BIT_MATH
|
||||
if (low32(key->num_left) == 0 && high32(key->num_left == 0))
|
||||
#else
|
||||
if (key->num_left < 1)
|
||||
#endif
|
||||
{ /* we just hit the hard limit */
|
||||
key->state = srtp_key_state_expired;
|
||||
return srtp_key_event_hard_limit;
|
||||
}
|
||||
return srtp_key_event_soft_limit;
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
/*
|
||||
* datatypes.c
|
||||
*
|
||||
* data types for finite fields and functions for input, output, and
|
||||
* manipulation
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef OPENSSL
|
||||
#include <openssl/crypto.h>
|
||||
#endif
|
||||
|
||||
#include "datatypes.h"
|
||||
|
||||
/*
|
||||
* bit_string is a buffer that is used to hold output strings, e.g.
|
||||
* for printing.
|
||||
*/
|
||||
|
||||
/* the value MAX_PRINT_STRING_LEN is defined in datatypes.h */
|
||||
/* include space for null terminator */
|
||||
static char bit_string[MAX_PRINT_STRING_LEN + 1];
|
||||
|
||||
uint8_t srtp_nibble_to_hex_char(uint8_t nibble)
|
||||
{
|
||||
char buf[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
return buf[nibble & 0xF];
|
||||
}
|
||||
|
||||
char *srtp_octet_string_hex_string(const void *s, int length)
|
||||
{
|
||||
const uint8_t *str = (const uint8_t *)s;
|
||||
int i;
|
||||
|
||||
/* double length, since one octet takes two hex characters */
|
||||
length *= 2;
|
||||
|
||||
/* truncate string if it would be too long */
|
||||
if (length > MAX_PRINT_STRING_LEN)
|
||||
length = MAX_PRINT_STRING_LEN - 2;
|
||||
|
||||
for (i = 0; i < length; i += 2) {
|
||||
bit_string[i] = srtp_nibble_to_hex_char(*str >> 4);
|
||||
bit_string[i + 1] = srtp_nibble_to_hex_char(*str++ & 0xF);
|
||||
}
|
||||
bit_string[i] = 0; /* null terminate string */
|
||||
return bit_string;
|
||||
}
|
||||
|
||||
char *v128_hex_string(v128_t *x)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = j = 0; i < 16; i++) {
|
||||
bit_string[j++] = srtp_nibble_to_hex_char(x->v8[i] >> 4);
|
||||
bit_string[j++] = srtp_nibble_to_hex_char(x->v8[i] & 0xF);
|
||||
}
|
||||
|
||||
bit_string[j] = 0; /* null terminate string */
|
||||
return bit_string;
|
||||
}
|
||||
|
||||
char *v128_bit_string(v128_t *x)
|
||||
{
|
||||
int j, i;
|
||||
uint32_t mask;
|
||||
|
||||
for (j = i = 0; j < 4; j++) {
|
||||
for (mask = 0x80000000; mask > 0; mask >>= 1) {
|
||||
if (x->v32[j] & mask)
|
||||
bit_string[i] = '1';
|
||||
else
|
||||
bit_string[i] = '0';
|
||||
++i;
|
||||
}
|
||||
}
|
||||
bit_string[128] = 0; /* null terminate string */
|
||||
|
||||
return bit_string;
|
||||
}
|
||||
|
||||
void v128_copy_octet_string(v128_t *x, const uint8_t s[16])
|
||||
{
|
||||
#ifdef ALIGNMENT_32BIT_REQUIRED
|
||||
if ((((uint32_t)&s[0]) & 0x3) != 0)
|
||||
#endif
|
||||
{
|
||||
x->v8[0] = s[0];
|
||||
x->v8[1] = s[1];
|
||||
x->v8[2] = s[2];
|
||||
x->v8[3] = s[3];
|
||||
x->v8[4] = s[4];
|
||||
x->v8[5] = s[5];
|
||||
x->v8[6] = s[6];
|
||||
x->v8[7] = s[7];
|
||||
x->v8[8] = s[8];
|
||||
x->v8[9] = s[9];
|
||||
x->v8[10] = s[10];
|
||||
x->v8[11] = s[11];
|
||||
x->v8[12] = s[12];
|
||||
x->v8[13] = s[13];
|
||||
x->v8[14] = s[14];
|
||||
x->v8[15] = s[15];
|
||||
}
|
||||
#ifdef ALIGNMENT_32BIT_REQUIRED
|
||||
else {
|
||||
v128_t *v = (v128_t *)&s[0];
|
||||
|
||||
v128_copy(x, v);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void v128_left_shift(v128_t *x, int shift)
|
||||
{
|
||||
int i;
|
||||
const int base_index = shift >> 5;
|
||||
const int bit_index = shift & 31;
|
||||
|
||||
if (shift > 127) {
|
||||
v128_set_to_zero(x);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bit_index == 0) {
|
||||
for (i = 0; i < 4 - base_index; i++)
|
||||
x->v32[i] = x->v32[i + base_index];
|
||||
} else {
|
||||
for (i = 0; i < 4 - base_index - 1; i++)
|
||||
x->v32[i] = (x->v32[i + base_index] >> bit_index) ^
|
||||
(x->v32[i + base_index + 1] << (32 - bit_index));
|
||||
x->v32[4 - base_index - 1] = x->v32[4 - 1] >> bit_index;
|
||||
}
|
||||
|
||||
/* now wrap up the final portion */
|
||||
for (i = 4 - base_index; i < 4; i++)
|
||||
x->v32[i] = 0;
|
||||
}
|
||||
|
||||
/* functions manipulating bitvector_t */
|
||||
|
||||
int bitvector_alloc(bitvector_t *v, unsigned long length)
|
||||
{
|
||||
unsigned long l;
|
||||
|
||||
/* Round length up to a multiple of bits_per_word */
|
||||
length =
|
||||
(length + bits_per_word - 1) & ~(unsigned long)((bits_per_word - 1));
|
||||
|
||||
l = length / bits_per_word * bytes_per_word;
|
||||
|
||||
/* allocate memory, then set parameters */
|
||||
if (l == 0) {
|
||||
v->word = NULL;
|
||||
v->length = 0;
|
||||
return -1;
|
||||
} else {
|
||||
v->word = (uint32_t *)srtp_crypto_alloc(l);
|
||||
if (v->word == NULL) {
|
||||
v->length = 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
v->length = length;
|
||||
|
||||
/* initialize bitvector to zero */
|
||||
bitvector_set_to_zero(v);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bitvector_dealloc(bitvector_t *v)
|
||||
{
|
||||
if (v->word != NULL)
|
||||
srtp_crypto_free(v->word);
|
||||
v->word = NULL;
|
||||
v->length = 0;
|
||||
}
|
||||
|
||||
void bitvector_set_to_zero(bitvector_t *x)
|
||||
{
|
||||
/* C99 guarantees that memset(0) will set the value 0 for uint32_t */
|
||||
memset(x->word, 0, x->length >> 3);
|
||||
}
|
||||
|
||||
void bitvector_left_shift(bitvector_t *x, int shift)
|
||||
{
|
||||
int i;
|
||||
const int base_index = shift >> 5;
|
||||
const int bit_index = shift & 31;
|
||||
const int word_length = x->length >> 5;
|
||||
|
||||
if (shift >= (int)x->length) {
|
||||
bitvector_set_to_zero(x);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bit_index == 0) {
|
||||
for (i = 0; i < word_length - base_index; i++)
|
||||
x->word[i] = x->word[i + base_index];
|
||||
} else {
|
||||
for (i = 0; i < word_length - base_index - 1; i++)
|
||||
x->word[i] = (x->word[i + base_index] >> bit_index) ^
|
||||
(x->word[i + base_index + 1] << (32 - bit_index));
|
||||
x->word[word_length - base_index - 1] =
|
||||
x->word[word_length - 1] >> bit_index;
|
||||
}
|
||||
|
||||
/* now wrap up the final portion */
|
||||
for (i = word_length - base_index; i < word_length; i++)
|
||||
x->word[i] = 0;
|
||||
}
|
||||
|
||||
int srtp_octet_string_is_eq(uint8_t *a, uint8_t *b, int len)
|
||||
{
|
||||
uint8_t *end = b + len;
|
||||
uint8_t accumulator = 0;
|
||||
|
||||
/*
|
||||
* We use this somewhat obscure implementation to try to ensure the running
|
||||
* time only depends on len, even accounting for compiler optimizations.
|
||||
* The accumulator ends up zero iff the strings are equal.
|
||||
*/
|
||||
while (b < end)
|
||||
accumulator |= (*a++ ^ *b++);
|
||||
|
||||
/* Return 1 if *not* equal. */
|
||||
return accumulator != 0;
|
||||
}
|
||||
|
||||
void srtp_cleanse(void *s, size_t len)
|
||||
{
|
||||
volatile unsigned char *p = (volatile unsigned char *)s;
|
||||
while (len--)
|
||||
*p++ = 0;
|
||||
}
|
||||
|
||||
void octet_string_set_to_zero(void *s, size_t len)
|
||||
{
|
||||
#if defined(OPENSSL) && !defined(OPENSSL_CLEANSE_BROKEN)
|
||||
OPENSSL_cleanse(s, len);
|
||||
#else
|
||||
srtp_cleanse(s, len);
|
||||
#endif
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* rdb.c
|
||||
*
|
||||
* Implements a replay database for packet security
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "rdb.h"
|
||||
|
||||
#define rdb_bits_in_bitmask (8 * sizeof(v128_t))
|
||||
|
||||
/*
|
||||
* this implementation of a replay database works as follows:
|
||||
*
|
||||
* window_start is the index of the first packet in the window
|
||||
* bitmask a bit-buffer, containing the most recently entered
|
||||
* index as the leftmost bit
|
||||
*
|
||||
*/
|
||||
|
||||
/* srtp_rdb_init initalizes rdb */
|
||||
srtp_err_status_t srtp_rdb_init(srtp_rdb_t *rdb)
|
||||
{
|
||||
v128_set_to_zero(&rdb->bitmask);
|
||||
rdb->window_start = 0;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdb_check checks to see if index appears in rdb
|
||||
*/
|
||||
srtp_err_status_t srtp_rdb_check(const srtp_rdb_t *rdb, uint32_t p_index)
|
||||
{
|
||||
/* if the index appears after (or at very end of) the window, its good */
|
||||
if (p_index >= rdb->window_start + rdb_bits_in_bitmask) {
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/* if the index appears before the window, its bad */
|
||||
if (p_index < rdb->window_start) {
|
||||
return srtp_err_status_replay_old;
|
||||
}
|
||||
|
||||
/* otherwise, the index appears within the window, so check the bitmask */
|
||||
if (v128_get_bit(&rdb->bitmask, (p_index - rdb->window_start)) == 1) {
|
||||
return srtp_err_status_replay_fail;
|
||||
}
|
||||
|
||||
/* otherwise, the index is okay */
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdb_add_index adds index to srtp_rdb_t (and does *not* check if
|
||||
* index appears in db)
|
||||
*
|
||||
* this function should be called only after srtp_rdb_check has
|
||||
* indicated that the index does not appear in the rdb, e.g., a mutex
|
||||
* should protect the rdb between these calls
|
||||
*/
|
||||
srtp_err_status_t srtp_rdb_add_index(srtp_rdb_t *rdb, uint32_t p_index)
|
||||
{
|
||||
unsigned int delta;
|
||||
|
||||
if (p_index < rdb->window_start)
|
||||
return srtp_err_status_replay_fail;
|
||||
|
||||
delta = (p_index - rdb->window_start);
|
||||
if (delta < rdb_bits_in_bitmask) {
|
||||
/* if the p_index is within the window, set the appropriate bit */
|
||||
v128_set_bit(&rdb->bitmask, delta);
|
||||
|
||||
} else {
|
||||
delta -= rdb_bits_in_bitmask - 1;
|
||||
|
||||
/* shift the window forward by delta bits*/
|
||||
v128_left_shift(&rdb->bitmask, delta);
|
||||
v128_set_bit(&rdb->bitmask, rdb_bits_in_bitmask - 1);
|
||||
rdb->window_start += delta;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_rdb_increment(srtp_rdb_t *rdb)
|
||||
{
|
||||
if (rdb->window_start >= 0x7fffffff) {
|
||||
return srtp_err_status_key_expired;
|
||||
}
|
||||
++rdb->window_start;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
uint32_t srtp_rdb_get_value(const srtp_rdb_t *rdb)
|
||||
{
|
||||
return rdb->window_start;
|
||||
}
|
||||
@@ -1,386 +0,0 @@
|
||||
/*
|
||||
* rdbx.c
|
||||
*
|
||||
* a replay database with extended range, using a rollover counter
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "rdbx.h"
|
||||
|
||||
/*
|
||||
* from RFC 3711:
|
||||
*
|
||||
* A receiver reconstructs the index i of a packet with sequence
|
||||
* number SEQ using the estimate
|
||||
*
|
||||
* i = 2^16 * v + SEQ,
|
||||
*
|
||||
* where v is chosen from the set { ROC-1, ROC, ROC+1 } such that i is
|
||||
* closest to the value 2^16 * ROC + s_l. If the value r+1 is used,
|
||||
* then the rollover counter r in the cryptographic context is
|
||||
* incremented by one (if the packet containing s is authentic).
|
||||
*/
|
||||
|
||||
/*
|
||||
* rdbx implementation notes
|
||||
*
|
||||
* A srtp_xtd_seq_num_t is essentially a sequence number for which some of
|
||||
* the data on the wire are implicit. It logically consists of a
|
||||
* rollover counter and a sequence number; the sequence number is the
|
||||
* explicit part, and the rollover counter is the implicit part.
|
||||
*
|
||||
* Upon receiving a sequence_number (e.g. in a newly received SRTP
|
||||
* packet), the complete srtp_xtd_seq_num_t can be estimated by using a
|
||||
* local srtp_xtd_seq_num_t as a basis. This is done using the function
|
||||
* srtp_index_guess(&local, &guess, seq_from_packet). This function
|
||||
* returns the difference of the guess and the local value. The local
|
||||
* srtp_xtd_seq_num_t can be moved forward to the guess using the function
|
||||
* srtp_index_advance(&guess, delta), where delta is the difference.
|
||||
*
|
||||
*
|
||||
* A srtp_rdbx_t consists of a srtp_xtd_seq_num_t and a bitmask. The index is
|
||||
* highest sequence number that has been received, and the bitmask indicates
|
||||
* which of the recent indicies have been received as well. The
|
||||
* highest bit in the bitmask corresponds to the index in the bitmask.
|
||||
*/
|
||||
|
||||
void srtp_index_init(srtp_xtd_seq_num_t *pi)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
*pi = make64(0, 0);
|
||||
#else
|
||||
*pi = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void srtp_index_advance(srtp_xtd_seq_num_t *pi, srtp_sequence_number_t s)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
/* a > ~b means a+b will generate a carry */
|
||||
/* s is uint16 here */
|
||||
*pi = make64(high32(*pi) + (s > ~low32(*pi) ? 1 : 0), low32(*pi) + s);
|
||||
#else
|
||||
*pi += s;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_index_guess(local, guess, s)
|
||||
*
|
||||
* given a srtp_xtd_seq_num_t local (which represents the last
|
||||
* known-to-be-good received srtp_xtd_seq_num_t) and a sequence number s
|
||||
* (from a newly arrived packet), sets the contents of *guess to
|
||||
* contain the best guess of the packet index to which s corresponds,
|
||||
* and returns the difference between *guess and *local
|
||||
*
|
||||
* nota bene - the output is a signed integer, DON'T cast it to a
|
||||
* unsigned integer!
|
||||
*/
|
||||
|
||||
int32_t srtp_index_guess(const srtp_xtd_seq_num_t *local,
|
||||
srtp_xtd_seq_num_t *guess,
|
||||
srtp_sequence_number_t s)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
uint32_t local_roc = ((high32(*local) << 16) | (low32(*local) >> 16));
|
||||
uint16_t local_seq = (uint16_t)(low32(*local));
|
||||
#else
|
||||
uint32_t local_roc = (uint32_t)(*local >> 16);
|
||||
uint16_t local_seq = (uint16_t)*local;
|
||||
#endif
|
||||
uint32_t guess_roc;
|
||||
uint16_t guess_seq;
|
||||
int32_t difference;
|
||||
|
||||
if (local_seq < seq_num_median) {
|
||||
if (s - local_seq > seq_num_median) {
|
||||
guess_roc = local_roc - 1;
|
||||
difference = s - local_seq - seq_num_max;
|
||||
} else {
|
||||
guess_roc = local_roc;
|
||||
difference = s - local_seq;
|
||||
}
|
||||
} else {
|
||||
if (local_seq - seq_num_median > s) {
|
||||
guess_roc = local_roc + 1;
|
||||
difference = s - local_seq + seq_num_max;
|
||||
} else {
|
||||
guess_roc = local_roc;
|
||||
difference = s - local_seq;
|
||||
}
|
||||
}
|
||||
guess_seq = s;
|
||||
|
||||
/* Note: guess_roc is 32 bits, so this generates a 48-bit result! */
|
||||
#ifdef NO_64BIT_MATH
|
||||
*guess = make64(guess_roc >> 16, (guess_roc << 16) | guess_seq);
|
||||
#else
|
||||
*guess = (((uint64_t)guess_roc) << 16) | guess_seq;
|
||||
#endif
|
||||
|
||||
return difference;
|
||||
}
|
||||
|
||||
/*
|
||||
* rdbx
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* srtp_rdbx_init(&r, ws) initializes the srtp_rdbx_t pointed to by r with
|
||||
* window size ws
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_init(srtp_rdbx_t *rdbx, unsigned long ws)
|
||||
{
|
||||
if (ws == 0) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
if (bitvector_alloc(&rdbx->bitmask, ws) != 0) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
srtp_index_init(&rdbx->index);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_dealloc(&r) frees memory for the srtp_rdbx_t pointed to by r
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_dealloc(srtp_rdbx_t *rdbx)
|
||||
{
|
||||
bitvector_dealloc(&rdbx->bitmask);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_set_roc(rdbx, roc) initalizes the srtp_rdbx_t at the location rdbx
|
||||
* to have the rollover counter value roc. If that value is less than
|
||||
* the current rollover counter value, then the function returns
|
||||
* srtp_err_status_replay_old; otherwise, srtp_err_status_ok is returned.
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_set_roc(srtp_rdbx_t *rdbx, uint32_t roc)
|
||||
{
|
||||
bitvector_set_to_zero(&rdbx->bitmask);
|
||||
|
||||
#ifdef NO_64BIT_MATH
|
||||
#error not yet implemented
|
||||
#else
|
||||
|
||||
/* make sure that we're not moving backwards */
|
||||
if (roc < (rdbx->index >> 16)) {
|
||||
return srtp_err_status_replay_old;
|
||||
}
|
||||
|
||||
rdbx->index &= 0xffff; /* retain lowest 16 bits */
|
||||
rdbx->index |= ((uint64_t)roc) << 16; /* set ROC */
|
||||
#endif
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_get_packet_index(rdbx) returns the value of the packet index
|
||||
* for the srtp_rdbx_t pointed to by rdbx
|
||||
*
|
||||
*/
|
||||
srtp_xtd_seq_num_t srtp_rdbx_get_packet_index(const srtp_rdbx_t *rdbx)
|
||||
{
|
||||
return rdbx->index;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_get_window_size(rdbx) returns the value of the window size
|
||||
* for the srtp_rdbx_t pointed to by rdbx
|
||||
*
|
||||
*/
|
||||
unsigned long srtp_rdbx_get_window_size(const srtp_rdbx_t *rdbx)
|
||||
{
|
||||
return bitvector_get_length(&rdbx->bitmask);
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_check(&r, delta) checks to see if the srtp_xtd_seq_num_t
|
||||
* which is at rdbx->index + delta is in the rdb
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_check(const srtp_rdbx_t *rdbx, int delta)
|
||||
{
|
||||
if (delta > 0) { /* if delta is positive, it's good */
|
||||
return srtp_err_status_ok;
|
||||
} else if ((int)(bitvector_get_length(&rdbx->bitmask) - 1) + delta < 0) {
|
||||
/* if delta is lower than the bitmask, it's bad */
|
||||
return srtp_err_status_replay_old;
|
||||
} else if (bitvector_get_bit(
|
||||
&rdbx->bitmask,
|
||||
(int)(bitvector_get_length(&rdbx->bitmask) - 1) + delta) ==
|
||||
1) {
|
||||
/* delta is within the window, so check the bitmask */
|
||||
return srtp_err_status_replay_fail;
|
||||
}
|
||||
/* otherwise, the index is okay */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_add_index adds the srtp_xtd_seq_num_t at rdbx->window_start + d to
|
||||
* replay_db (and does *not* check if that srtp_xtd_seq_num_t appears in db)
|
||||
*
|
||||
* this function should be called only after replay_check has
|
||||
* indicated that the index does not appear in the rdbx, e.g., a mutex
|
||||
* should protect the rdbx between these calls if need be
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_add_index(srtp_rdbx_t *rdbx, int delta)
|
||||
{
|
||||
if (delta > 0) {
|
||||
/* shift forward by delta */
|
||||
srtp_index_advance(&rdbx->index, delta);
|
||||
bitvector_left_shift(&rdbx->bitmask, delta);
|
||||
bitvector_set_bit(&rdbx->bitmask,
|
||||
bitvector_get_length(&rdbx->bitmask) - 1);
|
||||
} else {
|
||||
/* delta is in window */
|
||||
bitvector_set_bit(&rdbx->bitmask,
|
||||
bitvector_get_length(&rdbx->bitmask) - 1 + delta);
|
||||
}
|
||||
|
||||
/* note that we need not consider the case that delta == 0 */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_estimate_index(rdbx, guess, s)
|
||||
*
|
||||
* given an rdbx and a sequence number s (from a newly arrived packet),
|
||||
* sets the contents of *guess to contain the best guess of the packet
|
||||
* index to which s corresponds, and returns the difference between
|
||||
* *guess and the locally stored synch info
|
||||
*/
|
||||
int32_t srtp_rdbx_estimate_index(const srtp_rdbx_t *rdbx,
|
||||
srtp_xtd_seq_num_t *guess,
|
||||
srtp_sequence_number_t s)
|
||||
{
|
||||
/*
|
||||
* if the sequence number and rollover counter in the rdbx are
|
||||
* non-zero, then use the srtp_index_guess(...) function, otherwise, just
|
||||
* set the rollover counter to zero (since the srtp_index_guess(...)
|
||||
* function might incorrectly guess that the rollover counter is
|
||||
* 0xffffffff)
|
||||
*/
|
||||
|
||||
#ifdef NO_64BIT_MATH
|
||||
/* seq_num_median = 0x8000 */
|
||||
if (high32(rdbx->index) > 0 || low32(rdbx->index) > seq_num_median)
|
||||
#else
|
||||
if (rdbx->index > seq_num_median)
|
||||
#endif
|
||||
{
|
||||
return srtp_index_guess(&rdbx->index, guess, s);
|
||||
}
|
||||
|
||||
#ifdef NO_64BIT_MATH
|
||||
*guess = make64(0, (uint32_t)s);
|
||||
#else
|
||||
*guess = s;
|
||||
#endif
|
||||
|
||||
#ifdef NO_64BIT_MATH
|
||||
return s - (uint16_t)low32(rdbx->index);
|
||||
#else
|
||||
return s - (uint16_t)rdbx->index;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_get_roc(rdbx)
|
||||
*
|
||||
* Get the current rollover counter
|
||||
*
|
||||
*/
|
||||
uint32_t srtp_rdbx_get_roc(const srtp_rdbx_t *rdbx)
|
||||
{
|
||||
uint32_t roc;
|
||||
|
||||
#ifdef NO_64BIT_MATH
|
||||
roc = ((high32(rdbx->index) << 16) | (low32(rdbx->index) >> 16));
|
||||
#else
|
||||
roc = (uint32_t)(rdbx->index >> 16);
|
||||
#endif
|
||||
|
||||
return roc;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_set_roc_seq(rdbx, roc, seq) initalizes the srtp_rdbx_t at the
|
||||
* location rdbx to have the rollover counter value roc and packet sequence
|
||||
* number seq. If the new rollover counter value is less than the current
|
||||
* rollover counter value, then the function returns
|
||||
* srtp_err_status_replay_old, otherwise, srtp_err_status_ok is returned.
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_set_roc_seq(srtp_rdbx_t *rdbx,
|
||||
uint32_t roc,
|
||||
uint16_t seq)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
#error not yet implemented
|
||||
#else
|
||||
|
||||
/* make sure that we're not moving backwards */
|
||||
if (roc < (rdbx->index >> 16)) {
|
||||
return srtp_err_status_replay_old;
|
||||
}
|
||||
|
||||
rdbx->index = seq;
|
||||
rdbx->index |= ((uint64_t)roc) << 16; /* set ROC */
|
||||
#endif
|
||||
|
||||
bitvector_set_to_zero(&rdbx->bitmask);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
/*
|
||||
* aes_calc.c
|
||||
*
|
||||
* A simple AES calculator for generating AES encryption values
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Example usage (with first NIST FIPS 197 test case):
|
||||
|
||||
[sh]$ test/aes_calc 000102030405060708090a0b0c0d0e0f \
|
||||
00112233445566778899aabbccddeeff -v
|
||||
|
||||
plaintext: 00112233445566778899aabbccddeeff
|
||||
key: 000102030405060708090a0b0c0d0e0f
|
||||
ciphertext: 69c4e0d86a7b0430d8cdb78070b4c55a
|
||||
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "aes.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "util.h"
|
||||
|
||||
void usage(char *prog_name)
|
||||
{
|
||||
printf("usage: %s <key> <plaintext> [<ciphertext>] [-v]\n", prog_name);
|
||||
exit(255);
|
||||
}
|
||||
|
||||
#define AES_MAX_KEY_LEN 32
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *expected_ciphertext = NULL;
|
||||
const char *ciphertext = NULL;
|
||||
v128_t data;
|
||||
uint8_t key[AES_MAX_KEY_LEN];
|
||||
srtp_aes_expanded_key_t exp_key;
|
||||
int key_len, len;
|
||||
int verbose = 0;
|
||||
srtp_err_status_t status;
|
||||
|
||||
/* -v must be last if it's passed */
|
||||
if (argc > 0 && strncmp(argv[argc - 1], "-v", 2) == 0) {
|
||||
/* we're in verbose mode */
|
||||
verbose = 1;
|
||||
--argc;
|
||||
}
|
||||
|
||||
if (argc < 3 || argc > 4) {
|
||||
/* we've been fed the wrong number of arguments - compain and exit */
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
if (argc == 4) {
|
||||
/* we're being passed the ciphertext to check (in unit test mode) */
|
||||
expected_ciphertext = argv[3];
|
||||
if (strlen(expected_ciphertext) != 16 * 2) {
|
||||
usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/* read in key, checking length */
|
||||
if (strlen(argv[1]) > AES_MAX_KEY_LEN * 2) {
|
||||
fprintf(stderr, "error: too many digits in key "
|
||||
"(should be at most %d hexadecimal digits, found %u)\n",
|
||||
AES_MAX_KEY_LEN * 2, (unsigned)strlen(argv[1]));
|
||||
exit(1);
|
||||
}
|
||||
len = hex_string_to_octet_string((char *)key, argv[1], AES_MAX_KEY_LEN * 2);
|
||||
/* check that hex string is the right length */
|
||||
if (len != 32 && len != 48 && len != 64) {
|
||||
fprintf(stderr, "error: bad number of digits in key "
|
||||
"(should be 32/48/64 hexadecimal digits, found %d)\n",
|
||||
len);
|
||||
exit(1);
|
||||
}
|
||||
key_len = len / 2;
|
||||
|
||||
/* read in plaintext, checking length */
|
||||
if (strlen(argv[2]) > 16 * 2) {
|
||||
fprintf(stderr, "error: too many digits in plaintext "
|
||||
"(should be %d hexadecimal digits, found %u)\n",
|
||||
16 * 2, (unsigned)strlen(argv[2]));
|
||||
exit(1);
|
||||
}
|
||||
len = hex_string_to_octet_string((char *)(&data), argv[2], 16 * 2);
|
||||
/* check that hex string is the right length */
|
||||
if (len < 16 * 2) {
|
||||
fprintf(stderr, "error: too few digits in plaintext "
|
||||
"(should be %d hexadecimal digits, found %d)\n",
|
||||
16 * 2, len);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
/* print out plaintext */
|
||||
printf("plaintext:\t%s\n",
|
||||
octet_string_hex_string((uint8_t *)&data, 16));
|
||||
}
|
||||
|
||||
/* encrypt plaintext */
|
||||
status = srtp_aes_expand_encryption_key(key, key_len, &exp_key);
|
||||
if (status) {
|
||||
fprintf(stderr, "error: AES key expansion failed.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
srtp_aes_encrypt(&data, &exp_key);
|
||||
|
||||
/* write ciphertext to output */
|
||||
if (verbose) {
|
||||
printf("key:\t\t%s\n", octet_string_hex_string(key, key_len));
|
||||
printf("ciphertext:\t");
|
||||
}
|
||||
|
||||
ciphertext = v128_hex_string(&data);
|
||||
printf("%s\n", ciphertext);
|
||||
|
||||
if (expected_ciphertext && strcmp(ciphertext, expected_ciphertext) != 0) {
|
||||
fprintf(stderr, "error: calculated ciphertext %s does not match "
|
||||
"expected ciphertext %s\n",
|
||||
ciphertext, expected_ciphertext);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,598 +0,0 @@
|
||||
/*
|
||||
* cipher_driver.c
|
||||
*
|
||||
* A driver for the generic cipher type
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h> /* for printf() */
|
||||
#include "getopt_s.h"
|
||||
#include "cipher.h"
|
||||
#include "cipher_priv.h"
|
||||
#include "datatypes.h"
|
||||
|
||||
#define PRINT_DEBUG 0
|
||||
|
||||
void cipher_driver_test_throughput(srtp_cipher_t *c);
|
||||
|
||||
srtp_err_status_t cipher_driver_self_test(srtp_cipher_type_t *ct);
|
||||
|
||||
/*
|
||||
* cipher_driver_test_buffering(ct) tests the cipher's output
|
||||
* buffering for correctness by checking the consistency of succesive
|
||||
* calls
|
||||
*/
|
||||
|
||||
srtp_err_status_t cipher_driver_test_buffering(srtp_cipher_t *c);
|
||||
|
||||
/*
|
||||
* functions for testing cipher cache thrash
|
||||
*/
|
||||
srtp_err_status_t cipher_driver_test_array_throughput(srtp_cipher_type_t *ct,
|
||||
int klen,
|
||||
int num_cipher);
|
||||
|
||||
void cipher_array_test_throughput(srtp_cipher_t *ca[], int num_cipher);
|
||||
|
||||
uint64_t cipher_array_bits_per_second(srtp_cipher_t *cipher_array[],
|
||||
int num_cipher,
|
||||
unsigned octets_in_buffer,
|
||||
int num_trials);
|
||||
|
||||
srtp_err_status_t cipher_array_delete(srtp_cipher_t *cipher_array[],
|
||||
int num_cipher);
|
||||
|
||||
srtp_err_status_t cipher_array_alloc_init(srtp_cipher_t ***cipher_array,
|
||||
int num_ciphers,
|
||||
srtp_cipher_type_t *ctype,
|
||||
int klen);
|
||||
|
||||
void usage(char *prog_name)
|
||||
{
|
||||
printf("usage: %s [ -t | -v | -a ]\n", prog_name);
|
||||
exit(255);
|
||||
}
|
||||
|
||||
void check_status(srtp_err_status_t s)
|
||||
{
|
||||
if (s) {
|
||||
printf("error (code %d)\n", s);
|
||||
exit(s);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* null_cipher and srtp_aes_icm are the cipher meta-objects
|
||||
* defined in the files in crypto/cipher subdirectory. these are
|
||||
* declared external so that we can use these cipher types here
|
||||
*/
|
||||
|
||||
extern srtp_cipher_type_t srtp_null_cipher;
|
||||
extern srtp_cipher_type_t srtp_aes_icm_128;
|
||||
extern srtp_cipher_type_t srtp_aes_icm_256;
|
||||
#ifdef GCM
|
||||
extern srtp_cipher_type_t srtp_aes_icm_192;
|
||||
extern srtp_cipher_type_t srtp_aes_gcm_128;
|
||||
extern srtp_cipher_type_t srtp_aes_gcm_256;
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
srtp_cipher_t *c = NULL;
|
||||
srtp_err_status_t status;
|
||||
/* clang-format off */
|
||||
unsigned char test_key[48] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
};
|
||||
/* clang-format on */
|
||||
int q;
|
||||
unsigned do_timing_test = 0;
|
||||
unsigned do_validation = 0;
|
||||
unsigned do_array_timing_test = 0;
|
||||
|
||||
/* process input arguments */
|
||||
while (1) {
|
||||
q = getopt_s(argc, argv, "tva");
|
||||
if (q == -1)
|
||||
break;
|
||||
switch (q) {
|
||||
case 't':
|
||||
do_timing_test = 1;
|
||||
break;
|
||||
case 'v':
|
||||
do_validation = 1;
|
||||
break;
|
||||
case 'a':
|
||||
do_array_timing_test = 1;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
printf("cipher test driver\n"
|
||||
"David A. McGrew\n"
|
||||
"Cisco Systems, Inc.\n");
|
||||
|
||||
if (!do_validation && !do_timing_test && !do_array_timing_test)
|
||||
usage(argv[0]);
|
||||
|
||||
/* arry timing (cache thrash) test */
|
||||
if (do_array_timing_test) {
|
||||
int max_num_cipher = 1 << 16; /* number of ciphers in cipher_array */
|
||||
int num_cipher;
|
||||
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8)
|
||||
cipher_driver_test_array_throughput(&srtp_null_cipher, 0,
|
||||
num_cipher);
|
||||
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8)
|
||||
cipher_driver_test_array_throughput(
|
||||
&srtp_aes_icm_128, SRTP_AES_ICM_128_KEY_LEN_WSALT, num_cipher);
|
||||
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8)
|
||||
cipher_driver_test_array_throughput(
|
||||
&srtp_aes_icm_256, SRTP_AES_ICM_256_KEY_LEN_WSALT, num_cipher);
|
||||
|
||||
#ifdef GCM
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8)
|
||||
cipher_driver_test_array_throughput(
|
||||
&srtp_aes_icm_192, SRTP_AES_ICM_192_KEY_LEN_WSALT, num_cipher);
|
||||
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8) {
|
||||
cipher_driver_test_array_throughput(
|
||||
&srtp_aes_gcm_128, SRTP_AES_GCM_128_KEY_LEN_WSALT, num_cipher);
|
||||
}
|
||||
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8) {
|
||||
cipher_driver_test_array_throughput(
|
||||
&srtp_aes_gcm_256, SRTP_AES_GCM_256_KEY_LEN_WSALT, num_cipher);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (do_validation) {
|
||||
cipher_driver_self_test(&srtp_null_cipher);
|
||||
cipher_driver_self_test(&srtp_aes_icm_128);
|
||||
cipher_driver_self_test(&srtp_aes_icm_256);
|
||||
#ifdef GCM
|
||||
cipher_driver_self_test(&srtp_aes_icm_192);
|
||||
cipher_driver_self_test(&srtp_aes_gcm_128);
|
||||
cipher_driver_self_test(&srtp_aes_gcm_256);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* do timing and/or buffer_test on srtp_null_cipher */
|
||||
status = srtp_cipher_type_alloc(&srtp_null_cipher, &c, 0, 0);
|
||||
check_status(status);
|
||||
|
||||
status = srtp_cipher_init(c, NULL);
|
||||
check_status(status);
|
||||
|
||||
if (do_timing_test)
|
||||
cipher_driver_test_throughput(c);
|
||||
if (do_validation) {
|
||||
status = cipher_driver_test_buffering(c);
|
||||
check_status(status);
|
||||
}
|
||||
status = srtp_cipher_dealloc(c);
|
||||
check_status(status);
|
||||
|
||||
/* run the throughput test on the aes_icm cipher (128-bit key) */
|
||||
status = srtp_cipher_type_alloc(&srtp_aes_icm_128, &c,
|
||||
SRTP_AES_ICM_128_KEY_LEN_WSALT, 0);
|
||||
if (status) {
|
||||
fprintf(stderr, "error: can't allocate cipher\n");
|
||||
exit(status);
|
||||
}
|
||||
|
||||
status = srtp_cipher_init(c, test_key);
|
||||
check_status(status);
|
||||
|
||||
if (do_timing_test)
|
||||
cipher_driver_test_throughput(c);
|
||||
|
||||
if (do_validation) {
|
||||
status = cipher_driver_test_buffering(c);
|
||||
check_status(status);
|
||||
}
|
||||
|
||||
status = srtp_cipher_dealloc(c);
|
||||
check_status(status);
|
||||
|
||||
/* repeat the tests with 256-bit keys */
|
||||
status = srtp_cipher_type_alloc(&srtp_aes_icm_256, &c,
|
||||
SRTP_AES_ICM_256_KEY_LEN_WSALT, 0);
|
||||
if (status) {
|
||||
fprintf(stderr, "error: can't allocate cipher\n");
|
||||
exit(status);
|
||||
}
|
||||
|
||||
status = srtp_cipher_init(c, test_key);
|
||||
check_status(status);
|
||||
|
||||
if (do_timing_test)
|
||||
cipher_driver_test_throughput(c);
|
||||
|
||||
if (do_validation) {
|
||||
status = cipher_driver_test_buffering(c);
|
||||
check_status(status);
|
||||
}
|
||||
|
||||
status = srtp_cipher_dealloc(c);
|
||||
check_status(status);
|
||||
|
||||
#ifdef GCM
|
||||
/* run the throughput test on the aes_gcm_128 cipher */
|
||||
status = srtp_cipher_type_alloc(&srtp_aes_gcm_128, &c,
|
||||
SRTP_AES_GCM_128_KEY_LEN_WSALT, 8);
|
||||
if (status) {
|
||||
fprintf(stderr, "error: can't allocate GCM 128 cipher\n");
|
||||
exit(status);
|
||||
}
|
||||
status = srtp_cipher_init(c, test_key);
|
||||
check_status(status);
|
||||
if (do_timing_test) {
|
||||
cipher_driver_test_throughput(c);
|
||||
}
|
||||
|
||||
// GCM ciphers don't do buffering; they're "one shot"
|
||||
|
||||
status = srtp_cipher_dealloc(c);
|
||||
check_status(status);
|
||||
|
||||
/* run the throughput test on the aes_gcm_256 cipher */
|
||||
status = srtp_cipher_type_alloc(&srtp_aes_gcm_256, &c,
|
||||
SRTP_AES_GCM_256_KEY_LEN_WSALT, 16);
|
||||
if (status) {
|
||||
fprintf(stderr, "error: can't allocate GCM 256 cipher\n");
|
||||
exit(status);
|
||||
}
|
||||
status = srtp_cipher_init(c, test_key);
|
||||
check_status(status);
|
||||
if (do_timing_test) {
|
||||
cipher_driver_test_throughput(c);
|
||||
}
|
||||
|
||||
// GCM ciphers don't do buffering; they're "one shot"
|
||||
|
||||
status = srtp_cipher_dealloc(c);
|
||||
check_status(status);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cipher_driver_test_throughput(srtp_cipher_t *c)
|
||||
{
|
||||
int i;
|
||||
int min_enc_len = 32;
|
||||
int max_enc_len = 2048; /* should be a power of two */
|
||||
int num_trials = 1000000;
|
||||
|
||||
printf("timing %s throughput, key length %d:\n", c->type->description,
|
||||
c->key_len);
|
||||
fflush(stdout);
|
||||
for (i = min_enc_len; i <= max_enc_len; i = i * 2)
|
||||
printf("msg len: %d\tgigabits per second: %f\n", i,
|
||||
srtp_cipher_bits_per_second(c, i, num_trials) / 1e9);
|
||||
}
|
||||
|
||||
srtp_err_status_t cipher_driver_self_test(srtp_cipher_type_t *ct)
|
||||
{
|
||||
srtp_err_status_t status;
|
||||
|
||||
printf("running cipher self-test for %s...", ct->description);
|
||||
status = srtp_cipher_type_self_test(ct);
|
||||
if (status) {
|
||||
printf("failed with error code %d\n", status);
|
||||
exit(status);
|
||||
}
|
||||
printf("passed\n");
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* cipher_driver_test_buffering(ct) tests the cipher's output
|
||||
* buffering for correctness by checking the consistency of succesive
|
||||
* calls
|
||||
*/
|
||||
|
||||
#define INITIAL_BUFLEN 1024
|
||||
srtp_err_status_t cipher_driver_test_buffering(srtp_cipher_t *c)
|
||||
{
|
||||
int i, j, num_trials = 1000;
|
||||
unsigned len, buflen = INITIAL_BUFLEN;
|
||||
uint8_t buffer0[INITIAL_BUFLEN], buffer1[INITIAL_BUFLEN], *current, *end;
|
||||
uint8_t idx[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34 };
|
||||
srtp_err_status_t status;
|
||||
|
||||
printf("testing output buffering for cipher %s...", c->type->description);
|
||||
|
||||
for (i = 0; i < num_trials; i++) {
|
||||
/* set buffers to zero */
|
||||
for (j = 0; j < (int)buflen; j++) {
|
||||
buffer0[j] = buffer1[j] = 0;
|
||||
}
|
||||
|
||||
/* initialize cipher */
|
||||
status = srtp_cipher_set_iv(c, (uint8_t *)idx, srtp_direction_encrypt);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* generate 'reference' value by encrypting all at once */
|
||||
status = srtp_cipher_encrypt(c, buffer0, &buflen);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* re-initialize cipher */
|
||||
status = srtp_cipher_set_iv(c, (uint8_t *)idx, srtp_direction_encrypt);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* now loop over short lengths until buffer1 is encrypted */
|
||||
current = buffer1;
|
||||
end = buffer1 + buflen;
|
||||
while (current < end) {
|
||||
/* choose a short length */
|
||||
len = srtp_cipher_rand_u32_for_tests() & 0x01f;
|
||||
|
||||
/* make sure that len doesn't cause us to overreach the buffer */
|
||||
if (current + len > end)
|
||||
len = end - current;
|
||||
|
||||
status = srtp_cipher_encrypt(c, current, &len);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* advance pointer into buffer1 to reflect encryption */
|
||||
current += len;
|
||||
|
||||
/* if buffer1 is all encrypted, break out of loop */
|
||||
if (current == end)
|
||||
break;
|
||||
}
|
||||
|
||||
/* compare buffers */
|
||||
for (j = 0; j < (int)buflen; j++) {
|
||||
if (buffer0[j] != buffer1[j]) {
|
||||
#if PRINT_DEBUG
|
||||
printf("test case %d failed at byte %d\n", i, j);
|
||||
printf("computed: %s\n",
|
||||
octet_string_hex_string(buffer1, buflen));
|
||||
printf("expected: %s\n",
|
||||
octet_string_hex_string(buffer0, buflen));
|
||||
#endif
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("passed\n");
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* The function cipher_test_throughput_array() tests the effect of CPU
|
||||
* cache thrash on cipher throughput.
|
||||
*
|
||||
* cipher_array_alloc_init(ctype, array, num_ciphers) creates an array
|
||||
* of srtp_cipher_t of type ctype
|
||||
*/
|
||||
|
||||
srtp_err_status_t cipher_array_alloc_init(srtp_cipher_t ***ca,
|
||||
int num_ciphers,
|
||||
srtp_cipher_type_t *ctype,
|
||||
int klen)
|
||||
{
|
||||
int i, j;
|
||||
srtp_err_status_t status;
|
||||
uint8_t *key;
|
||||
srtp_cipher_t **cipher_array;
|
||||
/* pad klen allocation, to handle aes_icm reading 16 bytes for the
|
||||
14-byte salt */
|
||||
int klen_pad = ((klen + 15) >> 4) << 4;
|
||||
|
||||
/* allocate array of pointers to ciphers */
|
||||
cipher_array = (srtp_cipher_t **)srtp_crypto_alloc(sizeof(srtp_cipher_t *) *
|
||||
num_ciphers);
|
||||
if (cipher_array == NULL)
|
||||
return srtp_err_status_alloc_fail;
|
||||
|
||||
/* set ca to location of cipher_array */
|
||||
*ca = cipher_array;
|
||||
|
||||
/* allocate key */
|
||||
key = srtp_crypto_alloc(klen_pad);
|
||||
if (key == NULL) {
|
||||
srtp_crypto_free(cipher_array);
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* allocate and initialize an array of ciphers */
|
||||
for (i = 0; i < num_ciphers; i++) {
|
||||
/* allocate cipher */
|
||||
status = srtp_cipher_type_alloc(ctype, cipher_array, klen, 16);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* generate random key and initialize cipher */
|
||||
srtp_cipher_rand_for_tests(key, klen);
|
||||
for (j = klen; j < klen_pad; j++)
|
||||
key[j] = 0;
|
||||
status = srtp_cipher_init(*cipher_array, key);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* printf("%dth cipher is at %p\n", i, *cipher_array); */
|
||||
/* printf("%dth cipher description: %s\n", i, */
|
||||
/* (*cipher_array)->type->description); */
|
||||
|
||||
/* advance cipher array pointer */
|
||||
cipher_array++;
|
||||
}
|
||||
|
||||
srtp_crypto_free(key);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t cipher_array_delete(srtp_cipher_t *cipher_array[],
|
||||
int num_cipher)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_cipher; i++) {
|
||||
srtp_cipher_dealloc(cipher_array[i]);
|
||||
}
|
||||
|
||||
srtp_crypto_free(cipher_array);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* cipher_array_bits_per_second(c, l, t) computes (an estimate of) the
|
||||
* number of bits that a cipher implementation can encrypt in a second
|
||||
* when distinct keys are used to encrypt distinct messages
|
||||
*
|
||||
* c is a cipher (which MUST be allocated an initialized already), l
|
||||
* is the length in octets of the test data to be encrypted, and t is
|
||||
* the number of trials
|
||||
*
|
||||
* if an error is encountered, the value 0 is returned
|
||||
*/
|
||||
|
||||
uint64_t cipher_array_bits_per_second(srtp_cipher_t *cipher_array[],
|
||||
int num_cipher,
|
||||
unsigned octets_in_buffer,
|
||||
int num_trials)
|
||||
{
|
||||
int i;
|
||||
v128_t nonce;
|
||||
clock_t timer;
|
||||
unsigned char *enc_buf;
|
||||
int cipher_index = srtp_cipher_rand_u32_for_tests() % num_cipher;
|
||||
|
||||
/* Over-alloc, for NIST CBC padding */
|
||||
enc_buf = srtp_crypto_alloc(octets_in_buffer + 17);
|
||||
if (enc_buf == NULL)
|
||||
return 0; /* indicate bad parameters by returning null */
|
||||
|
||||
/* time repeated trials */
|
||||
v128_set_to_zero(&nonce);
|
||||
timer = clock();
|
||||
for (i = 0; i < num_trials; i++, nonce.v32[3] = i) {
|
||||
/* length parameter to srtp_cipher_encrypt is in/out -- out is total,
|
||||
* padded
|
||||
* length -- so reset it each time. */
|
||||
unsigned octets_to_encrypt = octets_in_buffer;
|
||||
|
||||
/* encrypt buffer with cipher */
|
||||
srtp_cipher_set_iv(cipher_array[cipher_index], (uint8_t *)&nonce,
|
||||
srtp_direction_encrypt);
|
||||
srtp_cipher_encrypt(cipher_array[cipher_index], enc_buf,
|
||||
&octets_to_encrypt);
|
||||
|
||||
/* choose a cipher at random from the array*/
|
||||
cipher_index = (*((uint32_t *)enc_buf)) % num_cipher;
|
||||
}
|
||||
timer = clock() - timer;
|
||||
|
||||
srtp_crypto_free(enc_buf);
|
||||
|
||||
if (timer == 0) {
|
||||
/* Too fast! */
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint64_t)CLOCKS_PER_SEC * num_trials * 8 * octets_in_buffer / timer;
|
||||
}
|
||||
|
||||
void cipher_array_test_throughput(srtp_cipher_t *ca[], int num_cipher)
|
||||
{
|
||||
int i;
|
||||
int min_enc_len = 16;
|
||||
int max_enc_len = 2048; /* should be a power of two */
|
||||
int num_trials = 1000000;
|
||||
|
||||
printf("timing %s throughput with key length %d, array size %d:\n",
|
||||
(ca[0])->type->description, (ca[0])->key_len, num_cipher);
|
||||
fflush(stdout);
|
||||
for (i = min_enc_len; i <= max_enc_len; i = i * 4)
|
||||
printf("msg len: %d\tgigabits per second: %f\n", i,
|
||||
cipher_array_bits_per_second(ca, num_cipher, i, num_trials) /
|
||||
1e9);
|
||||
}
|
||||
|
||||
srtp_err_status_t cipher_driver_test_array_throughput(srtp_cipher_type_t *ct,
|
||||
int klen,
|
||||
int num_cipher)
|
||||
{
|
||||
srtp_cipher_t **ca = NULL;
|
||||
srtp_err_status_t status;
|
||||
|
||||
status = cipher_array_alloc_init(&ca, num_cipher, ct, klen);
|
||||
if (status) {
|
||||
printf("error: cipher_array_alloc_init() failed with error code %d\n",
|
||||
status);
|
||||
return status;
|
||||
}
|
||||
|
||||
cipher_array_test_throughput(ca, num_cipher);
|
||||
|
||||
cipher_array_delete(ca, num_cipher);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
/*
|
||||
* datatypes_driver.c
|
||||
*
|
||||
* a test driver for crypto/math datatypes
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h> /* for printf() */
|
||||
#include <string.h> /* for strlen() */
|
||||
#include "datatypes.h"
|
||||
#include "util.h"
|
||||
|
||||
void byte_order(void);
|
||||
|
||||
void test_hex_string_funcs(void);
|
||||
|
||||
void print_string(char *s);
|
||||
|
||||
void test_bswap(void);
|
||||
|
||||
void test_set_to_zero(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/*
|
||||
* this program includes various and sundry tests for fundamental
|
||||
* datatypes. it's a grab-bag of throwaway code, retained only in
|
||||
* case of future problems
|
||||
*/
|
||||
|
||||
int i, j;
|
||||
v128_t x;
|
||||
char *r = "The Moving Finger writes; and, having writ,\n"
|
||||
"Moves on: nor all thy Piety nor Wit\n"
|
||||
"Shall lure it back to cancel half a Line,\n"
|
||||
"Nor all thy Tears wash out a Word of it.";
|
||||
char *s = "incomplet";
|
||||
|
||||
print_string(r);
|
||||
print_string(s);
|
||||
|
||||
byte_order();
|
||||
test_hex_string_funcs();
|
||||
|
||||
for (j = 0; j < 128; j++) {
|
||||
v128_set_to_zero(&x);
|
||||
/* x.v32[0] = (1 << j); */
|
||||
v128_set_bit(&x, j);
|
||||
printf("%s\n", v128_bit_string(&x));
|
||||
v128_clear_bit(&x, j);
|
||||
printf("%s\n", v128_bit_string(&x));
|
||||
}
|
||||
|
||||
printf("----------------------------------------------\n");
|
||||
v128_set_to_zero(&x);
|
||||
for (i = 0; i < 128; i++) {
|
||||
v128_set_bit(&x, i);
|
||||
}
|
||||
printf("%s\n", v128_bit_string(&x));
|
||||
|
||||
printf("----------------------------------------------\n");
|
||||
v128_set_to_zero(&x);
|
||||
v128_set_bit(&x, 127);
|
||||
for (i = 0; i < 128; i++) {
|
||||
printf("%s\n", v128_bit_string(&x));
|
||||
v128_left_shift(&x, 1);
|
||||
}
|
||||
printf("----------------------------------------------\n");
|
||||
for (i = 0; i < 128; i++) {
|
||||
v128_set_to_zero(&x);
|
||||
v128_set_bit(&x, 127);
|
||||
v128_left_shift(&x, i);
|
||||
printf("%s\n", v128_bit_string(&x));
|
||||
}
|
||||
printf("----------------------------------------------\n");
|
||||
v128_set_to_zero(&x);
|
||||
for (i = 0; i < 128; i += 2) {
|
||||
v128_set_bit(&x, i);
|
||||
}
|
||||
printf("bit_string: { %s }\n", v128_bit_string(&x));
|
||||
printf("get_bit: { ");
|
||||
for (i = 0; i < 128; i++) {
|
||||
if (v128_get_bit(&x, i) == 1)
|
||||
printf("1");
|
||||
else
|
||||
printf("0");
|
||||
}
|
||||
printf(" } \n");
|
||||
|
||||
test_bswap();
|
||||
test_set_to_zero();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* byte_order() prints out byte ordering of datatypes */
|
||||
|
||||
void byte_order(void)
|
||||
{
|
||||
int i;
|
||||
v128_t e;
|
||||
|
||||
printf("byte ordering of crypto/math datatypes:\n");
|
||||
for (i = 0; i < sizeof(e); i++)
|
||||
e.v8[i] = i;
|
||||
printf("v128_t: %s\n", v128_hex_string(&e));
|
||||
}
|
||||
|
||||
void test_hex_string_funcs(void)
|
||||
{
|
||||
char hex1[] = "abadcafe";
|
||||
char hex2[] = "0123456789abcdefqqqqq";
|
||||
char raw[10];
|
||||
int len;
|
||||
|
||||
len = hex_string_to_octet_string(raw, hex1, strlen(hex1));
|
||||
printf("computed length: %d\tstring: %s\n", len,
|
||||
octet_string_hex_string(raw, len / 2));
|
||||
printf("expected length: %u\tstring: %s\n", (unsigned)strlen(hex1), hex1);
|
||||
|
||||
len = hex_string_to_octet_string(raw, hex2, strlen(hex2));
|
||||
printf("computed length: %d\tstring: %s\n", len,
|
||||
octet_string_hex_string(raw, len / 2));
|
||||
printf("expected length: %d\tstring: %s\n", 16, "0123456789abcdef");
|
||||
}
|
||||
|
||||
void print_string(char *s)
|
||||
{
|
||||
size_t i;
|
||||
printf("%s\n", s);
|
||||
printf("strlen(s) = %u\n", (unsigned)strlen(s));
|
||||
printf("{ ");
|
||||
for (i = 0; i < strlen(s); i++) {
|
||||
printf("0x%x, ", s[i]);
|
||||
if (((i + 1) % 8) == 0)
|
||||
printf("\n ");
|
||||
}
|
||||
printf("}\n");
|
||||
}
|
||||
|
||||
void test_bswap(void)
|
||||
{
|
||||
uint32_t x = 0x11223344;
|
||||
uint64_t y = 0x1122334455667788LL;
|
||||
|
||||
printf("before: %0x\nafter: %0x\n", x, (unsigned int)be32_to_cpu(x));
|
||||
printf("before: %0llx\nafter: %0llx\n", (unsigned long long)y,
|
||||
(unsigned long long)be64_to_cpu(y));
|
||||
|
||||
y = 1234;
|
||||
|
||||
printf("1234: %0llx\n", (unsigned long long)y);
|
||||
printf("as octet string: %s\n", octet_string_hex_string((uint8_t *)&y, 8));
|
||||
y = be64_to_cpu(y);
|
||||
printf("bswapped octet string: %s\n",
|
||||
octet_string_hex_string((uint8_t *)&y, 8));
|
||||
}
|
||||
|
||||
void test_set_to_zero(void)
|
||||
{
|
||||
#define BUFFER_SIZE (16)
|
||||
uint8_t buffer[BUFFER_SIZE];
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < BUFFER_SIZE; i++) {
|
||||
buffer[i] = i & 0xff;
|
||||
}
|
||||
printf("Buffer before: %s\n", octet_string_hex_string(buffer, BUFFER_SIZE));
|
||||
octet_string_set_to_zero(buffer, BUFFER_SIZE);
|
||||
printf("Buffer after: %s\n", octet_string_hex_string(buffer, BUFFER_SIZE));
|
||||
for (i = 0; i < BUFFER_SIZE; i++) {
|
||||
if (buffer[i]) {
|
||||
fprintf(stderr,
|
||||
"Buffer contents not zero at position %zu (is %d)\n", i,
|
||||
buffer[i]);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
#undef BUFFER_SIZE
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* env.c
|
||||
*
|
||||
* prints out a brief report on the build environment
|
||||
*
|
||||
* David McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h> /* for srtcmp() */
|
||||
#include "config.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int err_count = 0;
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
printf("CPU set to big-endian\t\t\t(WORDS_BIGENDIAN == 1)\n");
|
||||
#else
|
||||
printf("CPU set to little-endian\t\t(WORDS_BIGENDIAN == 0)\n");
|
||||
#endif
|
||||
|
||||
#ifdef CPU_RISC
|
||||
printf("CPU set to RISC\t\t\t\t(CPU_RISC == 1)\n");
|
||||
#elif defined(CPU_CISC)
|
||||
printf("CPU set to CISC\t\t\t\t(CPU_CISC == 1)\n");
|
||||
#else
|
||||
printf(
|
||||
"CPU set to an unknown type, probably due to a configuration error\n");
|
||||
err_count++;
|
||||
#endif
|
||||
|
||||
#ifdef CPU_ALTIVEC
|
||||
printf("CPU set to ALTIVEC\t\t\t\t(CPU_ALTIVEC == 0)\n");
|
||||
#endif
|
||||
|
||||
#ifndef NO_64BIT_MATH
|
||||
printf("using native 64-bit type\t\t(NO_64_BIT_MATH == 0)\n");
|
||||
#else
|
||||
printf("using built-in 64-bit math\t\t(NO_64_BIT_MATH == 1)\n");
|
||||
#endif
|
||||
|
||||
#ifdef ERR_REPORTING_STDOUT
|
||||
printf("using stdout for error reporting\t(ERR_REPORTING_STDOUT == 1)\n");
|
||||
#endif
|
||||
|
||||
if (err_count)
|
||||
printf("warning: configuration is probably in error "
|
||||
"(found %d problems)\n",
|
||||
err_count);
|
||||
|
||||
return err_count;
|
||||
}
|
||||
Loaded 100 of 153 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user