mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-02-05 02:34:18 +00:00
Merge libzrtp fixes and improvements
This brings FS's libzrtp up to date with upstream with the exception of the changes to the cache API, the new SQLite cache backend, and SDES support. In particular, this merge brings in support for elliptic curve (ECC) algorithms.
This commit is contained in:
commit
89980756c4
@ -159,11 +159,11 @@ CORE_CFLAGS += -I$(switch_srcdir)/libs/libzrtp/third_party/bgaes
|
||||
CORE_CFLAGS += -I$(switch_srcdir)/libs/libzrtp/third_party/bnlib
|
||||
CORE_CFLAGS += -isystem $(switch_srcdir)/libs/libzrtp/include
|
||||
ZRTP_LDFLAGS = -L$(switch_srcdir)/libs/libzrtp/third_party/bnlib
|
||||
ZRTP_LDFLAGS += -L$(switch_srcdir)/libs/libzrtp/projects/gnu/build
|
||||
ZRTP_LDFLAGS += -L$(switch_srcdir)/libs/libzrtp
|
||||
ZRTP_LIBS = -lbn -lzrtp
|
||||
libfreeswitch_la_LDFLAGS += $(ZRTP_LDFLAGS)
|
||||
libfreeswitch_la_LIBADD += $(ZRTP_LIBS)
|
||||
CORE_LIBS += libs/libzrtp/projects/gnu/build/libzrtp.a
|
||||
CORE_LIBS += libs/libzrtp/libzrtp.a
|
||||
LIBS += libs/libzrtp/third_party/bnlib/libbn.a
|
||||
endif
|
||||
|
||||
@ -441,8 +441,8 @@ src/include/switch_version.h: src/include/switch_version.h.in Makefile build/pri
|
||||
libs/libedit/src/.libs/libedit.a:
|
||||
cd libs/libedit && $(MAKE)
|
||||
|
||||
libs/libzrtp/projects/gnu/build/libzrtp.a:
|
||||
cd libs/libzrtp/projects/gnu && $(MAKE)
|
||||
libs/libzrtp/libzrtp.a:
|
||||
cd libs/libzrtp && $(MAKE)
|
||||
|
||||
libs/sofia-sip/Makefile:
|
||||
cd libs/sofia-sip && sh ./configure.gnu --prefix=$(prefix)
|
||||
|
@ -347,7 +347,7 @@ bootstrap_apr() {
|
||||
}
|
||||
|
||||
bootstrap_libzrtp() {
|
||||
(cd ${LIBDIR}/libzrtp/projects/gnu && ./bootstrap.sh)
|
||||
(cd ${LIBDIR}/libzrtp && ./bootstrap.sh)
|
||||
}
|
||||
|
||||
# Libs automake automation function
|
||||
|
@ -1181,7 +1181,7 @@ AC_CONFIG_SUBDIRS([libs/libg722_1])
|
||||
AC_CONFIG_SUBDIRS([libs/silk])
|
||||
AC_CONFIG_SUBDIRS([libs/libcodec2])
|
||||
if test "x${enable_zrtp}" = "xyes"; then
|
||||
AC_CONFIG_SUBDIRS([libs/libzrtp/projects/gnu])
|
||||
AC_CONFIG_SUBDIRS([libs/libzrtp])
|
||||
fi
|
||||
AC_CONFIG_SUBDIRS([libs/libwebsockets])
|
||||
|
||||
|
20
libs/libzrtp/.gitignore
vendored
20
libs/libzrtp/.gitignore
vendored
@ -1,2 +1,22 @@
|
||||
# -*- mode:conf -*-
|
||||
/*.a
|
||||
/*.dat
|
||||
/*.o
|
||||
/.cproject
|
||||
/.deps
|
||||
/.project
|
||||
/.stamp-doc
|
||||
/Makefile
|
||||
/Makefile.in
|
||||
/_configs.sed
|
||||
/aclocal.m4
|
||||
/autom4te.cache/*
|
||||
/cache_test
|
||||
/config.*
|
||||
/config/*
|
||||
/configure
|
||||
/doc/Doxyfile
|
||||
/doc/out
|
||||
/include/zrtp_config_unix.h
|
||||
!/build/Makefile.am
|
||||
!/build/test/Makefile.am
|
||||
|
@ -5,8 +5,6 @@
|
||||
#
|
||||
# Viktor Krikun <v.krikun at zfoneproject.com>
|
||||
|
||||
libzrtp BETA
|
||||
|
||||
Created by Phil Zimmermann.
|
||||
|
||||
Developers:
|
||||
@ -28,7 +26,5 @@ Thanks to:
|
||||
Ariel Boston
|
||||
Donovan Preston
|
||||
|
||||
Software development services provided by Soft_industry http://www.soft-industry.com/en.
|
||||
|
||||
Portions of this software are available under open source licenses from other authors.
|
||||
Notably, Brian Gladman's AES implementation, and David McGrew's libSRTP package.
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
SINCE LIBZRTP v0.80 CHANGELOG IS A PART OF HTML DOCUMENTATION.
|
||||
https://developers.zfoneproject.com/libzrtp/wiki/LibzrtpChangeLog
|
||||
Check generated html or doc/manuals/changelog.dox doxygen sources
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
|
||||
|
115
libs/libzrtp/Makefile.am
Normal file
115
libs/libzrtp/Makefile.am
Normal file
@ -0,0 +1,115 @@
|
||||
#
|
||||
# Copyright (c) 2006-2007 Philip R. Zimmermann. All rights reserved.
|
||||
# Contact: http://philzimmermann.com
|
||||
#
|
||||
# Viktor Krikun <v.krikun@soft-industry.com> <v.krikun@gmail.com>
|
||||
#
|
||||
|
||||
libzrtp_includedir=$(includedir)/libzrtp
|
||||
libzrtp_include_HEADERS = \
|
||||
$(top_srcdir)/include/zrtp.h \
|
||||
$(top_srcdir)/include/zrtp_base.h \
|
||||
$(top_srcdir)/include/zrtp_config.h \
|
||||
$(top_srcdir)/include/zrtp_config_user.h \
|
||||
$(top_srcdir)/include/zrtp_config_unix.h \
|
||||
$(top_srcdir)/include/zrtp_crypto.h \
|
||||
$(top_srcdir)/include/zrtp_ec.h \
|
||||
$(top_srcdir)/include/zrtp_engine.h \
|
||||
$(top_srcdir)/include/zrtp_error.h \
|
||||
$(top_srcdir)/include/zrtp_iface.h \
|
||||
$(top_srcdir)/include/zrtp_iface_scheduler.h \
|
||||
$(top_srcdir)/include/zrtp_iface_cache.h \
|
||||
$(top_srcdir)/include/zrtp_iface_system.h \
|
||||
$(top_srcdir)/include/zrtp_legal.h \
|
||||
$(top_srcdir)/include/zrtp_list.h \
|
||||
$(top_srcdir)/include/zrtp_log.h \
|
||||
$(top_srcdir)/include/zrtp_pbx.h \
|
||||
$(top_srcdir)/include/zrtp_protocol.h \
|
||||
$(top_srcdir)/include/zrtp_srtp.h \
|
||||
$(top_srcdir)/include/zrtp_srtp_builtin.h \
|
||||
$(top_srcdir)/include/zrtp_string.h \
|
||||
$(top_srcdir)/include/zrtp_types.h \
|
||||
$(top_srcdir)/include/zrtp_version.h \
|
||||
\
|
||||
$(top_srcdir)/third_party/bnlib/bn.h \
|
||||
\
|
||||
$(top_srcdir)/third_party/bgaes/aes.h \
|
||||
$(top_srcdir)/third_party/bgaes/aesopt.h \
|
||||
$(top_srcdir)/third_party/bgaes/aestab.h \
|
||||
$(top_srcdir)/third_party/bgaes/bg2zrtp.h \
|
||||
$(top_srcdir)/third_party/bgaes/brg_types.h \
|
||||
$(top_srcdir)/third_party/bgaes/sha1.h \
|
||||
$(top_srcdir)/third_party/bgaes/sha2.h
|
||||
|
||||
lib_LIBRARIES = libzrtp.a
|
||||
|
||||
libzrtp_a_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/. \
|
||||
-I$(top_srcdir)/third_party/bgaes \
|
||||
-I$(top_srcdir)/third_party/bnlib
|
||||
|
||||
libzrtp_a_LIBADD = $(top_srcdir)/third_party/bnlib/libbn.a
|
||||
|
||||
libzrtp_a_SOURCES = $(top_srcdir)/src/zrtp.c \
|
||||
$(top_srcdir)/src/zrtp_crc.c \
|
||||
$(top_srcdir)/src/zrtp_crypto_aes.c \
|
||||
$(top_srcdir)/src/zrtp_crypto_atl.c \
|
||||
$(top_srcdir)/src/zrtp_crypto_ec.c \
|
||||
$(top_srcdir)/src/zrtp_crypto_ecdh.c \
|
||||
$(top_srcdir)/src/zrtp_crypto_hash.c \
|
||||
$(top_srcdir)/src/zrtp_crypto_pk.c \
|
||||
$(top_srcdir)/src/zrtp_crypto_sas.c \
|
||||
$(top_srcdir)/src/zrtp_datatypes.c \
|
||||
$(top_srcdir)/src/zrtp_engine.c \
|
||||
$(top_srcdir)/src/zrtp_iface_scheduler.c \
|
||||
$(top_srcdir)/src/zrtp_iface_sys.c \
|
||||
$(top_srcdir)/src/zrtp_initiator.c \
|
||||
$(top_srcdir)/src/zrtp_legal.c \
|
||||
$(top_srcdir)/src/zrtp_list.c \
|
||||
$(top_srcdir)/src/zrtp_log.c \
|
||||
$(top_srcdir)/src/zrtp_pbx.c \
|
||||
$(top_srcdir)/src/zrtp_protocol.c \
|
||||
$(top_srcdir)/src/zrtp_responder.c \
|
||||
$(top_srcdir)/src/zrtp_rng.c \
|
||||
$(top_srcdir)/src/zrtp_srtp_builtin.c \
|
||||
$(top_srcdir)/src/zrtp_string.c \
|
||||
$(top_srcdir)/src/zrtp_utils.c \
|
||||
$(top_srcdir)/src/zrtp_utils_proto.c \
|
||||
\
|
||||
$(top_srcdir)/third_party/bgaes/aes_modes.c \
|
||||
$(top_srcdir)/third_party/bgaes/aescrypt.c \
|
||||
$(top_srcdir)/third_party/bgaes/aeskey.c \
|
||||
$(top_srcdir)/third_party/bgaes/aestab.c \
|
||||
$(top_srcdir)/third_party/bgaes/sha1.c \
|
||||
$(top_srcdir)/third_party/bgaes/sha2.c\
|
||||
\
|
||||
$(top_srcdir)/src/zrtp_iface_cache.c
|
||||
$(top_srcdir)/src/zrtp_engine_driven.c
|
||||
|
||||
check_PROGRAMS = cache_test
|
||||
|
||||
cache_test_CPPFLAGS = -I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/. \
|
||||
-I$(top_srcdir)/test \
|
||||
-I$(top_srcdir)/test/cmockery \
|
||||
-I$(top_srcdir)/third_party/bgaes \
|
||||
-I$(top_srcdir)/third_party/bnlib
|
||||
|
||||
cache_test_SOURCES = $(top_srcdir)/test/cmockery/cmockery.c \
|
||||
$(top_srcdir)/test/cache_test.c
|
||||
cache_test_LDADD = libzrtp.a $(top_srcdir)/third_party/bnlib/libbn.a -lpthread
|
||||
|
||||
SUBDIRS = third_party/bnlib
|
||||
|
||||
if HAVE_DOXYGEN
|
||||
doc: .stamp-doc
|
||||
.stamp-doc:
|
||||
(cd doc && $(DOXYGEN) Doxyfile)
|
||||
touch $@
|
||||
endif
|
||||
|
||||
uninstall:
|
||||
rm -rf $(prefix)/include/libzrtp
|
||||
rm -f $(prefix)/lib/libzrtp.a
|
||||
|
@ -9,6 +9,6 @@ reconf () {
|
||||
automake --no-force --add-missing --copy
|
||||
}
|
||||
|
||||
(cd ../../third_party/bnlib && ./bootstrap.sh)
|
||||
(cd third_party/bnlib && ./bootstrap.sh)
|
||||
reconf
|
||||
|
@ -6,7 +6,7 @@
|
||||
# Viktor Krikun <v.krikun at zfoneproject.com>
|
||||
#
|
||||
|
||||
AC_INIT()
|
||||
AC_INIT([libzrtp], [1.2.0])
|
||||
|
||||
AC_CONFIG_AUX_DIR(config)
|
||||
AC_CONFIG_HEADER(config/config.h)
|
||||
@ -32,16 +32,16 @@ case $target_os in
|
||||
esac
|
||||
|
||||
|
||||
AM_INIT_AUTOMAKE([libzrtp], [1.15])
|
||||
AX_PREFIX_CONFIG_H(../../include/zrtp_config_unix.h,ZRTP,config/config.h)
|
||||
AM_INIT_AUTOMAKE
|
||||
AX_PREFIX_CONFIG_H(include/zrtp_config_unix.h,ZRTP,config/config.h)
|
||||
|
||||
CFLAGS="$CFLAGS -Wno-unused-parameter -fno-strict-aliasing -fPIC -DZRTP_AUTOMAKE=1"
|
||||
CFLAGS="$CFLAGS -std=c99 -O2 -g3 -Wall -Wextra -Wno-unused-parameter -fno-strict-aliasing -fPIC -DZRTP_AUTOMAKE=1"
|
||||
|
||||
# Configuring external libraries
|
||||
echo "========================= configuring bnlib =============================="
|
||||
cd ./../../third_party/bnlib
|
||||
cd third_party/bnlib
|
||||
./configure CFLAGS="$CFLAGS"
|
||||
cd ../../projects/gnu
|
||||
cd ../..
|
||||
echo "================================ done ==================================="
|
||||
|
||||
# Checks for programs.
|
||||
@ -49,10 +49,6 @@ AC_PROG_CC
|
||||
AC_PROG_CXX
|
||||
AC_PROG_RANLIB
|
||||
|
||||
# Apply configure options
|
||||
AC_ARG_ENABLE(enterprise, [ --enable-enterprise enable building of enterprise components).], enable_enterprise=$enableval,enable_enterprise="no")
|
||||
AM_CONDITIONAL(ZRTP_BUILD_ENTERPRISE, [test "x$enable_enterprise" = "xyes"])
|
||||
|
||||
# Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS([linux/version.h endian.h])
|
||||
@ -78,19 +74,24 @@ AC_CHECK_FUNCS([pthread_mutex_lock pthread_mutex_unlock pthread_mutex_init pthre
|
||||
AC_CHECK_FUNCS([pthread_attr_init pthread_attr_setdetachstate pthread_create])
|
||||
AC_CHECK_FUNCS([sem_wait sem_trywait sem_post sem_unlink sem_destroy sem_open sem_init])
|
||||
|
||||
AC_CHECK_LIB([pthread], [main], [LIB_PTHREAD="-lpthread"], [echo " Couldn't find library pthread";])
|
||||
AC_CHECK_LIB([pthread], [main], [LIBS="-lpthread $LIBS"], [echo " Couldn't find library pthread";])
|
||||
|
||||
# Other
|
||||
AC_DEFINE(PRAGMA_PACK_PUSH,[#pragma pack(push, 1)],[Define pragma pack(push) for your platform])
|
||||
AC_DEFINE(PRAGMA_PACK_POP,[#pragma pack(pop)],[Define pragma pack(pop) for your platform])
|
||||
AC_DEFINE(INLINE,[static inline],[Define inline construction for your platform])
|
||||
|
||||
if test "x$enable_enterprise" = "xyes" ; then
|
||||
AC_DEFINE(ENABLE_EC,1,Enterprise)
|
||||
CFLAGS="$CFLAGS -DZRTP_ENABLE_EC=1"
|
||||
#
|
||||
# Documentation
|
||||
#
|
||||
AC_CHECK_PROGS([DOXYGEN], [doxygen])
|
||||
if test -z "$DOXYGEN";
|
||||
then AC_MSG_WARN([Doxygen not found - continuing without Doxygen support])
|
||||
fi
|
||||
|
||||
AC_SUBST(ENABLE_EC)
|
||||
AM_CONDITIONAL([HAVE_DOXYGEN],
|
||||
[test -n "$DOXYGEN"])AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])
|
||||
|
||||
#
|
||||
# Genearte Makefiles
|
||||
AC_OUTPUT([Makefile build/Makefile build/test/Makefile])
|
||||
AC_OUTPUT([Makefile])
|
@ -7,5 +7,3 @@ mkdir libzrtp-doc
|
||||
cp -Rf ./out/html/* ./libzrtp-doc
|
||||
tar -zcvf ./libzrtp-doc.tar.gz ./libzrtp-doc >> /dev/null
|
||||
rm -rf libzrtp-doc
|
||||
mv libzrtp-doc.tar.gz ../projects/gnu
|
||||
cd ../projects/gnu
|
File diff suppressed because it is too large
Load Diff
@ -1,451 +0,0 @@
|
||||
BODY,H1,H2,H3,H4,H5,H6,P,CENTER,TD,TH,UL,DL,DIV {
|
||||
font-family: Geneva, Arial, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
BODY,TD {
|
||||
font-size: 100%;
|
||||
}
|
||||
|
||||
CODE {
|
||||
font-size: 120%;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.fragment, pre {
|
||||
font-size: 110%;
|
||||
font-family: monospace;
|
||||
}
|
||||
H1 {
|
||||
text-align: center;
|
||||
font-size: 240%;
|
||||
}
|
||||
H2 {
|
||||
font-size: 180%;
|
||||
margin-top: 60px;
|
||||
}
|
||||
H3 {
|
||||
font-size: 140%;
|
||||
}
|
||||
H4 {
|
||||
font-size: 120%;
|
||||
}
|
||||
|
||||
caption {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
div.qindex, div.navtab{
|
||||
background-color: #e8eef2;
|
||||
border: 1px solid #84b0c7;
|
||||
text-align: center;
|
||||
margin: 2px;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
div.qindex, div.navpath {
|
||||
width: 100%;
|
||||
line-height: 140%;
|
||||
}
|
||||
|
||||
div.navtab {
|
||||
margin-right: 15px;
|
||||
}
|
||||
|
||||
/* @group Link Styling */
|
||||
|
||||
a {
|
||||
color: #153788;
|
||||
font-weight: normal;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.contents a:visited {
|
||||
color: #1b77c5;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a.qindex {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
a.qindexHL {
|
||||
font-weight: bold;
|
||||
background-color: #6666cc;
|
||||
color: #ffffff;
|
||||
border: 1px double #9295C2;
|
||||
}
|
||||
|
||||
.contents a.qindexHL:visited {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
a.el {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
a.elRef {
|
||||
}
|
||||
|
||||
a.code {
|
||||
}
|
||||
|
||||
a.codeRef {
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
dl.el {
|
||||
margin-left: -1cm;
|
||||
}
|
||||
|
||||
.fragment {
|
||||
font-family: monospace, fixed;
|
||||
font-size: 105%;
|
||||
}
|
||||
|
||||
pre.fragment {
|
||||
border: 1px solid #CCCCCC;
|
||||
background-color: #f5f5f5;
|
||||
padding: 4px 6px;
|
||||
margin: 4px 8px 4px 2px;
|
||||
}
|
||||
|
||||
div.ah {
|
||||
background-color: black;
|
||||
font-weight: bold;
|
||||
color: #ffffff;
|
||||
margin-bottom: 3px;
|
||||
margin-top: 3px
|
||||
}
|
||||
|
||||
div.groupHeader {
|
||||
margin-left: 16px;
|
||||
margin-top: 12px;
|
||||
margin-bottom: 6px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
div.groupText {
|
||||
margin-left: 16px;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
body {
|
||||
background: white;
|
||||
color: black;
|
||||
margin-right: 20px;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
td.indexkey {
|
||||
background-color: #e8eef2;
|
||||
font-weight: bold;
|
||||
border: 1px solid #CCCCCC;
|
||||
margin: 2px 0px 2px 0;
|
||||
padding: 2px 10px;
|
||||
}
|
||||
|
||||
td.indexvalue {
|
||||
background-color: #e8eef2;
|
||||
border: 1px solid #CCCCCC;
|
||||
padding: 2px 10px;
|
||||
margin: 2px 0px;
|
||||
}
|
||||
|
||||
tr.memlist {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
p.formulaDsp {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
img.formulaDsp {
|
||||
|
||||
}
|
||||
|
||||
img.formulaInl {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* @group Code Colorization */
|
||||
|
||||
span.keyword {
|
||||
color: #008000
|
||||
}
|
||||
|
||||
span.keywordtype {
|
||||
color: #604020
|
||||
}
|
||||
|
||||
span.keywordflow {
|
||||
color: #e08000
|
||||
}
|
||||
|
||||
span.comment {
|
||||
color: #800000
|
||||
}
|
||||
|
||||
span.preprocessor {
|
||||
color: #806020
|
||||
}
|
||||
|
||||
span.stringliteral {
|
||||
color: #002080
|
||||
}
|
||||
|
||||
span.charliteral {
|
||||
color: #008080
|
||||
}
|
||||
|
||||
span.vhdldigit {
|
||||
color: #ff00ff
|
||||
}
|
||||
|
||||
span.vhdlchar {
|
||||
color: #000000
|
||||
}
|
||||
|
||||
span.vhdlkeyword {
|
||||
color: #700070
|
||||
}
|
||||
|
||||
span.vhdllogic {
|
||||
color: #ff0000
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
.search {
|
||||
color: #003399;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
form.search {
|
||||
margin-bottom: 0px;
|
||||
margin-top: 0px;
|
||||
}
|
||||
|
||||
input.search {
|
||||
font-size: 75%;
|
||||
color: #000080;
|
||||
font-weight: normal;
|
||||
background-color: #e8eef2;
|
||||
}
|
||||
|
||||
td.tiny {
|
||||
font-size: 75%;
|
||||
}
|
||||
|
||||
.dirtab {
|
||||
padding: 4px;
|
||||
border-collapse: collapse;
|
||||
border: 1px solid #84b0c7;
|
||||
}
|
||||
|
||||
th.dirtab {
|
||||
background: #e8eef2;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
hr {
|
||||
height: 0;
|
||||
border: none;
|
||||
border-top: 1px solid #666;
|
||||
}
|
||||
|
||||
/* @group Member Descriptions */
|
||||
|
||||
.mdescLeft, .mdescRight,
|
||||
.memItemLeft, .memItemRight,
|
||||
.memTemplItemLeft, .memTemplItemRight, .memTemplParams {
|
||||
background-color: #FAFAFA;
|
||||
border: none;
|
||||
margin: 4px;
|
||||
padding: 1px 0 0 8px;
|
||||
}
|
||||
|
||||
.mdescLeft, .mdescRight {
|
||||
padding: 0px 8px 4px 8px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.memItemLeft, .memItemRight, .memTemplParams {
|
||||
border-top: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.memTemplParams {
|
||||
color: #606060;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
/* @group Member Details */
|
||||
|
||||
/* Styles for detailed member documentation */
|
||||
|
||||
.memtemplate {
|
||||
font-size: 80%;
|
||||
color: #606060;
|
||||
font-weight: normal;
|
||||
margin-left: 3px;
|
||||
}
|
||||
|
||||
.memnav {
|
||||
background-color: #e8eef2;
|
||||
border: 1px solid #84b0c7;
|
||||
text-align: center;
|
||||
margin: 2px;
|
||||
margin-right: 15px;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.memitem {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.memname {
|
||||
white-space: nowrap;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.memproto, .memdoc {
|
||||
border: 1px solid #84b0c7;
|
||||
}
|
||||
|
||||
.memproto {
|
||||
padding: 0;
|
||||
background-color: #d5e1e8;
|
||||
font-weight: bold;
|
||||
-webkit-border-top-left-radius: 8px;
|
||||
-webkit-border-top-right-radius: 8px;
|
||||
-moz-border-radius-topleft: 8px;
|
||||
-moz-border-radius-topright: 8px;
|
||||
}
|
||||
|
||||
.memdoc {
|
||||
padding: 2px 5px;
|
||||
background-color: #eef3f5;
|
||||
border-top-width: 0;
|
||||
-webkit-border-bottom-left-radius: 8px;
|
||||
-webkit-border-bottom-right-radius: 8px;
|
||||
-moz-border-radius-bottomleft: 8px;
|
||||
-moz-border-radius-bottomright: 8px;
|
||||
}
|
||||
|
||||
.paramkey {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.paramtype {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.paramname {
|
||||
color: #602020;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.paramname em {
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
/* @group Directory (tree) */
|
||||
|
||||
/* for the tree view */
|
||||
|
||||
.ftvtree {
|
||||
font-family: sans-serif;
|
||||
margin: 0.5em;
|
||||
}
|
||||
|
||||
/* these are for tree view when used as main index */
|
||||
|
||||
.directory {
|
||||
font-size: 9pt;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.directory h3 {
|
||||
margin: 0px;
|
||||
margin-top: 1em;
|
||||
font-size: 11pt;
|
||||
}
|
||||
|
||||
/*
|
||||
The following two styles can be used to replace the root node title
|
||||
with an image of your choice. Simply uncomment the next two styles,
|
||||
specify the name of your image and be sure to set 'height' to the
|
||||
proper pixel height of your image.
|
||||
*/
|
||||
|
||||
/*
|
||||
.directory h3.swap {
|
||||
height: 61px;
|
||||
background-repeat: no-repeat;
|
||||
background-image: url("yourimage.gif");
|
||||
}
|
||||
.directory h3.swap span {
|
||||
display: none;
|
||||
}
|
||||
*/
|
||||
|
||||
.directory > h3 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.directory p {
|
||||
margin: 0px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.directory div {
|
||||
display: none;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.directory img {
|
||||
vertical-align: -30%;
|
||||
}
|
||||
|
||||
/* these are for tree view when not used as main index */
|
||||
|
||||
.directory-alt {
|
||||
font-size: 100%;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.directory-alt h3 {
|
||||
margin: 0px;
|
||||
margin-top: 1em;
|
||||
font-size: 11pt;
|
||||
}
|
||||
|
||||
.directory-alt > h3 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.directory-alt p {
|
||||
margin: 0px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.directory-alt div {
|
||||
display: none;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.directory-alt img {
|
||||
vertical-align: -30%;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
address {
|
||||
font-style: normal;
|
||||
color: #333;
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
<hr size="1"><address style="text-align: right;"><small>
|
||||
Generated on $datetime for $projectname <a href="http://www.zfoneproject.com"><img src="zfone.jpg" alt="zfone" align="middle" border="0"></a> </small></address>
|
||||
</body>
|
||||
</html>
|
@ -1,6 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<title>$title</title>
|
||||
<link href="$relpath$tabs.css" rel="stylesheet" type="text/css">
|
||||
<link href="$relpath$doxygen.css" rel="stylesheet" type="text/css">
|
||||
</head><body>
|
@ -11,7 +11,32 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\page changelog libzrtp ChangeLog
|
||||
\page changelog ChangeLog
|
||||
|
||||
****************************************************************************************************
|
||||
\section v120 libzrtp v1.20 build XXX (ZRTP RFC 6189, protocol 1.1)
|
||||
****************************************************************************************************
|
||||
|
||||
<b>This release is focused</b> on better ZRTP cache management.
|
||||
|
||||
***\subsection v120_changes API changes and Upgrade Instructions:
|
||||
*- Starting from v120 libzrtp uses global ZID for all outgoing connections. Local ZID should be
|
||||
specified in zrtp_global_t#zid and provided to zrtp_init(). App doesn't need to pass local ZID
|
||||
each time it creates new session via zrtp_session_init().
|
||||
*- Added zrtp_randstr2() which allow to generate random string before libzrtp being initialized.
|
||||
Can be handy to generate initial ZID. In normal circumstances, use zrtp_randstr() whenever possible.
|
||||
*- ZRTP cache API was completely redesigned. Look at zrtp_cache.h for more details.
|
||||
|
||||
|
||||
***\subsection v120_feature New features and improvements.
|
||||
*- new better cache management API.
|
||||
|
||||
***\subsection v120_bugs Bug fixes
|
||||
*- fixed bug when ZRTP forces enrolled endpoints to re-render SAS when sashash is empty.
|
||||
*- other minor bug fixes and improvements
|
||||
*- fixed bug when zrtp_signaling_hash_set() silently not accepted imported zrtp-hash-value with
|
||||
"buffer too small" debug output.
|
||||
|
||||
|
||||
****************************************************************************************************
|
||||
\section v091 DEVELOPERS BUILD Release Notes - libzrtp - Version 0.91 build XXX (ZRTP ID v16x, protocol 1.X)
|
||||
@ -194,4 +219,5 @@ Minor improvements. Zfone and libZRTP projects moved to public bug-tracking and
|
||||
|
||||
*- [LZRTP-132] <b>Replace HMAC with KDF function call.</b>\n
|
||||
Since ZRTP draft 12b defines ZRTP KDF to be in compliance with the recommendations in NIST SP 800-108. KDF function implemented as _zrtp_kdf() in zrtp_utils_proto.c. All KDF operations were replaced with from hmac to kdf function.
|
||||
|
||||
*/
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 8.3 KiB |
@ -35,9 +35,7 @@
|
||||
#include "zrtp_legal.h"
|
||||
#include "zrtp_version.h"
|
||||
#include "zrtp_iface_cache.h"
|
||||
#if (defined(ZRTP_ENABLE_EC) && (ZRTP_ENABLE_EC == 1))
|
||||
#include "zrtp_ec.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@ -82,6 +80,9 @@
|
||||
* \ingroup zrtp_main_init
|
||||
*/
|
||||
|
||||
/** Length of "zrtp-hash-value", RFC 6189 sec 8. @sa zrtp_signaling_hash_get(); */
|
||||
#define ZRTP_SIGN_ZRTP_HASH_LENGTH (ZRTP_MESSAGE_HASH_SIZE*2)
|
||||
|
||||
/**
|
||||
* \brief Enumeration for ZRTP Licensing modes
|
||||
* \ingroup zrtp_main_init
|
||||
@ -161,13 +162,24 @@ typedef struct zrtp_config_t
|
||||
|
||||
/** @brief Path to zrtp cache file (set if you use built-in realization) */
|
||||
zrtp_string256_t def_cache_path;
|
||||
|
||||
/**
|
||||
* @brief Flush the cache automatically
|
||||
* Set to 1 if you want libzrtp to flush the cache to the persistent storage
|
||||
* right after it is modified. If cache_auto_store is 0, libzrtp will flush
|
||||
* the cache on going down only and the app is responsible for storing the
|
||||
* cache in unexpected situations. Enabled by default.
|
||||
*
|
||||
* @sa zrtp_def_cache_store()
|
||||
*/
|
||||
unsigned cache_auto_store;
|
||||
} zrtp_config_t;
|
||||
|
||||
/**
|
||||
* \brief zrtp stream information structure
|
||||
* \ingroup zrtp_main_management
|
||||
*
|
||||
* libzrtp, since v0.80 takes data incapsulating approach and hides all private date inside
|
||||
* libzrtp, since v0.80 takes data encapsulating approach and hides all private data inside
|
||||
* zrtp_stream_t structure. Developers shouldn't access them directly. \ref zrtp_stream_get() should
|
||||
* be used instead to fill zrtp_stream_info_t structure. zrtp_stream_info_t contains all needed
|
||||
* information in safe and easy to use form.
|
||||
@ -787,7 +799,7 @@ zrtp_status_t zrtp_process_srtcp( zrtp_stream_t *stream,
|
||||
*
|
||||
* \param stream - stream for operating with;
|
||||
* \param hash_buff - signaling hash buffer. Function accepts string, not a binary value!;
|
||||
* \param hash_buff_length - signaling hash length in bytes (must be 64 bytes);
|
||||
* \param hash_buff_length - signaling hash length in bytes, must be ZRTP_SIGN_ZRTP_HASH_LENGTH bytes;
|
||||
* \return:
|
||||
* - zrtp_status_ok if the operation finished successfully
|
||||
* - one of the errors otherwise
|
||||
@ -808,8 +820,8 @@ zrtp_status_t zrtp_signaling_hash_set( zrtp_stream_t* stream,
|
||||
*
|
||||
* \param stream - stream for operating with
|
||||
* \param hash_buff - buffer for storing signaling hash. Function returns already parsed hex string.
|
||||
* String is null-terminated.
|
||||
* \param hash_buff_length - buffer length in bytes (not shorter than 65 bytes)
|
||||
* String is null-terminated. Buffer must be at least ZRTP_SIGN_ZRTP_HASH_LENGTH bytes length.
|
||||
* \param hash_buff_length - buffer length in bytes, non less than ZRTP_SIGN_ZRTP_HASH_LENGTH bytes.
|
||||
* \return:
|
||||
* - zrtp_status_ok if the operation finished successfully
|
||||
* - one of the errors otherwise
|
||||
@ -817,9 +829,9 @@ zrtp_status_t zrtp_signaling_hash_set( zrtp_stream_t* stream,
|
||||
* - ZRTP RFC. sec 8;
|
||||
* - zrtp_signaling_hash_set()
|
||||
*/
|
||||
zrtp_status_t zrtp_signaling_hash_get( zrtp_stream_t* stream,
|
||||
char* hash_buff,
|
||||
uint32_t hash_buff_length);
|
||||
zrtp_status_t zrtp_signaling_hash_get(zrtp_stream_t* stream,
|
||||
char* hash_buff,
|
||||
uint32_t hash_buff_length);
|
||||
|
||||
/**
|
||||
* \brief Changing the value of the secret's verification flag
|
||||
@ -945,6 +957,8 @@ int zrtp_entropy_add(zrtp_global_t* zrtp, const unsigned char *buffer, uint32_t
|
||||
*/
|
||||
int zrtp_randstr(zrtp_global_t* zrtp, unsigned char *buffer, uint32_t length);
|
||||
|
||||
int zrtp_randstr2(unsigned char *buffer, uint32_t length);
|
||||
|
||||
/* \} */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
@ -94,8 +94,6 @@
|
||||
#define ZRTP_USE_BUILTIN_SCEHDULER 1
|
||||
#undef ZRTP_USE_STACK_MINIM
|
||||
#define ZRTP_USE_STACK_MINIM 1
|
||||
#undef ZRTP_ENABLE_EC
|
||||
#define ZRTP_ENABLE_EC 0
|
||||
#define ALIGNMENT_32BIT_REQUIRED
|
||||
|
||||
#endif /* ZRTP_WIN_CONFIG_H__ */
|
||||
|
@ -122,10 +122,6 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ZRTP_ENABLE_EC
|
||||
#define ZRTP_ENABLE_EC 0
|
||||
#endif
|
||||
|
||||
#ifndef ZRTP_DEBUG_WITH_PJSIP
|
||||
#define ZRTP_DEBUG_WITH_PJSIP 0
|
||||
#endif
|
||||
|
@ -15,10 +15,7 @@
|
||||
#include "zrtp_error.h"
|
||||
#include "zrtp_engine.h"
|
||||
#include "zrtp_config_user.h"
|
||||
|
||||
#if (defined(ZRTP_ENABLE_EC) && (ZRTP_ENABLE_EC == 1))
|
||||
#include "zrtp_ec.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
81
libs/libzrtp/include/zrtp_ec.h
Normal file
81
libs/libzrtp/include/zrtp_ec.h
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*/
|
||||
|
||||
#ifndef __ZRTP_CRYPTO_EC_H__
|
||||
#define __ZRTP_CRYPTO_EC_H__
|
||||
|
||||
#include "bn.h"
|
||||
|
||||
#include "zrtp_config.h"
|
||||
#include "zrtp_types.h"
|
||||
#include "zrtp_error.h"
|
||||
|
||||
#define ZRTP_MAXECBITS 521
|
||||
#define ZRTP_MAXECWORDS ((ZRTP_MAXECBITS+7)/8)
|
||||
|
||||
typedef struct zrtp_ec_params
|
||||
{
|
||||
unsigned ec_bits; /* # EC bits: 256, 384, 521 */
|
||||
uint8_t P_data[ZRTP_MAXECWORDS]; /* curve field prime */
|
||||
uint8_t n_data[ZRTP_MAXECWORDS]; /* curve order (# points) */
|
||||
uint8_t b_data[ZRTP_MAXECWORDS]; /* curve param, y^3 = x^2 -3x + b */
|
||||
uint8_t Gx_data[ZRTP_MAXECWORDS]; /* curve point, x coordinate */
|
||||
uint8_t Gy_data[ZRTP_MAXECWORDS]; /* curve point, y coordinate */
|
||||
} zrtp_ec_params_t;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*============================================================================*/
|
||||
/* Elliptic Curve library */
|
||||
/*============================================================================*/
|
||||
|
||||
int zrtp_ecAdd ( struct BigNum *rsltx,
|
||||
struct BigNum *rslty,
|
||||
struct BigNum *p1x,
|
||||
struct BigNum *p1y,
|
||||
struct BigNum *p2x,
|
||||
struct BigNum *p2y,
|
||||
struct BigNum *mod);
|
||||
|
||||
int zrtp_ecMul ( struct BigNum *rsltx,
|
||||
struct BigNum *rslty,
|
||||
struct BigNum *mult,
|
||||
struct BigNum *basex,
|
||||
struct BigNum *basey,
|
||||
struct BigNum *mod);
|
||||
|
||||
zrtp_status_t zrtp_ec_random_point( zrtp_global_t *zrtp,
|
||||
struct BigNum *P,
|
||||
struct BigNum *n,
|
||||
struct BigNum *Gx,
|
||||
struct BigNum *Gy,
|
||||
struct BigNum *pkx,
|
||||
struct BigNum *pky,
|
||||
struct BigNum *sv,
|
||||
uint8_t *test_sv_data,
|
||||
size_t test_sv_data_len);
|
||||
|
||||
extern zrtp_status_t zrtp_ec_init_params(struct zrtp_ec_params *params, uint32_t bits );
|
||||
|
||||
|
||||
/* Useful bignum utility functions not defined in bignum library */
|
||||
int bnAddMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *mod);
|
||||
int bnAddQMod_ (struct BigNum *rslt, unsigned n1, struct BigNum *mod);
|
||||
int bnSubMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *mod);
|
||||
int bnSubQMod_ (struct BigNum *rslt, unsigned n1, struct BigNum *mod);
|
||||
int bnMulMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *n2, struct BigNum *mod);
|
||||
int bnMulQMod_ (struct BigNum *rslt, struct BigNum *n1, unsigned n2, struct BigNum *mod);
|
||||
int bnSquareMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *mod);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ZRTP_CRYPTO_EC_H__ */
|
@ -11,7 +11,6 @@
|
||||
#define __ZRTP_STRING_H__
|
||||
|
||||
#include "zrtp_config.h"
|
||||
#include "zrtp_types.h"
|
||||
|
||||
/**
|
||||
* \file zrtp_strings.h
|
||||
|
@ -344,29 +344,15 @@ typedef enum zrtp_statemachine_type_t
|
||||
*/
|
||||
struct zrtp_global_t
|
||||
{
|
||||
/** ZRTP license mode. */
|
||||
uint32_t lic_mode;
|
||||
|
||||
/** Local ZRTP client ID. */
|
||||
zrtp_string16_t client_id;
|
||||
|
||||
/** Flags defines that the local endpoint acts as ZRTP MiTM. */
|
||||
uint8_t is_mitm;
|
||||
|
||||
/** Hash context for entropy accumulation for the RNG unit. */
|
||||
MD_CTX rand_ctx;
|
||||
|
||||
/** RNG unit initialization flag. */
|
||||
uint8_t rand_initialized;
|
||||
|
||||
/** Full path to ZRTP cache file. */
|
||||
zrtp_string256_t def_cache_path;
|
||||
|
||||
/** This object is used to protect the shared RNG hash zrtp#rand_ctx */
|
||||
zrtp_mutex_t* rng_protector;
|
||||
|
||||
/** This section provides static data for DH3K and DH4K components */
|
||||
struct BigNum one;
|
||||
uint32_t lic_mode; /** ZRTP license mode. */
|
||||
zrtp_string16_t client_id; /** Local ZRTP client ID. */
|
||||
uint8_t is_mitm; /** Flags defines that the local endpoint acts as ZRTP MiTM. */
|
||||
MD_CTX rand_ctx; /** Hash context for entropy accumulation for the RNG unit. */
|
||||
uint8_t rand_initialized; /** RNG unit initialization flag. */
|
||||
zrtp_string256_t def_cache_path; /** Full path to ZRTP cache file. */
|
||||
unsigned cache_auto_store; /** Set when user wants libzrtp to flush the cache once it changed */
|
||||
zrtp_mutex_t* rng_protector; /** This object is used to protect the shared RNG hash zrtp#rand_ctx */
|
||||
struct BigNum one; /** This section provides static data for DH3K and DH4K components */
|
||||
struct BigNum G;
|
||||
struct BigNum P_2048;
|
||||
struct BigNum P_2048_1;
|
||||
@ -374,39 +360,17 @@ struct zrtp_global_t
|
||||
struct BigNum P_3072_1;
|
||||
uint8_t P_2048_data[256];
|
||||
uint8_t P_3072_data[384];
|
||||
|
||||
/** Head of hash components list */
|
||||
mlist_t hash_head;
|
||||
|
||||
/** Head of ciphers list */
|
||||
mlist_t cipher_head;
|
||||
|
||||
/** Head of ATL components list */
|
||||
mlist_t atl_head;
|
||||
|
||||
/** Head of public key exchange schemes list */
|
||||
mlist_t pktype_head;
|
||||
|
||||
/** SAS schemes list */
|
||||
mlist_t sas_head;
|
||||
|
||||
/** Storage for some SRTP global data */
|
||||
void* srtp_global;
|
||||
|
||||
/** Head of ZRTP sessions list */
|
||||
mlist_t sessions_head;
|
||||
|
||||
/** Global sessions count used to create ZRTP session IDs. For debug purposes mostly. */
|
||||
uint32_t sessions_count;
|
||||
|
||||
/** Global streams count used to create ZRTP session IDs. For debug purposes mostly. */
|
||||
uint32_t streams_count;
|
||||
|
||||
/** This object is used to synchronize sessions list operations */
|
||||
zrtp_mutex_t* sessions_protector;
|
||||
|
||||
/** Set of feedback callbacks used by libzrtp to interact with the user-space.*/
|
||||
zrtp_callback_t cb;
|
||||
mlist_t hash_head; /** Head of hash components list */
|
||||
mlist_t cipher_head; /** Head of ciphers list */
|
||||
mlist_t atl_head; /** Head of ATL components list */
|
||||
mlist_t pktype_head; /** Head of public key exchange schemes list */
|
||||
mlist_t sas_head; /** SAS schemes list */
|
||||
void* srtp_global; /** Storage for some SRTP global data */
|
||||
mlist_t sessions_head; /** Head of ZRTP sessions list */
|
||||
uint32_t sessions_count; /** Global sessions count used to create ZRTP session IDs. For debug purposes mostly. */
|
||||
uint32_t streams_count; /** Global streams count used to create ZRTP session IDs. For debug purposes mostly. */
|
||||
zrtp_mutex_t* sessions_protector; /** This object is used to synchronize sessions list operations */
|
||||
zrtp_callback_t cb; /** Set of feedback callbacks used by libzrtp to interact with the user-space.*/
|
||||
};
|
||||
|
||||
|
||||
|
@ -12,8 +12,8 @@
|
||||
|
||||
#define LIBZRTP_VERSION_MAJOR 1
|
||||
|
||||
#define LIBZRTP_VERSION_MINOR 15
|
||||
#define LIBZRTP_VERSION_BUILD 607
|
||||
#define LIBZRTP_VERSION_STR "v1.15 607"
|
||||
#define LIBZRTP_VERSION_MINOR 20
|
||||
#define LIBZRTP_VERSION_BUILD 616
|
||||
#define LIBZRTP_VERSION_STR "v1.20 616"
|
||||
|
||||
#endif /*__ZRTP_VERSION_H__*/
|
||||
|
10
libs/libzrtp/projects/gnu/.gitignore
vendored
10
libs/libzrtp/projects/gnu/.gitignore
vendored
@ -1,10 +0,0 @@
|
||||
# -*- mode:conf -*-
|
||||
/Makefile
|
||||
/Makefile.in
|
||||
/_configs.sed
|
||||
/build/Makefile
|
||||
/build/Makefile.in
|
||||
/build/test/Makefile
|
||||
/build/test/Makefile.in
|
||||
/config/config.h
|
||||
/config/stamp-h1
|
@ -1,30 +0,0 @@
|
||||
libzrtp betta
|
||||
Copyright (c) 2005-2008 Philip Zimmermann. All rights reserved.
|
||||
Contact Phil at: www.philzimmermann.com
|
||||
Visit the Zfone Project Home Page http://zfoneproject.com/
|
||||
Report bugs via the Zfone Bugs Page http://zfoneproject.com/bugs.html
|
||||
|
||||
Created by Phil Zimmermann.
|
||||
|
||||
Developers:
|
||||
Viktor Krikun <v.krikun@soft-industry.com> <v.krikun@gmail.com>
|
||||
Nikolay Popok
|
||||
Vitaly Rozhkov
|
||||
Andrey Rozinko
|
||||
Bryce Wilcox-O'Hearn
|
||||
|
||||
Thanks to:
|
||||
Alan Johnston
|
||||
Jon Callas
|
||||
Hal Finney
|
||||
Colin Plumb
|
||||
Sagar Pai
|
||||
Werner Dittmann
|
||||
L. Amber Wilcox-O'Hearn
|
||||
Ariel Boston
|
||||
Donovan Preston
|
||||
|
||||
Software development services provided by Svitla Systems and http://www.soft-industry.com/en.
|
||||
|
||||
Portions of this software are available under open source licenses from other authors.
|
||||
Notably, Brian Gladman's AES implementation, and David McGrew's libSRTP package.
|
@ -1 +0,0 @@
|
||||
Change Log is available at [https://developers.zfoneproject.com/libzrtp/wiki/LibzrtpChangeLog]
|
@ -1,57 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2006-2007 Philip R. Zimmermann. All rights reserved.
|
||||
# Contact: http://philzimmermann.com
|
||||
#
|
||||
# Viktor Krikun <v.krikun@soft-industry.com> <v.krikun@gmail.com>
|
||||
#
|
||||
|
||||
TEST_DIR=$(top_srcdir)/../../test
|
||||
TOP_SRCDIR=$(top_srcdir)/../../include
|
||||
THIRD_DIR=$(top_srcdir)/../../third_party
|
||||
|
||||
libzrtp_includedir=$(includedir)/libzrtp
|
||||
|
||||
libzrtp_include_HEADERS = \
|
||||
$(TOP_SRCDIR)/zrtp.h \
|
||||
$(TOP_SRCDIR)/zrtp_base.h \
|
||||
$(TOP_SRCDIR)/zrtp_config.h \
|
||||
$(TOP_SRCDIR)/zrtp_config_user.h \
|
||||
$(TOP_SRCDIR)/zrtp_config_unix.h \
|
||||
$(TOP_SRCDIR)/zrtp_crypto.h \
|
||||
$(TOP_SRCDIR)/zrtp_engine.h \
|
||||
$(TOP_SRCDIR)/zrtp_error.h \
|
||||
$(TOP_SRCDIR)/zrtp_iface.h \
|
||||
$(TOP_SRCDIR)/zrtp_iface_scheduler.h \
|
||||
$(TOP_SRCDIR)/zrtp_iface_cache.h \
|
||||
$(TOP_SRCDIR)/zrtp_iface_system.h \
|
||||
$(TOP_SRCDIR)/zrtp_legal.h \
|
||||
$(TOP_SRCDIR)/zrtp_list.h \
|
||||
$(TOP_SRCDIR)/zrtp_log.h \
|
||||
$(TOP_SRCDIR)/zrtp_pbx.h \
|
||||
$(TOP_SRCDIR)/zrtp_protocol.h \
|
||||
$(TOP_SRCDIR)/zrtp_srtp.h \
|
||||
$(TOP_SRCDIR)/zrtp_srtp_builtin.h \
|
||||
$(TOP_SRCDIR)/zrtp_string.h \
|
||||
$(TOP_SRCDIR)/zrtp_types.h \
|
||||
$(TOP_SRCDIR)/zrtp_version.h \
|
||||
\
|
||||
$(THIRD_DIR)/bnlib/bn.h \
|
||||
\
|
||||
$(THIRD_DIR)/bgaes/aes.h \
|
||||
$(THIRD_DIR)/bgaes/aesopt.h \
|
||||
$(THIRD_DIR)/bgaes/aestab.h \
|
||||
$(THIRD_DIR)/bgaes/bg2zrtp.h \
|
||||
$(THIRD_DIR)/bgaes/brg_types.h \
|
||||
$(THIRD_DIR)/bgaes/sha1.h \
|
||||
$(THIRD_DIR)/bgaes/sha2.h
|
||||
|
||||
if ZRTP_BUILD_ENTERPRISE
|
||||
libzrtp_include_HEADERS += $(TOP_SRCDIR)/zrtp_ec.h
|
||||
endif
|
||||
|
||||
SUBDIRS = ../../third_party/bnlib
|
||||
SUBDIRS += build
|
||||
|
||||
uninstall:
|
||||
rm -rf $(prefix)/include/libzrtp
|
||||
rm -f $(prefix)/lib/libzrtp.a
|
@ -1,56 +0,0 @@
|
||||
#
|
||||
# Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
# Contact: http://philzimmermann.com
|
||||
#
|
||||
# Viktor Krikun <v.krikun@soft-industry.com> <v.krikun@gmail.com>
|
||||
#
|
||||
|
||||
TOP_SRCDIR=$(top_srcdir)/../..
|
||||
INCLUDES = -I$(TOP_SRCDIR)/include \
|
||||
-I$(TOP_SRCDIR)/. \
|
||||
-I$(TOP_SRCDIR)/third_party/bgaes \
|
||||
-I$(TOP_SRCDIR)/third_party/bnlib
|
||||
|
||||
lib_LIBRARIES = libzrtp.a
|
||||
|
||||
libzrtp_a_LIBADD = $(TOP_SRCDIR)/third_party/bnlib/libbn.a
|
||||
|
||||
libzrtp_a_SOURCES = $(TOP_SRCDIR)/src/zrtp.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_crc.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_crypto_aes.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_crypto_atl.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_crypto_hash.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_crypto_pk.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_crypto_sas.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_datatypes.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_engine.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_iface_scheduler.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_iface_sys.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_initiator.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_legal.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_list.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_log.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_pbx.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_protocol.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_responder.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_rng.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_srtp_builtin.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_string.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_utils.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_utils_proto.c \
|
||||
\
|
||||
$(TOP_SRCDIR)/third_party/bgaes/aes_modes.c \
|
||||
$(TOP_SRCDIR)/third_party/bgaes/aescrypt.c \
|
||||
$(TOP_SRCDIR)/third_party/bgaes/aeskey.c \
|
||||
$(TOP_SRCDIR)/third_party/bgaes/aestab.c \
|
||||
$(TOP_SRCDIR)/third_party/bgaes/sha1.c \
|
||||
$(TOP_SRCDIR)/third_party/bgaes/sha2.c\
|
||||
\
|
||||
$(TOP_SRCDIR)/src/zrtp_iface_cache.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_engine_driven.c
|
||||
if ZRTP_BUILD_ENTERPRISE
|
||||
libzrtp_a_SOURCES +=$(TOP_SRCDIR)/src/zrtp_crypto_ec.c \
|
||||
$(TOP_SRCDIR)/src/zrtp_crypto_ecdh.c
|
||||
endif
|
||||
|
||||
SUBDIRS = test
|
@ -1,57 +0,0 @@
|
||||
|
||||
# Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
# Contact: http://philzimmermann.com
|
||||
#
|
||||
# Viktor Krikun <v.krikun@soft-industry.com> <v.krikun@gmail.com>
|
||||
#
|
||||
|
||||
|
||||
|
||||
TOP_SRCDIR=$(top_srcdir)/../..
|
||||
INCLUDES = -I$(TOP_SRCDIR)/include \
|
||||
-I$(TOP_SRCDIR)/include/enterprise \
|
||||
-I$(TOP_SRCDIR)/. \
|
||||
-I$(TOP_SRCDIR)/test \
|
||||
-I$(TOP_SRCDIR)/test/cmockery \
|
||||
-I$(TOP_SRCDIR)/third_party/bgaes \
|
||||
-I$(TOP_SRCDIR)/third_party/bnlib
|
||||
|
||||
|
||||
#check_PROGRAMS = cache_test libzrtp_test
|
||||
check_PROGRAMS = cache_test
|
||||
|
||||
### ZRTP Cache testing
|
||||
|
||||
cache_test_SOURCES = $(TOP_SRCDIR)/test/cmockery/cmockery.c \
|
||||
$(TOP_SRCDIR)/test/cache_test.c
|
||||
cache_test_LDADD = ../libzrtp.a $(TOP_SRCDIR)/third_party/bnlib/libbn.a -lpthread
|
||||
|
||||
|
||||
### ZRTP high-level test-case
|
||||
|
||||
libzrtp_test_SOURCES = $(TOP_SRCDIR)/test/pc/zrtp_test_core.c \
|
||||
$(TOP_SRCDIR)/test/pc/zrtp_test_crypto.c \
|
||||
$(TOP_SRCDIR)/test/pc/zrtp_test_queue.c \
|
||||
$(TOP_SRCDIR)/test/pc/zrtp_test_ui.c
|
||||
|
||||
libzrtp_test_LDADD = ../libzrtp.a $(TOP_SRCDIR)/third_party/bnlib/libbn.a -lpthread
|
||||
|
||||
SUBDIRS = .
|
||||
|
||||
check:
|
||||
# @ ./cache_test
|
||||
|
||||
# check:
|
||||
# @echo ""
|
||||
# @echo "*========================================================================*"
|
||||
# @echo "* starting libZRTP tests *"
|
||||
# @echo "*========================================================================*"
|
||||
# @echo ""
|
||||
# @./libzrtp_test
|
||||
#
|
||||
# @echo ""
|
||||
# @echo "*========================================================================*"
|
||||
# @echo "* In case you have a test FAILED send the generated log file *"
|
||||
# @echo "* with your comment to <zrtp_support@zfoneproject.com>. *"
|
||||
# @echo "*========================================================================*"
|
||||
# @echo ""
|
@ -43,7 +43,7 @@
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../../include;../../third_party/bnlib;../../third_party/bgaes;../../test/include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;HAVE_CONFIG_H=1;ZRTP_ENABLE_EC=0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;HAVE_CONFIG_H=1;ZRTP_ENABLE_EC=1"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
@ -109,7 +109,7 @@
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalIncludeDirectories="../../include;../../third_party/bnlib;../../third_party/bgaes"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;HAVE_CONFIG_H=1;ZRTP_ENABLE_EC=0"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;HAVE_CONFIG_H=1;ZRTP_ENABLE_EC=1"
|
||||
ExceptionHandling="0"
|
||||
RuntimeLibrary="0"
|
||||
StructMemberAlignment="0"
|
||||
@ -180,6 +180,10 @@
|
||||
RelativePath="..\..\include\zrtp_crypto.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\zrtp_ec.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\zrtp_engine.h"
|
||||
>
|
||||
@ -244,6 +248,10 @@
|
||||
RelativePath="..\..\include\zrtp_utils.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\zrtp_version.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="src"
|
||||
@ -264,6 +272,14 @@
|
||||
RelativePath="..\..\src\zrtp_crypto_atl.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\zrtp_crypto_ec.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\zrtp_crypto_ecdh.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\zrtp_crypto_hash.c"
|
||||
>
|
||||
|
@ -52,7 +52,7 @@
|
||||
ExecutionBucket="7"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../../third_party/bnlib;../../include;../../include/enterprise;../../third_party/bgaes;../../test/include"
|
||||
PreprocessorDefinitions="_DEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;DEBUG;_LIB;$(ARCHFAM);$(_ARCHFAM_);_UNICODE;UNICODE;ZRTP_ENABLE_EC=0"
|
||||
PreprocessorDefinitions="_DEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;DEBUG;_LIB;$(ARCHFAM);$(_ARCHFAM_);_UNICODE;UNICODE;ZRTP_ENABLE_EC=1"
|
||||
MinimalRebuild="true"
|
||||
RuntimeLibrary="1"
|
||||
StructMemberAlignment="0"
|
||||
@ -136,7 +136,7 @@
|
||||
ExecutionBucket="7"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="../../third_party/bnlib;../../include;../../include/enterprise;../../third_party/bgaes;../../test/include"
|
||||
PreprocessorDefinitions="_DEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;DEBUG;_LIB;$(ARCHFAM);$(_ARCHFAM_);_UNICODE;ZRTP_ENABLE_EC=0"
|
||||
PreprocessorDefinitions="_DEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;DEBUG;_LIB;$(ARCHFAM);$(_ARCHFAM_);_UNICODE;ZRTP_ENABLE_EC=1"
|
||||
MinimalRebuild="true"
|
||||
RuntimeLibrary="1"
|
||||
BufferSecurityCheck="false"
|
||||
@ -219,7 +219,7 @@
|
||||
ExecutionBucket="7"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories="../../third_party/bnlib;../../include;../../include/enterprise;../../third_party/bgaes;../../test/include"
|
||||
PreprocessorDefinitions="NDEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;_LIB;$(ARCHFAM);$(_ARCHFAM_);_UNICODE;ZRTP_ENABLE_EC=0"
|
||||
PreprocessorDefinitions="NDEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;_LIB;$(ARCHFAM);$(_ARCHFAM_);_UNICODE;ZRTP_ENABLE_EC=1"
|
||||
RuntimeLibrary="0"
|
||||
BufferSecurityCheck="false"
|
||||
UsePrecompiledHeader="0"
|
||||
@ -300,7 +300,7 @@
|
||||
ExecutionBucket="7"
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories="../../third_party/bnlib;../../include;../../include/enterprise;../../third_party/bgaes;../../test/include"
|
||||
PreprocessorDefinitions="NDEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;_LIB;$(ARCHFAM);$(_ARCHFAM_);_UNICODE;UNICODE;ZRTP_ENABLE_EC=0"
|
||||
PreprocessorDefinitions="NDEBUG;_WIN32_WCE=$(CEVER);UNDER_CE;$(PLATFORMDEFINES);WINCE;_LIB;$(ARCHFAM);$(_ARCHFAM_);_UNICODE;UNICODE;ZRTP_ENABLE_EC=1"
|
||||
RuntimeLibrary="0"
|
||||
BufferSecurityCheck="false"
|
||||
UsePrecompiledHeader="0"
|
||||
@ -382,6 +382,10 @@
|
||||
RelativePath="..\..\include\zrtp_crypto.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\zrtp_ec.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\include\zrtp_engine.h"
|
||||
>
|
||||
@ -462,6 +466,18 @@
|
||||
RelativePath="..\..\src\zrtp_crypto_atl.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\zrtp_crypto_ec.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\zrtp_crypto_ecdh.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\zrtp_crypto_ecdsa.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\zrtp_crypto_hash.c"
|
||||
>
|
||||
@ -482,6 +498,10 @@
|
||||
RelativePath="..\..\src\zrtp_engine.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\zrtp_engine_driven.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\zrtp_iface_cache.c"
|
||||
>
|
||||
|
@ -43,6 +43,9 @@ protocol = \
|
||||
../../src/zrtp_crypto_sas.obj \
|
||||
../../src/zrtp_datatypes.obj \
|
||||
../../src/zrtp_engine.obj \
|
||||
../../src/enterprise/zrtp_engine_driven.obj \
|
||||
../../src/enterprise/zrtp_crypto_ec.obj \
|
||||
../../src/enterprise/zrtp_crypto_ecdh.obj \
|
||||
../../src/zrtp_iface_sys.obj \
|
||||
../../src/zrtp_initiator.obj \
|
||||
../../src/zrtp_legal.obj \
|
||||
@ -71,13 +74,13 @@ OBJECTS = $(bnlib) $(protocol) $(bgaes)
|
||||
|
||||
# Debug
|
||||
|
||||
OUT_DIR = debug.km
|
||||
OUT_DIR = debug_ec.km
|
||||
|
||||
DEFINES_D = -D_X86_=1 -Di386=1 -DSTD_CALL -DCONDITION_HANDLING=1 \
|
||||
-DNT_UP=1 -DNT_INST=0 -DWIN32=100 -D_NT1X_=100 \
|
||||
-DWINNT=1 -D_WIN32_WINNT=0x0500 -DWIN32_LEAN_AND_MEAN=1 -DDBG=1 -D_DEBUG -DDEBUG -DDEVL=1 \
|
||||
-DFPO=0 -D_DLL=1 -D_IDWBUILD -DRDRDBG -DSRVDBG -DDBG_MESSAGES=1 \
|
||||
-D_UNICODE -DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=0
|
||||
-D_UNICODE -DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=1
|
||||
|
||||
CFLAGS_D = $(DEFINES_D) -Zel -Zp8 -Gy -cbstring -Gz -QIfdiv- -QIf -Gi- -Gm- -GX- \
|
||||
-GR- -GF -FI$(DDK)\inc\$(OS)\warning.h -Z7 -Od -Oi -Oy- -W3
|
||||
@ -86,13 +89,13 @@ CFLAGS_D = $(DEFINES_D) -Zel -Zp8 -Gy -cbstring -Gz -QIfdiv- -QIf -Gi- -Gm- -GX-
|
||||
|
||||
# Release
|
||||
|
||||
OUT_DIR = release.km
|
||||
OUT_DIR = release_ec.km
|
||||
|
||||
DEFINES_D = -D_X86_=1 -Di386=1 -DSTD_CALL -DCONDITION_HANDLING=1 \
|
||||
-DNT_UP=1 -DNO_DISK_ACCESS -DNT_INST=0 -DWIN32=100 -D_NT1X_=100 \
|
||||
-DWINNT=1 -D_WIN32_WINNT=0x0500 -DWIN32_LEAN_AND_MEAN=1 -DDEVL=1 \
|
||||
-DFPO=1 -DNDEBUG -D_DLL=1 -D_IDWBUILD -D_UNICODE \
|
||||
-DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=0
|
||||
-DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=1
|
||||
|
||||
CFLAGS_D = $(DEFINES_D) -Zel -Zp8 -Gy -cbstring -Gz -QIfdiv- -QIf -Gi- -Gm- -GX- \
|
||||
-GR- -GF -Oxs -Oy -FI$(DDK)\inc\$(OS)\warning.h -W3 -FAcs -Z7
|
||||
|
@ -44,6 +44,9 @@ protocol = \
|
||||
../../src/zrtp_crypto_sas.obj \
|
||||
../../src/zrtp_datatypes.obj \
|
||||
../../src/zrtp_engine.obj \
|
||||
../../src/enterprise/zrtp_engine_driven.obj \
|
||||
../../src/enterprise/zrtp_crypto_ec.obj \
|
||||
../../src/enterprise/zrtp_crypto_ecdh.obj \
|
||||
../../src/zrtp_iface_sys.obj \
|
||||
../../src/zrtp_initiator.obj \
|
||||
../../src/zrtp_legal.obj \
|
||||
@ -72,14 +75,14 @@ OBJECTS = $(bnlib) $(protocol) $(bgaes)
|
||||
|
||||
# Debug
|
||||
|
||||
OUT_DIR = debug64.km
|
||||
OUT_DIR = debug64_ec.km
|
||||
|
||||
DEFINES_D = -DWIN64=1 -D_WIN64=1 -D_AMD64_=1 -D_M_AMD64 -D_WINDOWS \
|
||||
-DSTD_CALL -DCONDITION_HANDLING=1 \
|
||||
-DNT_UP=1 -DNT_INST=0 -D_NT1X_=100 \
|
||||
-DWINNT=1 -D_WIN32_WINNT=0x0500 -DWIN32_LEAN_AND_MEAN=1 -DDBG=1 -D_DEBUG -DDEBUG -DDEVL=1 \
|
||||
-DFPO=0 -D_DLL=1 -D_IDWBUILD -DRDRDBG -DSRVDBG -DDBG_MESSAGES=1 \
|
||||
-D_UNICODE -DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=0
|
||||
-D_UNICODE -DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=1
|
||||
|
||||
CFLAGS_D = $(DEFINES_D) -Zp8 -Gy -cbstring -Gz -Gm- -EHs-c- \
|
||||
-GR- -GF -FI$(DDK)\inc\$(OS)\warning.h -Z7 -Od -Oi -Oy- -W3
|
||||
@ -88,14 +91,14 @@ CFLAGS_D = $(DEFINES_D) -Zp8 -Gy -cbstring -Gz -Gm- -EHs-c- \
|
||||
|
||||
# Release
|
||||
|
||||
OUT_DIR = release64.km
|
||||
OUT_DIR = release64_ec.km
|
||||
|
||||
DEFINES_D = -DWIN64=1 -D_WIN64=1 -D_AMD64_=1 -D_M_AMD64 -D_WINDOWS \
|
||||
-DSTD_CALL -DCONDITION_HANDLING=1 \
|
||||
-DNT_UP=1 -DNO_DISK_ACCESS -DNT_INST=0 -DWIN32=100 -D_NT1X_=100 \
|
||||
-DWINNT=1 -D_WIN32_WINNT=0x0500 -DWIN32_LEAN_AND_MEAN=1 -DDEVL=1 \
|
||||
-DFPO=1 -DNDEBUG -D_DLL=1 -D_IDWBUILD -D_UNICODE \
|
||||
-DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=0
|
||||
-DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=1
|
||||
|
||||
CFLAGS_D = $(DEFINES_D) -Zel -Zp8 -Gy -cbstring -Gz -QIfdiv- -QIf -Gi- -Gm- -GX- \
|
||||
-GR- -GF -Oxs -Oy -FI$(DDK)\inc\$(OS)\warning.h -W3 -FAcs -Z7
|
||||
|
@ -34,6 +34,8 @@ void zrtp_config_defaults(zrtp_config_t* config)
|
||||
ZSTR_SET_EMPTY(config->def_cache_path);
|
||||
zrtp_zstrncpyc(ZSTR_GV(config->def_cache_path), "./zrtp_def_cache_path.dat", 25);
|
||||
|
||||
config->cache_auto_store = 1; /* cache auto flushing should be enabled by default */
|
||||
|
||||
#if (defined(ZRTP_USE_BUILTIN_CACHE) && (ZRTP_USE_BUILTIN_CACHE == 1))
|
||||
config->cb.cache_cb.on_init = zrtp_def_cache_init;
|
||||
config->cb.cache_cb.on_down = zrtp_def_cache_down;
|
||||
@ -81,6 +83,7 @@ zrtp_status_t zrtp_init(zrtp_config_t* config, zrtp_global_t** zrtp)
|
||||
ZSTR_SET_EMPTY(new_zrtp->def_cache_path);
|
||||
zrtp_zstrcpy(ZSTR_GV(new_zrtp->def_cache_path), ZSTR_GV(config->def_cache_path));
|
||||
zrtp_memcpy(&new_zrtp->cb, &config->cb, sizeof(zrtp_callback_t));
|
||||
new_zrtp->cache_auto_store = config->cache_auto_store;
|
||||
|
||||
ZSTR_SET_EMPTY(new_zrtp->client_id);
|
||||
zrtp_memset(new_zrtp->client_id.buffer, ' ', sizeof(zrtp_client_id_t));
|
||||
@ -434,8 +437,6 @@ zrtp_status_t zrtp_stream_attach(zrtp_session_t *session, zrtp_stream_t** stream
|
||||
ZSTR_SET_EMPTY(new_stream->cc.peer_hmackey);
|
||||
ZSTR_SET_EMPTY(new_stream->cc.zrtp_key);
|
||||
ZSTR_SET_EMPTY(new_stream->cc.peer_zrtp_key);
|
||||
|
||||
ZSTR_SET_EMPTY(new_stream->messages.signaling_hash);
|
||||
|
||||
new_stream->dh_cc.initialized_with = ZRTP_COMP_UNKN;
|
||||
bnBegin(&new_stream->dh_cc.peer_pv);
|
||||
@ -461,8 +462,9 @@ zrtp_status_t zrtp_stream_attach(zrtp_session_t *session, zrtp_stream_t** stream
|
||||
* Then insert these directly into the message structures.
|
||||
*/
|
||||
|
||||
zrtp_memset(&new_stream->messages, 0, sizeof(new_stream->messages));
|
||||
zrtp_memset(&new_stream->messages, 0, sizeof(new_stream->messages));
|
||||
ZSTR_SET_EMPTY(new_stream->messages.h0);
|
||||
ZSTR_SET_EMPTY(new_stream->messages.signaling_hash);
|
||||
|
||||
/* Generate Random nonce, compute H1 and store in the DH packet */
|
||||
new_stream->messages.h0.length = (uint16_t)zrtp_randstr( new_stream->zrtp,
|
||||
@ -592,11 +594,11 @@ zrtp_status_t zrtp_signaling_hash_get( zrtp_stream_t* stream,
|
||||
zrtp_string32_t hash_str = ZSTR_INIT_EMPTY(hash_str);
|
||||
zrtp_hash_t *hash = NULL;
|
||||
|
||||
if (!stream) {
|
||||
if (!stream || !hash_buff) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
if (ZRTP_MESSAGE_HASH_SIZE*2+1 > hash_buff_length) {
|
||||
if (ZRTP_SIGN_ZRTP_HASH_LENGTH > hash_buff_length) {
|
||||
return zrtp_status_buffer_size;
|
||||
}
|
||||
|
||||
@ -619,11 +621,11 @@ zrtp_status_t zrtp_signaling_hash_set( zrtp_stream_t* ctx,
|
||||
const char *hash_buff,
|
||||
uint32_t hash_buff_length)
|
||||
{
|
||||
if (!ctx) {
|
||||
if (!ctx || !hash_buff) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
if (ZRTP_MESSAGE_HASH_SIZE*2 < hash_buff_length) {
|
||||
if (ZRTP_SIGN_ZRTP_HASH_LENGTH > hash_buff_length) {
|
||||
return zrtp_status_buffer_size;
|
||||
}
|
||||
|
||||
@ -631,17 +633,14 @@ zrtp_status_t zrtp_signaling_hash_set( zrtp_stream_t* ctx,
|
||||
return zrtp_status_wrong_state;
|
||||
}
|
||||
|
||||
str2hex( hash_buff,
|
||||
hash_buff_length,
|
||||
ctx->messages.signaling_hash.buffer,
|
||||
ctx->messages.signaling_hash.max_length);
|
||||
str2hex(hash_buff,
|
||||
ZRTP_SIGN_ZRTP_HASH_LENGTH,
|
||||
ctx->messages.signaling_hash.buffer,
|
||||
ctx->messages.signaling_hash.max_length);
|
||||
ctx->messages.signaling_hash.length = ZRTP_MESSAGE_HASH_SIZE;
|
||||
|
||||
{
|
||||
char buff[64];
|
||||
ZRTP_LOG(3, (_ZTU_,"SIGNALLING HAS was ADDED for the comparision. ID=%u\n", ctx->id));
|
||||
ZRTP_LOG(3, (_ZTU_,"Hash=%s.\n", hex2str(hash_buff, hash_buff_length, buff, sizeof(buff))));
|
||||
}
|
||||
ZRTP_LOG(3, (_ZTU_,"SIGNALLING HAS was ADDED for the comparison. ID=%u\n", ctx->id));
|
||||
ZRTP_LOG(3, (_ZTU_,"Hash=%.*s.\n", ZRTP_SIGN_ZRTP_HASH_LENGTH, hash_buff));
|
||||
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
@ -803,7 +802,6 @@ void zrtp_profile_defaults(zrtp_profile_t* profile, zrtp_global_t* zrtp)
|
||||
profile->auth_tag_lens[0] = ZRTP_ATL_HS32;
|
||||
profile->hash_schemes[0] = ZRTP_HASH_SHA256;
|
||||
|
||||
#if (defined(ZRTP_ENABLE_EC) && (ZRTP_ENABLE_EC == 1))
|
||||
if (zrtp && (ZRTP_LICENSE_MODE_PASSIVE == zrtp->lic_mode)) {
|
||||
profile->pk_schemes[0] = ZRTP_PKTYPE_DH2048;
|
||||
profile->pk_schemes[1] = ZRTP_PKTYPE_EC256P;
|
||||
@ -814,16 +812,6 @@ void zrtp_profile_defaults(zrtp_profile_t* profile, zrtp_global_t* zrtp)
|
||||
profile->pk_schemes[2] = ZRTP_PKTYPE_DH2048;
|
||||
}
|
||||
profile->pk_schemes[3] = ZRTP_PKTYPE_MULT;
|
||||
#else
|
||||
if (zrtp && (ZRTP_LICENSE_MODE_PASSIVE == zrtp->lic_mode)) {
|
||||
profile->pk_schemes[0] = ZRTP_PKTYPE_DH2048;
|
||||
profile->pk_schemes[1] = ZRTP_PKTYPE_DH3072;
|
||||
} else {
|
||||
profile->pk_schemes[0] = ZRTP_PKTYPE_DH3072;
|
||||
profile->pk_schemes[1] = ZRTP_PKTYPE_DH2048;
|
||||
}
|
||||
profile->pk_schemes[2] = ZRTP_PKTYPE_MULT;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@ -1093,6 +1081,7 @@ char* zrtp_comp_id2type(zrtp_crypto_comp_t type, uint8_t id)
|
||||
case ZRTP_HASH_SHA384: return ZRTP_S384;
|
||||
default: return "Unkn";
|
||||
}
|
||||
break;
|
||||
|
||||
case ZRTP_CC_SAS:
|
||||
switch (id)
|
||||
@ -1101,6 +1090,7 @@ char* zrtp_comp_id2type(zrtp_crypto_comp_t type, uint8_t id)
|
||||
case ZRTP_SAS_BASE256: return ZRTP_B256;
|
||||
default: return "Unkn";
|
||||
}
|
||||
break;
|
||||
|
||||
case ZRTP_CC_CIPHER:
|
||||
switch (id)
|
||||
@ -1109,6 +1099,7 @@ char* zrtp_comp_id2type(zrtp_crypto_comp_t type, uint8_t id)
|
||||
case ZRTP_CIPHER_AES256: return ZRTP_AES3;
|
||||
default: return "Unkn";
|
||||
}
|
||||
break;
|
||||
|
||||
case ZRTP_CC_PKT:
|
||||
switch (id)
|
||||
@ -1122,6 +1113,7 @@ char* zrtp_comp_id2type(zrtp_crypto_comp_t type, uint8_t id)
|
||||
case ZRTP_PKTYPE_EC521P: return ZRTP_EC521P;
|
||||
default: return "Unkn";
|
||||
}
|
||||
break;
|
||||
|
||||
case ZRTP_CC_ATL:
|
||||
switch (id)
|
||||
@ -1129,7 +1121,8 @@ char* zrtp_comp_id2type(zrtp_crypto_comp_t type, uint8_t id)
|
||||
case ZRTP_ATL_HS32: return ZRTP_HS32;
|
||||
case ZRTP_ATL_HS80: return ZRTP_HS80;
|
||||
default: return "Unkn";
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return "Unkn";
|
||||
|
461
libs/libzrtp/src/zrtp_crypto_ec.c
Normal file
461
libs/libzrtp/src/zrtp_crypto_ec.c
Normal file
@ -0,0 +1,461 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*/
|
||||
|
||||
#include "zrtp.h"
|
||||
|
||||
/* Size of extra random data to approximate a uniform distribution mod n */
|
||||
#define UNIFORMBYTES 8
|
||||
|
||||
|
||||
/*============================================================================*/
|
||||
/* Bignum Shorthand Functions */
|
||||
/*============================================================================*/
|
||||
|
||||
int bnAddMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *mod)
|
||||
{
|
||||
bnAdd (rslt, n1);
|
||||
if (bnCmp (rslt, mod) >= 0) {
|
||||
bnSub (rslt, mod);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bnAddQMod_ (struct BigNum *rslt, unsigned n1, struct BigNum *mod)
|
||||
{
|
||||
bnAddQ (rslt, n1);
|
||||
if (bnCmp (rslt, mod) >= 0) {
|
||||
bnSub (rslt, mod);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bnSubMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *mod)
|
||||
{
|
||||
if (bnCmp (rslt, n1) < 0) {
|
||||
bnAdd (rslt, mod);
|
||||
}
|
||||
bnSub (rslt, n1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bnSubQMod_ (struct BigNum *rslt, unsigned n1, struct BigNum *mod)
|
||||
{
|
||||
if (bnCmpQ (rslt, n1) < 0) {
|
||||
bnAdd (rslt, mod);
|
||||
}
|
||||
bnSubQ (rslt, n1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bnMulMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *n2, struct BigNum *mod)
|
||||
{
|
||||
bnMul (rslt, n1, n2);
|
||||
bnMod (rslt, rslt, mod);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bnMulQMod_ (struct BigNum *rslt, struct BigNum *n1, unsigned n2, struct BigNum *mod)
|
||||
{
|
||||
bnMulQ (rslt, n1, n2);
|
||||
bnMod (rslt, rslt, mod);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bnSquareMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *mod)
|
||||
{
|
||||
bnSquare (rslt, n1);
|
||||
bnMod (rslt, rslt, mod);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*============================================================================*/
|
||||
/* Elliptic Curve arithmetic */
|
||||
/*============================================================================*/
|
||||
|
||||
/* Add two elliptic curve points. Any of them may be the same object. */
|
||||
int zrtp_ecAdd ( struct BigNum *rsltx, struct BigNum *rslty,
|
||||
struct BigNum *p1x, struct BigNum *p1y,
|
||||
struct BigNum *p2x, struct BigNum *p2y, struct BigNum *mod)
|
||||
{
|
||||
struct BigNum trsltx, trslty;
|
||||
struct BigNum t1, gam;
|
||||
struct BigNum bnzero;
|
||||
|
||||
bnBegin (&bnzero);
|
||||
|
||||
/* Check for an operand being zero */
|
||||
if (bnCmp (p1x, &bnzero) == 0 && bnCmp (p1y, &bnzero) == 0) {
|
||||
bnCopy (rsltx, p2x); bnCopy (rslty, p2y);
|
||||
bnEnd (&bnzero);
|
||||
return 0;
|
||||
}
|
||||
if (bnCmp (p2x, &bnzero) == 0 && bnCmp (p2y, &bnzero) == 0) {
|
||||
bnCopy (rsltx, p1x); bnCopy (rslty, p1y);
|
||||
bnEnd (&bnzero);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Check if p1 == -p2 and return 0 if so */
|
||||
if (bnCmp (p1x, p2x) == 0) {
|
||||
struct BigNum tsum;
|
||||
bnBegin (&tsum);
|
||||
bnCopy (&tsum, p1x);
|
||||
bnAddMod_ (&tsum, p2x, mod);
|
||||
if (bnCmp (&tsum, &bnzero) == 0) {
|
||||
bnSetQ (rsltx, 0); bnSetQ (rslty, 0);
|
||||
bnEnd (&tsum);
|
||||
bnEnd (&bnzero);
|
||||
return 0;
|
||||
}
|
||||
bnEnd (&tsum);
|
||||
}
|
||||
|
||||
bnBegin (&t1);
|
||||
bnBegin (&gam);
|
||||
bnBegin (&trsltx);
|
||||
bnBegin (&trslty);
|
||||
|
||||
/* Check for doubling, different formula for gamma */
|
||||
if (bnCmp (p1x, p2x) == 0 && bnCmp (p1y, p2y) == 0) {
|
||||
bnCopy (&t1, p1y);
|
||||
bnAddMod_ (&t1, p1y, mod);
|
||||
bnInv (&t1, &t1, mod);
|
||||
bnSquareMod_ (&gam, p1x, mod);
|
||||
bnMulQMod_ (&gam, &gam, 3, mod);
|
||||
bnSubQMod_ (&gam, 3, mod);
|
||||
bnMulMod_ (&gam, &gam, &t1, mod);
|
||||
} else {
|
||||
bnCopy (&t1, p2x);
|
||||
bnSubMod_ (&t1, p1x, mod);
|
||||
bnInv (&t1, &t1, mod);
|
||||
bnCopy (&gam, p2y);
|
||||
bnSubMod_ (&gam, p1y, mod);
|
||||
bnMulMod_ (&gam, &gam, &t1, mod);
|
||||
}
|
||||
|
||||
bnSquareMod_ (&trsltx, &gam, mod);
|
||||
bnSubMod_ (&trsltx, p1x, mod);
|
||||
bnSubMod_ (&trsltx, p2x, mod);
|
||||
|
||||
bnCopy (&trslty, p1x);
|
||||
bnSubMod_ (&trslty, &trsltx, mod);
|
||||
bnMulMod_ (&trslty, &trslty, &gam, mod);
|
||||
bnSubMod_ (&trslty, p1y, mod);
|
||||
|
||||
bnCopy (rsltx, &trsltx);
|
||||
bnCopy (rslty, &trslty);
|
||||
|
||||
bnEnd (&t1);
|
||||
bnEnd (&gam);
|
||||
bnEnd (&trsltx);
|
||||
bnEnd (&trslty);
|
||||
bnEnd (&bnzero);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int zrtp_ecMul ( struct BigNum *rsltx, struct BigNum *rslty, struct BigNum *mult,
|
||||
struct BigNum *basex, struct BigNum *basey, struct BigNum *mod)
|
||||
{
|
||||
struct BigNum bnzero;
|
||||
struct BigNum tbasex, tbasey;
|
||||
struct BigNum trsltx, trslty;
|
||||
struct BigNum tmult;
|
||||
|
||||
bnBegin (&bnzero);
|
||||
bnBegin (&tbasex);
|
||||
bnBegin (&tbasey);
|
||||
bnBegin (&trsltx);
|
||||
bnBegin (&trslty);
|
||||
bnBegin (&tmult);
|
||||
|
||||
/* Initialize result to 0 before additions */
|
||||
bnSetQ (&trsltx, 0);
|
||||
bnSetQ (&trslty, 0);
|
||||
/* Make copies of base and multiplier */
|
||||
bnCopy (&tbasex, basex);
|
||||
bnCopy (&tbasey, basey);
|
||||
bnCopy (&tmult, mult);
|
||||
while (bnCmp (&tmult, &bnzero) > 0) {
|
||||
/* Test lsb of mult */
|
||||
unsigned lsw = bnLSWord (&tmult);
|
||||
if (lsw & 1) {
|
||||
/* Add base to result */
|
||||
zrtp_ecAdd (&trsltx, &trslty, &trsltx, &trslty, &tbasex, &tbasey, mod);
|
||||
}
|
||||
/* Double the base */
|
||||
zrtp_ecAdd (&tbasex, &tbasey, &tbasex, &tbasey, &tbasex, &tbasey, mod);
|
||||
/* Shift multiplier right */
|
||||
bnRShift (&tmult, 1);
|
||||
}
|
||||
|
||||
bnCopy (rsltx, &trsltx);
|
||||
bnCopy (rslty, &trslty);
|
||||
|
||||
bnEnd (&bnzero);
|
||||
bnEnd (&tbasex);
|
||||
bnEnd (&tbasey);
|
||||
bnEnd (&trsltx);
|
||||
bnEnd (&trslty);
|
||||
bnEnd (&tmult);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Choose a random point on the elliptic curve. */
|
||||
/* Provision is made to use a given point from test vectors. */
|
||||
/* pkx and pky are the output point, sv is output discrete log */
|
||||
/* Input base is Gx, Gy; curve field modulus is P; curve order is n. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
zrtp_status_t zrtp_ec_random_point( zrtp_global_t *zrtp,
|
||||
struct BigNum *P,
|
||||
struct BigNum *n,
|
||||
struct BigNum *Gx,
|
||||
struct BigNum *Gy,
|
||||
struct BigNum *pkx,
|
||||
struct BigNum *pky,
|
||||
struct BigNum *sv,
|
||||
uint8_t *test_sv_data,
|
||||
size_t test_sv_data_len)
|
||||
{
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
unsigned char* buffer = zrtp_sys_alloc(sizeof(zrtp_uchar1024_t));
|
||||
|
||||
if (!buffer) {
|
||||
return zrtp_status_alloc_fail;
|
||||
}
|
||||
zrtp_memset(buffer, 0, sizeof(zrtp_uchar1024_t));
|
||||
|
||||
do
|
||||
{
|
||||
if (test_sv_data_len != 0) {
|
||||
/* Force certain secret value */
|
||||
if (bnBytes(P) != test_sv_data_len) {
|
||||
break;
|
||||
}
|
||||
zrtp_memcpy(buffer+UNIFORMBYTES, test_sv_data, test_sv_data_len);
|
||||
} else {
|
||||
/* Choose random value, larger than needed so it will be uniform */
|
||||
if (bnBytes(P)+UNIFORMBYTES != (uint32_t)zrtp_randstr(zrtp, buffer, bnBytes(P)+UNIFORMBYTES)) {
|
||||
break; /* if we can't generate random string - fail initialization */
|
||||
}
|
||||
}
|
||||
|
||||
bnInsertBigBytes(sv, (const unsigned char *)buffer, 0, bnBytes(P)+UNIFORMBYTES);
|
||||
bnMod(sv, sv, n);
|
||||
zrtp_ecMul(pkx, pky, sv, Gx, Gy, P);
|
||||
|
||||
s = zrtp_status_ok;
|
||||
} while (0);
|
||||
|
||||
if (buffer) {
|
||||
zrtp_sys_free(buffer);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/*============================================================================*/
|
||||
/* Curve parameters */
|
||||
/*============================================================================*/
|
||||
|
||||
uint8_t P_256_data[] =
|
||||
{
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
|
||||
};
|
||||
|
||||
uint8_t n_256_data[] =
|
||||
{
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84,
|
||||
0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51
|
||||
};
|
||||
|
||||
uint8_t b_256_data[] =
|
||||
{
|
||||
0x5a, 0xc6, 0x35, 0xd8, 0xaa, 0x3a, 0x93, 0xe7,
|
||||
0xb3, 0xeb, 0xbd, 0x55, 0x76, 0x98, 0x86, 0xbc,
|
||||
0x65, 0x1d, 0x06, 0xb0, 0xcc, 0x53, 0xb0, 0xf6,
|
||||
0x3b, 0xce, 0x3c, 0x3e, 0x27, 0xd2, 0x60, 0x4b
|
||||
};
|
||||
|
||||
uint8_t Gx_256_data[] =
|
||||
{
|
||||
0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47,
|
||||
0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2,
|
||||
0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0,
|
||||
0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96
|
||||
};
|
||||
|
||||
uint8_t Gy_256_data[] =
|
||||
{
|
||||
0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b,
|
||||
0x8e, 0xe7, 0xeb, 0x4a, 0x7c, 0x0f, 0x9e, 0x16,
|
||||
0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce,
|
||||
0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5
|
||||
};
|
||||
|
||||
|
||||
|
||||
uint8_t P_384_data[] =
|
||||
{
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF
|
||||
};
|
||||
|
||||
uint8_t n_384_data[] =
|
||||
{
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xC7, 0x63, 0x4D, 0x81, 0xF4, 0x37, 0x2D, 0xDF,
|
||||
0x58, 0x1A, 0x0D, 0xB2, 0x48, 0xB0, 0xA7, 0x7A,
|
||||
0xEC, 0xEC, 0x19, 0x6A, 0xCC, 0xC5, 0x29, 0x73
|
||||
};
|
||||
|
||||
uint8_t b_384_data[] =
|
||||
{
|
||||
0xb3, 0x31, 0x2f, 0xa7, 0xe2, 0x3e, 0xe7, 0xe4,
|
||||
0x98, 0x8e, 0x05, 0x6b, 0xe3, 0xf8, 0x2d, 0x19,
|
||||
0x18, 0x1d, 0x9c, 0x6e, 0xfe, 0x81, 0x41, 0x12,
|
||||
0x03, 0x14, 0x08, 0x8f, 0x50, 0x13, 0x87, 0x5a,
|
||||
0xc6, 0x56, 0x39, 0x8d, 0x8a, 0x2e, 0xd1, 0x9d,
|
||||
0x2a, 0x85, 0xc8, 0xed, 0xd3, 0xec, 0x2a, 0xef
|
||||
};
|
||||
|
||||
uint8_t Gx_384_data[] =
|
||||
{
|
||||
0xaa, 0x87, 0xca, 0x22, 0xbe, 0x8b, 0x05, 0x37,
|
||||
0x8e, 0xb1, 0xc7, 0x1e, 0xf3, 0x20, 0xad, 0x74,
|
||||
0x6e, 0x1d, 0x3b, 0x62, 0x8b, 0xa7, 0x9b, 0x98,
|
||||
0x59, 0xf7, 0x41, 0xe0, 0x82, 0x54, 0x2a, 0x38,
|
||||
0x55, 0x02, 0xf2, 0x5d, 0xbf, 0x55, 0x29, 0x6c,
|
||||
0x3a, 0x54, 0x5e, 0x38, 0x72, 0x76, 0x0a, 0xb7
|
||||
};
|
||||
|
||||
uint8_t Gy_384_data[] =
|
||||
{
|
||||
0x36, 0x17, 0xde, 0x4a, 0x96, 0x26, 0x2c, 0x6f,
|
||||
0x5d, 0x9e, 0x98, 0xbf, 0x92, 0x92, 0xdc, 0x29,
|
||||
0xf8, 0xf4, 0x1d, 0xbd, 0x28, 0x9a, 0x14, 0x7c,
|
||||
0xe9, 0xda, 0x31, 0x13, 0xb5, 0xf0, 0xb8, 0xc0,
|
||||
0x0a, 0x60, 0xb1, 0xce, 0x1d, 0x7e, 0x81, 0x9d,
|
||||
0x7a, 0x43, 0x1d, 0x7c, 0x90, 0xea, 0x0e, 0x5f
|
||||
};
|
||||
|
||||
|
||||
uint8_t P_521_data[] =
|
||||
{
|
||||
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF
|
||||
};
|
||||
|
||||
uint8_t n_521_data[] =
|
||||
{
|
||||
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFA, 0x51, 0x86, 0x87, 0x83, 0xBF, 0x2F,
|
||||
0x96, 0x6B, 0x7F, 0xCC, 0x01, 0x48, 0xF7, 0x09,
|
||||
0xA5, 0xD0, 0x3B, 0xB5, 0xC9, 0xB8, 0x89, 0x9C,
|
||||
0x47, 0xAE, 0xBB, 0x6F, 0xB7, 0x1E, 0x91, 0x38,
|
||||
0x64, 0x09
|
||||
};
|
||||
|
||||
uint8_t b_521_data[] =
|
||||
{
|
||||
0x00, 0x51, 0x95, 0x3e, 0xb9, 0x61, 0x8e, 0x1c,
|
||||
0x9a, 0x1f, 0x92, 0x9a, 0x21, 0xa0, 0xb6, 0x85,
|
||||
0x40, 0xee, 0xa2, 0xda, 0x72, 0x5b, 0x99, 0xb3,
|
||||
0x15, 0xf3, 0xb8, 0xb4, 0x89, 0x91, 0x8e, 0xf1,
|
||||
0x09, 0xe1, 0x56, 0x19, 0x39, 0x51, 0xec, 0x7e,
|
||||
0x93, 0x7b, 0x16, 0x52, 0xc0, 0xbd, 0x3b, 0xb1,
|
||||
0xbf, 0x07, 0x35, 0x73, 0xdf, 0x88, 0x3d, 0x2c,
|
||||
0x34, 0xf1, 0xef, 0x45, 0x1f, 0xd4, 0x6b, 0x50,
|
||||
0x3f, 0x00
|
||||
};
|
||||
|
||||
uint8_t Gx_521_data[] =
|
||||
{
|
||||
0x00, 0xc6, 0x85, 0x8e, 0x06, 0xb7, 0x04, 0x04,
|
||||
0xe9, 0xcd, 0x9e, 0x3e, 0xcb, 0x66, 0x23, 0x95,
|
||||
0xb4, 0x42, 0x9c, 0x64, 0x81, 0x39, 0x05, 0x3f,
|
||||
0xb5, 0x21, 0xf8, 0x28, 0xaf, 0x60, 0x6b, 0x4d,
|
||||
0x3d, 0xba, 0xa1, 0x4b, 0x5e, 0x77, 0xef, 0xe7,
|
||||
0x59, 0x28, 0xfe, 0x1d, 0xc1, 0x27, 0xa2, 0xff,
|
||||
0xa8, 0xde, 0x33, 0x48, 0xb3, 0xc1, 0x85, 0x6a,
|
||||
0x42, 0x9b, 0xf9, 0x7e, 0x7e, 0x31, 0xc2, 0xe5,
|
||||
0xbd, 0x66
|
||||
};
|
||||
|
||||
uint8_t Gy_521_data[] =
|
||||
{
|
||||
0x01, 0x18, 0x39, 0x29, 0x6a, 0x78, 0x9a, 0x3b,
|
||||
0xc0, 0x04, 0x5c, 0x8a, 0x5f, 0xb4, 0x2c, 0x7d,
|
||||
0x1b, 0xd9, 0x98, 0xf5, 0x44, 0x49, 0x57, 0x9b,
|
||||
0x44, 0x68, 0x17, 0xaf, 0xbd, 0x17, 0x27, 0x3e,
|
||||
0x66, 0x2c, 0x97, 0xee, 0x72, 0x99, 0x5e, 0xf4,
|
||||
0x26, 0x40, 0xc5, 0x50, 0xb9, 0x01, 0x3f, 0xad,
|
||||
0x07, 0x61, 0x35, 0x3c, 0x70, 0x86, 0xa2, 0x72,
|
||||
0xc2, 0x40, 0x88, 0xbe, 0x94, 0x76, 0x9f, 0xd1,
|
||||
0x66, 0x50
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Initialize the curve parameters struct */
|
||||
zrtp_status_t zrtp_ec_init_params( struct zrtp_ec_params *params, uint32_t bits )
|
||||
{
|
||||
unsigned ec_bytes = (bits+7) / 8;
|
||||
params->ec_bits = bits;
|
||||
switch (bits) {
|
||||
case 256:
|
||||
zrtp_memcpy (params->P_data, P_256_data, ec_bytes);
|
||||
zrtp_memcpy (params->n_data, n_256_data, ec_bytes);
|
||||
zrtp_memcpy (params->b_data, b_256_data, ec_bytes);
|
||||
zrtp_memcpy (params->Gx_data, Gx_256_data, ec_bytes);
|
||||
zrtp_memcpy (params->Gy_data, Gy_256_data, ec_bytes);
|
||||
break;
|
||||
case 384:
|
||||
zrtp_memcpy (params->P_data, P_384_data, ec_bytes);
|
||||
zrtp_memcpy (params->n_data, n_384_data, ec_bytes);
|
||||
zrtp_memcpy (params->b_data, b_384_data, ec_bytes);
|
||||
zrtp_memcpy (params->Gx_data, Gx_384_data, ec_bytes);
|
||||
zrtp_memcpy (params->Gy_data, Gy_384_data, ec_bytes);
|
||||
break;
|
||||
case 521:
|
||||
zrtp_memcpy (params->P_data, P_521_data, ec_bytes);
|
||||
zrtp_memcpy (params->n_data, n_521_data, ec_bytes);
|
||||
zrtp_memcpy (params->b_data, b_521_data, ec_bytes);
|
||||
zrtp_memcpy (params->Gx_data, Gx_521_data, ec_bytes);
|
||||
zrtp_memcpy (params->Gy_data, Gy_521_data, ec_bytes);
|
||||
break;
|
||||
default:
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
return zrtp_status_ok;
|
||||
}
|
559
libs/libzrtp/src/zrtp_crypto_ecdh.c
Normal file
559
libs/libzrtp/src/zrtp_crypto_ecdh.c
Normal file
@ -0,0 +1,559 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*/
|
||||
|
||||
#include "zrtp.h"
|
||||
|
||||
|
||||
#define _ZTU_ "zrtp ecdh"
|
||||
|
||||
static unsigned get_pbits(zrtp_pk_scheme_t *self)
|
||||
{
|
||||
switch (self->base.id) {
|
||||
case ZRTP_PKTYPE_EC256P:
|
||||
return 256;
|
||||
break;
|
||||
case ZRTP_PKTYPE_EC384P:
|
||||
return 384;
|
||||
break;
|
||||
case ZRTP_PKTYPE_EC521P:
|
||||
return 521;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*============================================================================*/
|
||||
/* Shared Elliptic Curve functions */
|
||||
/* */
|
||||
/* The Elliptic Curve DH algorithm and key generation is from */
|
||||
/* NIST SP 800-56A. The curves used are from NSA Suite B, which */
|
||||
/* uses the same curves as ECDSA defined by FIPS 186-3, and are */
|
||||
/* also defined in RFC 4753, sections 3.1 through 3.3. */
|
||||
/* The validation procedures are from NIST SP 800-56A section 5.6.2.6, */
|
||||
/* method 3, ECC Partial Validation. */
|
||||
/*============================================================================*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t zrtp_ecdh_init(void *s) {
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
static zrtp_status_t zrtp_ecdh_free(void *s) {
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Return dh_cc->pv holding public value and dh_cc->sv holding secret value */
|
||||
/* The public value is an elliptic curve point encoded as the x part shifted */
|
||||
/* left Pbits bits and or'd with the y part. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t zrtp_ecdh_initialize( zrtp_pk_scheme_t *self,
|
||||
zrtp_dh_crypto_context_t *dh_cc)
|
||||
{
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
struct BigNum P, Gx, Gy, n;
|
||||
struct BigNum pkx, pky;
|
||||
unsigned ec_bytes = 0;
|
||||
unsigned pbits = 0;
|
||||
struct zrtp_ec_params ec_params;
|
||||
zrtp_time_t start_ts = zrtp_time_now();
|
||||
|
||||
if (!self || !dh_cc) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
pbits = get_pbits(self);
|
||||
if (!pbits) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
zrtp_ec_init_params(&ec_params, pbits);
|
||||
|
||||
ec_bytes = (ec_params.ec_bits+7) / 8;
|
||||
|
||||
bnBegin(&P);
|
||||
bnInsertBigBytes(&P, ec_params.P_data, 0, ec_bytes );
|
||||
bnBegin(&Gx);
|
||||
bnInsertBigBytes(&Gx, ec_params.Gx_data, 0, ec_bytes );
|
||||
bnBegin(&Gy);
|
||||
bnInsertBigBytes(&Gy, ec_params.Gy_data, 0, ec_bytes );
|
||||
bnBegin(&n);
|
||||
bnInsertBigBytes(&n, ec_params.n_data, 0, ec_bytes );
|
||||
|
||||
bnBegin(&pkx);
|
||||
bnBegin(&pky);
|
||||
bnBegin(&dh_cc->sv);
|
||||
s = zrtp_ec_random_point( self->base.zrtp, &P, &n, &Gx, &Gy,
|
||||
&pkx, &pky, &dh_cc->sv,
|
||||
NULL, 0);
|
||||
|
||||
if (zrtp_status_ok == s)
|
||||
{
|
||||
bnBegin(&dh_cc->pv);
|
||||
bnCopy (&dh_cc->pv, &pkx);
|
||||
bnLShift (&dh_cc->pv, pbits);
|
||||
bnAdd (&dh_cc->pv, &pky);
|
||||
}
|
||||
|
||||
bnEnd (&pkx);
|
||||
bnEnd (&pky);
|
||||
bnEnd (&P);
|
||||
bnEnd (&Gx);
|
||||
bnEnd (&Gy);
|
||||
bnEnd (&n);
|
||||
|
||||
ZRTP_LOG(1,(_ZTU_,"\tDH TEST: zrtp_ecdh_initialize() for %.4s was executed by %llums.\n", self->base.type, zrtp_time_now()-start_ts));
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Compute the shared dhresult as the X coordinate of the EC point. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t zrtp_ecdh_compute( zrtp_pk_scheme_t *self,
|
||||
zrtp_dh_crypto_context_t *dh_cc,
|
||||
struct BigNum *dhresult,
|
||||
struct BigNum *pv)
|
||||
{
|
||||
struct BigNum P;
|
||||
struct BigNum pkx, pky, rsltx, rslty;
|
||||
unsigned ec_bytes = 0;
|
||||
unsigned pbits = 0;
|
||||
struct zrtp_ec_params ec_params;
|
||||
zrtp_time_t start_ts = zrtp_time_now();
|
||||
|
||||
if (!self || !dh_cc || !dhresult || !pv) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
pbits = get_pbits(self);
|
||||
if (!pbits) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
zrtp_ec_init_params(&ec_params, pbits);
|
||||
|
||||
ec_bytes = (ec_params.ec_bits+7) / 8;
|
||||
|
||||
bnBegin(&P);
|
||||
bnInsertBigBytes( &P, ec_params.P_data, 0, ec_bytes );
|
||||
|
||||
bnBegin (&pkx);
|
||||
bnBegin (&pky);
|
||||
bnBegin (&rsltx);
|
||||
bnBegin (&rslty);
|
||||
|
||||
bnSetQ (&pkx, 1);
|
||||
bnLShift (&pkx, pbits);
|
||||
bnMod (&pky, pv, &pkx);
|
||||
bnCopy (&pkx, pv);
|
||||
bnRShift (&pkx, pbits);
|
||||
|
||||
zrtp_ecMul (&rsltx, &rslty, &dh_cc->sv, &pkx, &pky, &P);
|
||||
bnCopy (dhresult, &rsltx);
|
||||
|
||||
bnEnd (&pkx);
|
||||
bnEnd (&pky);
|
||||
bnEnd (&rsltx);
|
||||
bnEnd (&rslty);
|
||||
bnEnd (&P);
|
||||
|
||||
ZRTP_LOG(1,(_ZTU_,"\tDH TEST: zrtp_ecdh_compute() for %.4s was executed by %llums.\n", self->base.type, zrtp_time_now()-start_ts));
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* ECC Partial Validation per NIST SP800-56A section 5.6.2.6 */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t zrtp_ecdh_validate( zrtp_pk_scheme_t *self,
|
||||
struct BigNum *pv)
|
||||
{
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
struct BigNum P, b;
|
||||
struct BigNum t1, t2;
|
||||
struct BigNum pkx, pky, bnzero;
|
||||
unsigned ec_bytes = 0;
|
||||
unsigned pbits = 0;
|
||||
struct zrtp_ec_params ec_params;
|
||||
zrtp_time_t start_ts = zrtp_time_now();
|
||||
|
||||
if (!self || !pv) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
pbits = get_pbits(self);
|
||||
if (!pbits) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
zrtp_ec_init_params(&ec_params, pbits);
|
||||
|
||||
ec_bytes = (ec_params.ec_bits+7) / 8;
|
||||
|
||||
bnBegin(&P);
|
||||
bnInsertBigBytes( &P, ec_params.P_data, 0, ec_bytes );
|
||||
bnBegin(&b);
|
||||
bnInsertBigBytes( &b, ec_params.b_data, 0, ec_bytes );
|
||||
|
||||
bnBegin (&t1);
|
||||
bnBegin (&t2);
|
||||
bnBegin (&pkx);
|
||||
bnBegin (&pky);
|
||||
bnBegin (&bnzero);
|
||||
|
||||
bnSetQ (&pkx, 1);
|
||||
bnLShift (&pkx, pbits);
|
||||
bnMod (&pky, pv, &pkx);
|
||||
bnCopy (&pkx, pv);
|
||||
bnRShift (&pkx, pbits);
|
||||
|
||||
do{
|
||||
/* Represent point at infinity by (0, 0), make sure it's not that */
|
||||
if (bnCmp (&pkx, &bnzero) == 0 && bnCmp (&pky, &bnzero) == 0) {
|
||||
break;
|
||||
}
|
||||
/* Check coordinates within range */
|
||||
if (bnCmp (&pkx, &bnzero) < 0 || bnCmp (&pkx, &P) >= 0) {
|
||||
break;
|
||||
}
|
||||
if (bnCmp (&pky, &bnzero) < 0 || bnCmp (&pky, &P) >= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Check that point satisfies EC equation y^2 = x^3 - 3x + b, mod P */
|
||||
bnSquareMod_ (&t1, &pky, &P);
|
||||
bnSquareMod_ (&t2, &pkx, &P);
|
||||
bnSubQMod_ (&t2, 3, &P);
|
||||
bnMulMod_ (&t2, &t2, &pkx, &P);
|
||||
bnAddMod_ (&t2, &b, &P);
|
||||
if (bnCmp (&t1, &t2) != 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
s = zrtp_status_ok;
|
||||
} while (0);
|
||||
|
||||
bnEnd (&t1);
|
||||
bnEnd (&t2);
|
||||
bnEnd (&pkx);
|
||||
bnEnd (&pky);
|
||||
bnEnd (&bnzero);
|
||||
bnEnd (&P);
|
||||
bnEnd (&b);
|
||||
|
||||
ZRTP_LOG(1,(_ZTU_,"\tDH TEST: zrtp_ecdh_validate() for %.4s was executed by %llums.\n", self->base.type, zrtp_time_now()-start_ts));
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/*============================================================================*/
|
||||
/* P-256, 384, 521 (FIPS 186-3) support. See RFC 4753 3.1, 3.2, 3.3 */
|
||||
/*============================================================================*/
|
||||
|
||||
static uint8_t sv256_data[] = {
|
||||
0x81, 0x42, 0x64, 0x14, 0x5F, 0x2F, 0x56, 0xF2,
|
||||
0xE9, 0x6A, 0x8E, 0x33, 0x7A, 0x12, 0x84, 0x99,
|
||||
0x3F, 0xAF, 0x43, 0x2A, 0x5A, 0xBC, 0xE5, 0x9E,
|
||||
0x86, 0x7B, 0x72, 0x91, 0xD5, 0x07, 0xA3, 0xAF
|
||||
};
|
||||
static uint8_t pvx256_data[] = {
|
||||
0x2A, 0xF5, 0x02, 0xF3, 0xBE, 0x89, 0x52, 0xF2,
|
||||
0xC9, 0xB5, 0xA8, 0xD4, 0x16, 0x0D, 0x09, 0xE9,
|
||||
0x71, 0x65, 0xBE, 0x50, 0xBC, 0x42, 0xAE, 0x4A,
|
||||
0x5E, 0x8D, 0x3B, 0x4B, 0xA8, 0x3A, 0xEB, 0x15
|
||||
};
|
||||
static uint8_t pvy256_data[] = {
|
||||
0xEB, 0x0F, 0xAF, 0x4C, 0xA9, 0x86, 0xC4, 0xD3,
|
||||
0x86, 0x81, 0xA0, 0xF9, 0x87, 0x2D, 0x79, 0xD5,
|
||||
0x67, 0x95, 0xBD, 0x4B, 0xFF, 0x6E, 0x6D, 0xE3,
|
||||
0xC0, 0xF5, 0x01, 0x5E, 0xCE, 0x5E, 0xFD, 0x85
|
||||
};
|
||||
|
||||
static uint8_t sv384_data[] = {
|
||||
0xD2, 0x73, 0x35, 0xEA, 0x71, 0x66, 0x4A, 0xF2,
|
||||
0x44, 0xDD, 0x14, 0xE9, 0xFD, 0x12, 0x60, 0x71,
|
||||
0x5D, 0xFD, 0x8A, 0x79, 0x65, 0x57, 0x1C, 0x48,
|
||||
0xD7, 0x09, 0xEE, 0x7A, 0x79, 0x62, 0xA1, 0x56,
|
||||
0xD7, 0x06, 0xA9, 0x0C, 0xBC, 0xB5, 0xDF, 0x29,
|
||||
0x86, 0xF0, 0x5F, 0xEA, 0xDB, 0x93, 0x76, 0xF1
|
||||
};
|
||||
static uint8_t pvx384_data[] = {
|
||||
0x79, 0x31, 0x48, 0xF1, 0x78, 0x76, 0x34, 0xD5,
|
||||
0xDA, 0x4C, 0x6D, 0x90, 0x74, 0x41, 0x7D, 0x05,
|
||||
0xE0, 0x57, 0xAB, 0x62, 0xF8, 0x20, 0x54, 0xD1,
|
||||
0x0E, 0xE6, 0xB0, 0x40, 0x3D, 0x62, 0x79, 0x54,
|
||||
0x7E, 0x6A, 0x8E, 0xA9, 0xD1, 0xFD, 0x77, 0x42,
|
||||
0x7D, 0x01, 0x6F, 0xE2, 0x7A, 0x8B, 0x8C, 0x66
|
||||
};
|
||||
static uint8_t pvy384_data[] = {
|
||||
0xC6, 0xC4, 0x12, 0x94, 0x33, 0x1D, 0x23, 0xE6,
|
||||
0xF4, 0x80, 0xF4, 0xFB, 0x4C, 0xD4, 0x05, 0x04,
|
||||
0xC9, 0x47, 0x39, 0x2E, 0x94, 0xF4, 0xC3, 0xF0,
|
||||
0x6B, 0x8F, 0x39, 0x8B, 0xB2, 0x9E, 0x42, 0x36,
|
||||
0x8F, 0x7A, 0x68, 0x59, 0x23, 0xDE, 0x3B, 0x67,
|
||||
0xBA, 0xCE, 0xD2, 0x14, 0xA1, 0xA1, 0xD1, 0x28
|
||||
};
|
||||
|
||||
static uint8_t sv521_data[] = {
|
||||
0x01, 0x13, 0xF8, 0x2D, 0xA8, 0x25, 0x73, 0x5E,
|
||||
0x3D, 0x97, 0x27, 0x66, 0x83, 0xB2, 0xB7, 0x42,
|
||||
0x77, 0xBA, 0xD2, 0x73, 0x35, 0xEA, 0x71, 0x66,
|
||||
0x4A, 0xF2, 0x43, 0x0C, 0xC4, 0xF3, 0x34, 0x59,
|
||||
0xB9, 0x66, 0x9E, 0xE7, 0x8B, 0x3F, 0xFB, 0x9B,
|
||||
0x86, 0x83, 0x01, 0x5D, 0x34, 0x4D, 0xCB, 0xFE,
|
||||
0xF6, 0xFB, 0x9A, 0xF4, 0xC6, 0xC4, 0x70, 0xBE,
|
||||
0x25, 0x45, 0x16, 0xCD, 0x3C, 0x1A, 0x1F, 0xB4,
|
||||
0x73, 0x62
|
||||
};
|
||||
static uint8_t pvx521_data[] = {
|
||||
0x01, 0xEB, 0xB3, 0x4D, 0xD7, 0x57, 0x21, 0xAB,
|
||||
0xF8, 0xAD, 0xC9, 0xDB, 0xED, 0x17, 0x88, 0x9C,
|
||||
0xBB, 0x97, 0x65, 0xD9, 0x0A, 0x7C, 0x60, 0xF2,
|
||||
0xCE, 0xF0, 0x07, 0xBB, 0x0F, 0x2B, 0x26, 0xE1,
|
||||
0x48, 0x81, 0xFD, 0x44, 0x42, 0xE6, 0x89, 0xD6,
|
||||
0x1C, 0xB2, 0xDD, 0x04, 0x6E, 0xE3, 0x0E, 0x3F,
|
||||
0xFD, 0x20, 0xF9, 0xA4, 0x5B, 0xBD, 0xF6, 0x41,
|
||||
0x3D, 0x58, 0x3A, 0x2D, 0xBF, 0x59, 0x92, 0x4F,
|
||||
0xD3, 0x5C
|
||||
};
|
||||
static uint8_t pvy521_data[] = {
|
||||
0x00, 0xF6, 0xB6, 0x32, 0xD1, 0x94, 0xC0, 0x38,
|
||||
0x8E, 0x22, 0xD8, 0x43, 0x7E, 0x55, 0x8C, 0x55,
|
||||
0x2A, 0xE1, 0x95, 0xAD, 0xFD, 0x15, 0x3F, 0x92,
|
||||
0xD7, 0x49, 0x08, 0x35, 0x1B, 0x2F, 0x8C, 0x4E,
|
||||
0xDA, 0x94, 0xED, 0xB0, 0x91, 0x6D, 0x1B, 0x53,
|
||||
0xC0, 0x20, 0xB5, 0xEE, 0xCA, 0xED, 0x1A, 0x5F,
|
||||
0xC3, 0x8A, 0x23, 0x3E, 0x48, 0x30, 0x58, 0x7B,
|
||||
0xB2, 0xEE, 0x34, 0x89, 0xB3, 0xB4, 0x2A, 0x5A,
|
||||
0x86, 0xA4
|
||||
};
|
||||
|
||||
zrtp_status_t zrtp_ecdh_selftest(zrtp_pk_scheme_t *self)
|
||||
{
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
struct BigNum P, Gx, Gy, n, sv;
|
||||
struct BigNum pkx, pky;
|
||||
unsigned ec_bytes = 0;
|
||||
unsigned pbits = 0;
|
||||
struct zrtp_ec_params ec_params;
|
||||
|
||||
zrtp_time_t start_ts = 0;
|
||||
|
||||
uint8_t *sv_data = NULL;
|
||||
size_t sv_data_len = 0;
|
||||
uint8_t *pvx_data = NULL;
|
||||
size_t pvx_data_len = 0;
|
||||
uint8_t *pvy_data = NULL;
|
||||
size_t pvy_data_len = 0;
|
||||
|
||||
if (!self) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_, "PKS %.4s testing... ", self->base.type));
|
||||
|
||||
switch (self->base.id) {
|
||||
case ZRTP_PKTYPE_EC256P:
|
||||
sv_data = sv256_data;
|
||||
sv_data_len = sizeof(sv256_data);
|
||||
pvx_data = pvx256_data;
|
||||
pvx_data_len = sizeof(pvx256_data);
|
||||
pvy_data = pvy256_data;
|
||||
pvy_data_len = sizeof(pvy256_data);
|
||||
break;
|
||||
case ZRTP_PKTYPE_EC384P:
|
||||
sv_data = sv384_data;
|
||||
sv_data_len = sizeof(sv384_data);
|
||||
pvx_data = pvx384_data;
|
||||
pvx_data_len = sizeof(pvx384_data);
|
||||
pvy_data = pvy384_data;
|
||||
pvy_data_len = sizeof(pvy384_data);
|
||||
break;
|
||||
case ZRTP_PKTYPE_EC521P:
|
||||
sv_data = sv521_data;
|
||||
sv_data_len = sizeof(sv521_data);
|
||||
pvx_data = pvx521_data;
|
||||
pvx_data_len = sizeof(pvx521_data);
|
||||
pvy_data = pvy521_data;
|
||||
pvy_data_len = sizeof(pvy521_data);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
pbits = get_pbits(self);
|
||||
if (!pbits) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
zrtp_ec_init_params(&ec_params, pbits);
|
||||
|
||||
ec_bytes = (ec_params.ec_bits+7) / 8;
|
||||
|
||||
bnBegin(&P);
|
||||
bnInsertBigBytes(&P, ec_params.P_data, 0, ec_bytes );
|
||||
bnBegin(&Gx);
|
||||
bnInsertBigBytes(&Gx, ec_params.Gx_data, 0, ec_bytes );
|
||||
bnBegin(&Gy);
|
||||
bnInsertBigBytes(&Gy, ec_params.Gy_data, 0, ec_bytes );
|
||||
bnBegin(&n);
|
||||
bnInsertBigBytes(&n, ec_params.n_data, 0, ec_bytes );
|
||||
|
||||
bnBegin(&pkx);
|
||||
bnBegin(&pky);
|
||||
bnBegin(&sv);
|
||||
s = zrtp_ec_random_point( self->base.zrtp, &P, &n, &Gx, &Gy,
|
||||
&pkx, &pky, &sv,
|
||||
sv_data, sv_data_len);
|
||||
if (zrtp_status_ok == s)
|
||||
{
|
||||
struct BigNum pkx1, pky1;
|
||||
|
||||
bnBegin(&pkx1); bnBegin(&pky1);
|
||||
bnInsertBigBytes(&pkx1, pvx_data, 0, pvx_data_len);
|
||||
bnInsertBigBytes(&pky1, pvy_data, 0, pvy_data_len);
|
||||
s = (bnCmp (&pkx1, &pkx) == 0 && bnCmp (&pky1, &pky) == 0) ? zrtp_status_ok : zrtp_status_fail;
|
||||
bnEnd(&pkx1);
|
||||
bnEnd(&pky1);
|
||||
}
|
||||
|
||||
bnEnd (&pkx);
|
||||
bnEnd (&pky);
|
||||
bnEnd (&P);
|
||||
bnEnd (&Gx);
|
||||
bnEnd (&Gy);
|
||||
bnEnd (&n);
|
||||
bnEnd (&sv);
|
||||
|
||||
if (zrtp_status_ok == s) {
|
||||
zrtp_status_t s = zrtp_status_ok;
|
||||
zrtp_dh_crypto_context_t alice_cc;
|
||||
zrtp_dh_crypto_context_t bob_cc;
|
||||
struct BigNum alice_k;
|
||||
struct BigNum bob_k;
|
||||
|
||||
start_ts = zrtp_time_now();
|
||||
|
||||
bnBegin(&alice_k);
|
||||
bnBegin(&bob_k);
|
||||
|
||||
do {
|
||||
/* Both sides initalise DH schemes and compute secret and public values. */
|
||||
s = self->initialize(self, &alice_cc);
|
||||
if (zrtp_status_ok != s) {
|
||||
break;
|
||||
}
|
||||
s = self->initialize(self, &bob_cc);
|
||||
if (zrtp_status_ok != s) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Both sides validate public values. (to provide exact performance estimation) */
|
||||
s = self->validate(self, &bob_cc.pv);
|
||||
if (zrtp_status_ok != s) {
|
||||
break;
|
||||
}
|
||||
s = self->validate(self, &alice_cc.pv);
|
||||
if (zrtp_status_ok != s) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Compute secret keys and compare them. */
|
||||
s = self->compute(self, &alice_cc, &alice_k, &bob_cc.pv);
|
||||
if (zrtp_status_ok != s) {
|
||||
break;
|
||||
}
|
||||
s= self->compute(self, &bob_cc, &bob_k, &alice_cc.pv);
|
||||
if (zrtp_status_ok != s) {
|
||||
break;
|
||||
}
|
||||
|
||||
s = (0 == bnCmp(&alice_k, &bob_k)) ? zrtp_status_ok : zrtp_status_algo_fail;
|
||||
} while (0);
|
||||
|
||||
bnEnd(&alice_k);
|
||||
bnEnd(&bob_k);
|
||||
}
|
||||
ZRTP_LOGC(3, ("%s (%llu ms)\n", zrtp_log_status2str(s), (zrtp_time_now()-start_ts)/2));
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/*============================================================================*/
|
||||
/* Public Key support */
|
||||
/*============================================================================*/
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
zrtp_status_t zrtp_defaults_ec_pkt(zrtp_global_t* zrtp)
|
||||
{
|
||||
zrtp_pk_scheme_t* ec256p = zrtp_sys_alloc(sizeof(zrtp_pk_scheme_t));
|
||||
zrtp_pk_scheme_t* ec384p = zrtp_sys_alloc(sizeof(zrtp_pk_scheme_t));
|
||||
zrtp_pk_scheme_t* ec521p = zrtp_sys_alloc(sizeof(zrtp_pk_scheme_t));
|
||||
|
||||
if (!ec256p || !ec384p || !ec521p) {
|
||||
if(ec256p) {
|
||||
zrtp_sys_free(ec256p);
|
||||
}
|
||||
if(ec384p) {
|
||||
zrtp_sys_free(ec384p);
|
||||
}
|
||||
if(ec521p) {
|
||||
zrtp_sys_free(ec521p);
|
||||
}
|
||||
return zrtp_status_alloc_fail;
|
||||
}
|
||||
|
||||
zrtp_memset(ec256p, 0, sizeof(zrtp_pk_scheme_t));
|
||||
zrtp_memcpy(ec256p->base.type, ZRTP_EC256P, ZRTP_COMP_TYPE_SIZE);
|
||||
ec256p->base.id = ZRTP_PKTYPE_EC256P;
|
||||
ec256p->base.zrtp = zrtp;
|
||||
ec256p->sv_length = 256/8;
|
||||
ec256p->pv_length = 2*256/8;
|
||||
ec256p->base.init = zrtp_ecdh_init;
|
||||
ec256p->base.free = zrtp_ecdh_free;
|
||||
ec256p->initialize = zrtp_ecdh_initialize;
|
||||
ec256p->compute = zrtp_ecdh_compute;
|
||||
ec256p->validate = zrtp_ecdh_validate;
|
||||
ec256p->self_test = zrtp_ecdh_selftest;
|
||||
|
||||
zrtp_memset(ec384p, 0, sizeof(zrtp_pk_scheme_t));
|
||||
zrtp_memcpy(ec384p->base.type, ZRTP_EC384P, ZRTP_COMP_TYPE_SIZE);
|
||||
ec384p->base.id = ZRTP_PKTYPE_EC384P;
|
||||
ec384p->base.zrtp = zrtp;
|
||||
ec384p->sv_length = 384/8;
|
||||
ec384p->pv_length = 2*384/8;
|
||||
ec384p->base.init = zrtp_ecdh_init;
|
||||
ec384p->base.free = zrtp_ecdh_free;
|
||||
ec384p->initialize = zrtp_ecdh_initialize;
|
||||
ec384p->compute = zrtp_ecdh_compute;
|
||||
ec384p->validate = zrtp_ecdh_validate;
|
||||
ec384p->self_test = zrtp_ecdh_selftest;
|
||||
|
||||
|
||||
zrtp_memset(ec521p, 0, sizeof(zrtp_pk_scheme_t));
|
||||
zrtp_memcpy(ec521p->base.type, ZRTP_EC521P, ZRTP_COMP_TYPE_SIZE);
|
||||
ec521p->base.id = ZRTP_PKTYPE_EC521P;
|
||||
ec521p->base.zrtp = zrtp;
|
||||
ec521p->sv_length = 528/8;
|
||||
ec521p->pv_length = 2*528/8;
|
||||
ec521p->base.init = zrtp_ecdh_init;
|
||||
ec521p->base.free = zrtp_ecdh_free;
|
||||
ec521p->initialize = zrtp_ecdh_initialize;
|
||||
ec521p->compute = zrtp_ecdh_compute;
|
||||
ec521p->validate = zrtp_ecdh_validate;
|
||||
ec521p->self_test = zrtp_ecdh_selftest;
|
||||
|
||||
zrtp_comp_register(ZRTP_CC_PKT, ec256p, zrtp);
|
||||
zrtp_comp_register(ZRTP_CC_PKT, ec384p, zrtp);
|
||||
zrtp_comp_register(ZRTP_CC_PKT, ec521p, zrtp);
|
||||
|
||||
return zrtp_status_ok;
|
||||
}
|
642
libs/libzrtp/src/zrtp_crypto_ecdsa.c
Normal file
642
libs/libzrtp/src/zrtp_crypto_ecdsa.c
Normal file
@ -0,0 +1,642 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*/
|
||||
|
||||
#include "zrtp.h"
|
||||
|
||||
/* We don't have digital signatures ready yet. */
|
||||
#if 0
|
||||
|
||||
/* Size of extra random data to approximate a uniform distribution mod n */
|
||||
#define UNIFORMBYTES 8
|
||||
|
||||
/*============================================================================*/
|
||||
/* Shared Elliptic Curve functions */
|
||||
/* */
|
||||
/* The Elliptic Curve DSA algorithm, key generation, and curves are */
|
||||
/* from FIPS 186-3. The curves used are */
|
||||
/* also defined in RFC 4753, sections 3.1 through 3.3. */
|
||||
/*============================================================================*/
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Return dsa_cc->pv holding public value and dsa_cc->sv holding secret value */
|
||||
/* The public value is an elliptic curve point encoded as the x part shifted */
|
||||
/* left Pbits bits and or'd with the y part. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t ECDSA_keygen( struct zrtp_sig_scheme *self,
|
||||
zrtp_dsa_crypto_context_t *dsa_cc,
|
||||
zrtp_ec_params_t *ec_params,
|
||||
#ifdef ZRTP_TEST_VECTORS
|
||||
uint8_t *sv_data, size_t sv_data_len,
|
||||
uint8_t *pvx_data, size_t pvx_data_len,
|
||||
uint8_t *pvy_data, size_t pvy_data_len,
|
||||
#endif
|
||||
unsigned Pbits )
|
||||
{
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
struct BigNum P, Gx, Gy, n;
|
||||
struct BigNum pkx, pky;
|
||||
unsigned ec_bytes;
|
||||
|
||||
if (!ec_params)
|
||||
return zrtp_status_bad_param;
|
||||
|
||||
ec_bytes = (ec_params->ec_bits+7) / 8;
|
||||
|
||||
do
|
||||
{
|
||||
if (!self || !dsa_cc)
|
||||
{
|
||||
s = zrtp_status_bad_param;
|
||||
break;
|
||||
}
|
||||
|
||||
bnBegin(&P);
|
||||
bnInsertBigBytes( &P, ec_params->P_data, 0, ec_bytes );
|
||||
bnBegin(&Gx);
|
||||
bnInsertBigBytes( &Gx, ec_params->Gx_data, 0, ec_bytes );
|
||||
bnBegin(&Gy);
|
||||
bnInsertBigBytes( &Gy, ec_params->Gy_data, 0, ec_bytes );
|
||||
bnBegin(&n);
|
||||
bnInsertBigBytes( &n, ec_params->n_data, 0, ec_bytes );
|
||||
|
||||
bnBegin(&pkx);
|
||||
bnBegin(&pky);
|
||||
bnBegin(&dsa_cc->sv);
|
||||
s = zrtp_ec_random_point( self->base.zrtp_global, &P, &n, &Gx, &Gy,
|
||||
#ifdef ZRTP_TEST_VECTORS
|
||||
sv_data, sv_data_len,
|
||||
pvx_data, pvx_data_len,
|
||||
pvy_data, pvy_data_len,
|
||||
#endif
|
||||
&pkx, &pky, &dsa_cc->sv );
|
||||
if ( s != zrtp_status_ok )
|
||||
break;
|
||||
s = zrtp_status_fail;
|
||||
|
||||
bnBegin(&dsa_cc->pv);
|
||||
bnCopy (&dsa_cc->pv, &pkx);
|
||||
bnLShift (&dsa_cc->pv, Pbits);
|
||||
bnAdd (&dsa_cc->pv, &pky);
|
||||
bnEnd (&pkx);
|
||||
bnEnd (&pky);
|
||||
bnEnd (&P);
|
||||
bnEnd (&Gx);
|
||||
bnEnd (&Gy);
|
||||
bnEnd (&n);
|
||||
|
||||
s = zrtp_status_ok;
|
||||
} while (0);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Sign the specified hash value - must be size matching the curve */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t ECDSA_sign( struct zrtp_sig_scheme *self,
|
||||
zrtp_dsa_crypto_context_t *dsa_cc,
|
||||
zrtp_ec_params_t *ec_params,
|
||||
#ifdef ZRTP_TEST_VECTORS
|
||||
uint8_t *k_data, size_t k_data_len,
|
||||
uint8_t *rx_data, size_t rx_data_len,
|
||||
uint8_t *ry_data, size_t ry_data_len,
|
||||
uint8_t *s_data, size_t s_data_len,
|
||||
#endif
|
||||
uint8_t *hash, uint32_t hash_len,
|
||||
struct BigNum *dsasig )
|
||||
{
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
struct BigNum P, Gx, Gy, n;
|
||||
struct BigNum h, s1, k, rx, ry, kinv, pkx, pky;
|
||||
unsigned ec_bytes;
|
||||
|
||||
if (!ec_params)
|
||||
return zrtp_status_bad_param;
|
||||
|
||||
ec_bytes = (ec_params->ec_bits+7) / 8;
|
||||
|
||||
do
|
||||
{
|
||||
if (!self || !dsa_cc)
|
||||
{
|
||||
s = zrtp_status_bad_param;
|
||||
break;
|
||||
}
|
||||
|
||||
bnBegin(&P);
|
||||
bnInsertBigBytes( &P, ec_params->P_data, 0, ec_bytes );
|
||||
bnBegin(&Gx);
|
||||
bnInsertBigBytes( &Gx, ec_params->Gx_data, 0, ec_bytes );
|
||||
bnBegin(&Gy);
|
||||
bnInsertBigBytes( &Gy, ec_params->Gy_data, 0, ec_bytes );
|
||||
bnBegin(&n);
|
||||
bnInsertBigBytes( &n, ec_params->n_data, 0, ec_bytes );
|
||||
|
||||
/* Hash to bignum */
|
||||
bnBegin(&h);
|
||||
bnInsertBigBytes( &h, hash, 0, hash_len );
|
||||
bnMod (&h, &h, &P);
|
||||
|
||||
/* Unpack signing key */
|
||||
bnBegin(&pkx);
|
||||
bnBegin(&pky);
|
||||
bnSetQ (&pkx, 1);
|
||||
bnLShift (&pkx, ec_bytes*8);
|
||||
bnMod (&pky, &dsa_cc->pv, &pkx);
|
||||
bnCopy (&pkx, &dsa_cc->pv);
|
||||
bnRShift (&pkx, ec_bytes*8);
|
||||
|
||||
/* Choose signature secret k value */
|
||||
bnBegin(&rx);
|
||||
bnBegin(&ry);
|
||||
bnBegin(&k);
|
||||
s = zrtp_ec_random_point( self->base.zrtp_global, &P, &n, &Gx, &Gy,
|
||||
#ifdef ZRTP_TEST_VECTORS
|
||||
k_data, k_data_len,
|
||||
rx_data, rx_data_len,
|
||||
ry_data, ry_data_len,
|
||||
#endif
|
||||
&rx, &ry, &k );
|
||||
if ( s != zrtp_status_ok )
|
||||
break;
|
||||
s = zrtp_status_fail;
|
||||
|
||||
#ifndef ZRTP_TEST_VECTORS
|
||||
/* For further randomness we are going to add the secret key to k */
|
||||
bnAddMod_ (&k, &dsa_cc->sv, &n);
|
||||
zrtp_ecAdd (&rx, &ry, &rx, &ry, &pkx, &pky, &P);
|
||||
#endif
|
||||
|
||||
/* Perform the signature */
|
||||
bnBegin (&s1);
|
||||
bnMulMod_ (&s1, &rx, &dsa_cc->sv, &n);
|
||||
bnAddMod_ (&s1, &h, &n);
|
||||
bnBegin (&kinv);
|
||||
bnInv (&kinv, &k, &n);
|
||||
bnMulMod_ (&s1, &s1, &kinv, &n);
|
||||
|
||||
#ifdef ZRTP_TEST_VECTORS
|
||||
if (k_data_len != 0)
|
||||
{
|
||||
/* rx is checked in ec_random_point */
|
||||
struct BigNum s2;
|
||||
int ok;
|
||||
bnBegin(&s2);
|
||||
bnInsertBigBytes(&s2, s_data, 0, s_data_len);
|
||||
ok = (bnCmp (&s1, &s2) == 0);
|
||||
bnEnd(&s2);
|
||||
if (!ok)
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Combine r, s into dsasig */
|
||||
bnBegin(dsasig);
|
||||
bnCopy (dsasig, &rx);
|
||||
bnLShift (dsasig, ec_bytes*8);
|
||||
bnAdd (dsasig, &s1);
|
||||
bnEnd (&rx);
|
||||
bnEnd (&ry);
|
||||
bnEnd (&k);
|
||||
bnEnd (&kinv);
|
||||
bnEnd (&s1);
|
||||
bnEnd (&h);
|
||||
bnEnd (&pkx);
|
||||
bnEnd (&pky);
|
||||
bnEnd (&P);
|
||||
bnEnd (&Gx);
|
||||
bnEnd (&Gy);
|
||||
bnEnd (&n);
|
||||
|
||||
s = zrtp_status_ok;
|
||||
} while (0);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Verify a signature value - hash must be size matching the curve */
|
||||
/* Signing key should be in peer_pv entry of dsa_cc */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t ECDSA_verify( struct zrtp_sig_scheme *self,
|
||||
zrtp_dsa_crypto_context_t *dsa_cc,
|
||||
zrtp_ec_params_t *ec_params,
|
||||
uint8_t *hash, uint32_t hash_len,
|
||||
struct BigNum *dsasig )
|
||||
{
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
struct BigNum P, Gx, Gy, n;
|
||||
struct BigNum rx, ry, pkx, pky, r, s1, sinv, u1, u2, u1x, u2x, u1y, u2y, h;
|
||||
unsigned ec_bytes;
|
||||
|
||||
if (!ec_params)
|
||||
return zrtp_status_bad_param;
|
||||
|
||||
ec_bytes = (ec_params->ec_bits+7) / 8;
|
||||
|
||||
do
|
||||
{
|
||||
if (!self || !dsa_cc)
|
||||
{
|
||||
s = zrtp_status_bad_param;
|
||||
break;
|
||||
}
|
||||
|
||||
bnBegin(&P);
|
||||
bnInsertBigBytes( &P, ec_params->P_data, 0, ec_bytes );
|
||||
bnBegin(&Gx);
|
||||
bnInsertBigBytes( &Gx, ec_params->Gx_data, 0, ec_bytes );
|
||||
bnBegin(&Gy);
|
||||
bnInsertBigBytes( &Gy, ec_params->Gy_data, 0, ec_bytes );
|
||||
bnBegin(&n);
|
||||
bnInsertBigBytes( &n, ec_params->n_data, 0, ec_bytes );
|
||||
|
||||
/* hash */
|
||||
bnBegin(&h);
|
||||
bnInsertBigBytes( &h, hash, 0, hash_len );
|
||||
bnMod (&h, &h, &P);
|
||||
|
||||
/* Unpack sig */
|
||||
bnBegin(&r);
|
||||
bnBegin(&s1);
|
||||
bnSetQ (&r, 1);
|
||||
bnLShift (&r, ec_bytes*8);
|
||||
bnMod (&s1, dsasig, &r);
|
||||
bnCopy (&r, dsasig);
|
||||
bnRShift (&r, ec_bytes*8);
|
||||
|
||||
/* Unpack signing key */
|
||||
bnBegin(&pkx);
|
||||
bnBegin(&pky);
|
||||
bnSetQ (&pkx, 1);
|
||||
bnLShift (&pkx, ec_bytes*8);
|
||||
bnMod (&pky, &dsa_cc->peer_pv, &pkx);
|
||||
bnCopy (&pkx, &dsa_cc->peer_pv);
|
||||
bnRShift (&pkx, ec_bytes*8);
|
||||
|
||||
/* Verify signature */
|
||||
bnBegin (&sinv);
|
||||
bnInv (&sinv, &s1, &n);
|
||||
bnBegin (&u1);
|
||||
bnBegin (&u2);
|
||||
bnMulMod_ (&u1, &sinv, &h, &n);
|
||||
bnMulMod_ (&u2, &sinv, &r, &n);
|
||||
|
||||
bnBegin (&u1x);
|
||||
bnBegin (&u1y);
|
||||
bnBegin (&u2x);
|
||||
bnBegin (&u2y);
|
||||
bnBegin (&rx);
|
||||
bnBegin (&ry);
|
||||
zrtp_ecMul (&u1x, &u1y, &u1, &Gx, &Gy, &P);
|
||||
zrtp_ecMul (&u2x, &u2y, &u2, &pkx, &pky, &P);
|
||||
zrtp_ecAdd (&rx, &ry, &u1x, &u1y, &u2x, &u2y, &P);
|
||||
|
||||
if (bnCmp (&rx, &r) == 0) {
|
||||
s = zrtp_status_ok;
|
||||
} else {
|
||||
s = zrtp_status_fail;
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
bnEnd (&rx);
|
||||
bnEnd (&ry);
|
||||
bnEnd (&r);
|
||||
bnEnd (&s1);
|
||||
bnEnd (&sinv);
|
||||
bnEnd (&u1);
|
||||
bnEnd (&u1x);
|
||||
bnEnd (&u1y);
|
||||
bnEnd (&u2);
|
||||
bnEnd (&u2x);
|
||||
bnEnd (&u2y);
|
||||
bnEnd (&h);
|
||||
bnEnd (&pkx);
|
||||
bnEnd (&pky);
|
||||
bnEnd (&P);
|
||||
bnEnd (&Gx);
|
||||
bnEnd (&Gy);
|
||||
bnEnd (&n);
|
||||
|
||||
} while (0);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t EC_dummy(void *s)
|
||||
{
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
|
||||
/*============================================================================*/
|
||||
/* P-256 (FIPS 186-3) support. See RFC 4753, section 3.1. */
|
||||
/*============================================================================*/
|
||||
|
||||
/* Test vectors from RFC4754 */
|
||||
#ifdef ZRTP_TEST_VECTORS
|
||||
static uint8_t sv256_data[] = {
|
||||
0xDC, 0x51, 0xD3, 0x86, 0x6A, 0x15, 0xBA, 0xCD,
|
||||
0xE3, 0x3D, 0x96, 0xF9, 0x92, 0xFC, 0xA9, 0x9D,
|
||||
0xA7, 0xE6, 0xEF, 0x09, 0x34, 0xE7, 0x09, 0x75,
|
||||
0x59, 0xC2, 0x7F, 0x16, 0x14, 0xC8, 0x8A, 0x7F,
|
||||
};
|
||||
static uint8_t pvx256_data[] = {
|
||||
0x24, 0x42, 0xA5, 0xCC, 0x0E, 0xCD, 0x01, 0x5F,
|
||||
0xA3, 0xCA, 0x31, 0xDC, 0x8E, 0x2B, 0xBC, 0x70,
|
||||
0xBF, 0x42, 0xD6, 0x0C, 0xBC, 0xA2, 0x00, 0x85,
|
||||
0xE0, 0x82, 0x2C, 0xB0, 0x42, 0x35, 0xE9, 0x70,
|
||||
};
|
||||
static uint8_t pvy256_data[] = {
|
||||
0x6F, 0xC9, 0x8B, 0xD7, 0xE5, 0x02, 0x11, 0xA4,
|
||||
0xA2, 0x71, 0x02, 0xFA, 0x35, 0x49, 0xDF, 0x79,
|
||||
0xEB, 0xCB, 0x4B, 0xF2, 0x46, 0xB8, 0x09, 0x45,
|
||||
0xCD, 0xDF, 0xE7, 0xD5, 0x09, 0xBB, 0xFD, 0x7D,
|
||||
};
|
||||
|
||||
static uint8_t k256_data[] = {
|
||||
0x9E, 0x56, 0xF5, 0x09, 0x19, 0x67, 0x84, 0xD9,
|
||||
0x63, 0xD1, 0xC0, 0xA4, 0x01, 0x51, 0x0E, 0xE7,
|
||||
0xAD, 0xA3, 0xDC, 0xC5, 0xDE, 0xE0, 0x4B, 0x15,
|
||||
0x4B, 0xF6, 0x1A, 0xF1, 0xD5, 0xA6, 0xDE, 0xCE,
|
||||
};
|
||||
static uint8_t rx256_data[] = {
|
||||
0xCB, 0x28, 0xE0, 0x99, 0x9B, 0x9C, 0x77, 0x15,
|
||||
0xFD, 0x0A, 0x80, 0xD8, 0xE4, 0x7A, 0x77, 0x07,
|
||||
0x97, 0x16, 0xCB, 0xBF, 0x91, 0x7D, 0xD7, 0x2E,
|
||||
0x97, 0x56, 0x6E, 0xA1, 0xC0, 0x66, 0x95, 0x7C,
|
||||
};
|
||||
static uint8_t ry256_data[] = {
|
||||
0x2B, 0x57, 0xC0, 0x23, 0x5F, 0xB7, 0x48, 0x97,
|
||||
0x68, 0xD0, 0x58, 0xFF, 0x49, 0x11, 0xC2, 0x0F,
|
||||
0xDB, 0xE7, 0x1E, 0x36, 0x99, 0xD9, 0x13, 0x39,
|
||||
0xAF, 0xBB, 0x90, 0x3E, 0xE1, 0x72, 0x55, 0xDC,
|
||||
};
|
||||
|
||||
static uint8_t h256_data[] = {
|
||||
0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA,
|
||||
0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23,
|
||||
0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C,
|
||||
0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD,
|
||||
};
|
||||
static uint8_t s256_data[] = {
|
||||
0x86, 0xFA, 0x3B, 0xB4, 0xE2, 0x6C, 0xAD, 0x5B,
|
||||
0xF9, 0x0B, 0x7F, 0x81, 0x89, 0x92, 0x56, 0xCE,
|
||||
0x75, 0x94, 0xBB, 0x1E, 0xA0, 0xC8, 0x92, 0x12,
|
||||
0x74, 0x8B, 0xFF, 0x3B, 0x3D, 0x5B, 0x03, 0x15,
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Return dsa_cc->pv holding public value and dsa_cc->sv holding secret value */
|
||||
/* The public value is an elliptic curve point encoded as the x part shifted */
|
||||
/* left 256 bits and or'd with the y part. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t EC256P_keygen( struct zrtp_sig_scheme *self,
|
||||
zrtp_dsa_crypto_context_t *dsa_cc )
|
||||
{
|
||||
struct zrtp_ec_params params;
|
||||
zrtp_ec_init_params(¶ms, 256);
|
||||
return ECDSA_keygen(self, dsa_cc, ¶ms,
|
||||
#ifdef ZRTP_TEST_VECTORS
|
||||
sv256_data, sizeof(sv256_data),
|
||||
pvx256_data, sizeof(pvx256_data),
|
||||
pvy256_data, sizeof(pvy256_data),
|
||||
#endif
|
||||
256);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Sign the specified hash value */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t EC256P_sign( struct zrtp_sig_scheme *self,
|
||||
zrtp_dsa_crypto_context_t *dsa_cc,
|
||||
uint8_t *hash, uint32_t hash_len,
|
||||
struct BigNum *dsasig )
|
||||
{
|
||||
struct zrtp_ec_params params;
|
||||
zrtp_ec_init_params(¶ms, 256);
|
||||
return ECDSA_sign(self, dsa_cc, ¶ms,
|
||||
#ifdef ZRTP_TEST_VECTORS
|
||||
k256_data, sizeof(k256_data),
|
||||
rx256_data, sizeof(rx256_data),
|
||||
ry256_data, sizeof(ry256_data),
|
||||
s256_data, sizeof(s256_data),
|
||||
h256_data, sizeof(h256_data),
|
||||
#else
|
||||
hash, hash_len,
|
||||
#endif
|
||||
dsasig);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Verify the signature on the hash value */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t EC256P_verify(struct zrtp_sig_scheme *self,
|
||||
zrtp_dsa_crypto_context_t *dsa_cc,
|
||||
uint8_t *hash, uint32_t hash_len,
|
||||
struct BigNum *dsasig )
|
||||
{
|
||||
struct zrtp_ec_params params;
|
||||
zrtp_ec_init_params(¶ms, 256);
|
||||
return ECDSA_verify(self, dsa_cc, ¶ms,
|
||||
#ifdef ZRTP_TEST_VECTORS
|
||||
h256_data, sizeof(h256_data),
|
||||
#else
|
||||
hash, hash_len,
|
||||
#endif
|
||||
dsasig);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*============================================================================*/
|
||||
/* P-384 (FIPS 186-3) support. See RFC 4753, section 3.2. */
|
||||
/*============================================================================*/
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Return dsa_cc->pv holding public value and dsa_cc->sv holding secret value */
|
||||
/* The public value is an elliptic curve point encoded as the x part shifted */
|
||||
/* left 384 bits and or'd with the y part. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t EC384P_keygen( struct zrtp_sig_scheme *self,
|
||||
zrtp_dsa_crypto_context_t *dsa_cc )
|
||||
{
|
||||
struct zrtp_ec_params params;
|
||||
zrtp_ec_init_params(¶ms, 384);
|
||||
return ECDSA_keygen(self, dsa_cc, ¶ms,
|
||||
#ifdef ZRTP_TEST_VECTORS
|
||||
0, 0, 0, 0, 0, 0,
|
||||
#endif
|
||||
384);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Sign the specified hash value */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t EC384P_sign( struct zrtp_sig_scheme *self,
|
||||
zrtp_dsa_crypto_context_t *dsa_cc,
|
||||
uint8_t *hash, uint32_t hash_len,
|
||||
struct BigNum *dsasig )
|
||||
{
|
||||
struct zrtp_ec_params params;
|
||||
zrtp_ec_init_params(¶ms, 384);
|
||||
return ECDSA_sign(self, dsa_cc, ¶ms,
|
||||
#ifdef ZRTP_TEST_VECTORS
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
#endif
|
||||
hash, hash_len, dsasig);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Verify the signature on the hash value */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t EC384P_verify(struct zrtp_sig_scheme *self,
|
||||
zrtp_dsa_crypto_context_t *dsa_cc,
|
||||
uint8_t *hash, uint32_t hash_len,
|
||||
struct BigNum *dsasig )
|
||||
{
|
||||
struct zrtp_ec_params params;
|
||||
zrtp_ec_init_params(¶ms, 384);
|
||||
return ECDSA_verify(self, dsa_cc, ¶ms, hash, hash_len, dsasig);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*============================================================================*/
|
||||
/* P-521 (FIPS 186-3) support. See RFC 4753, section 3.3. */
|
||||
/*============================================================================*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Return dsa_cc->pv holding public value and dsa_cc->sv holding secret value */
|
||||
/* The public value is an elliptic curve point encoded as the x part shifted */
|
||||
/* left 528 bits (note, not 521) and or'd with the y part. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t EC521P_keygen( struct zrtp_sig_scheme *self,
|
||||
zrtp_dsa_crypto_context_t *dsa_cc )
|
||||
{
|
||||
struct zrtp_ec_params params;
|
||||
zrtp_ec_init_params(¶ms, 521);
|
||||
return ECDSA_keygen(self, dsa_cc, ¶ms,
|
||||
#ifdef ZRTP_TEST_VECTORS
|
||||
0, 0, 0, 0, 0, 0,
|
||||
#endif
|
||||
528);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Sign the specified hash value */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t EC521P_sign( struct zrtp_sig_scheme *self,
|
||||
zrtp_dsa_crypto_context_t *dsa_cc,
|
||||
uint8_t *hash, uint32_t hash_len,
|
||||
struct BigNum *dsasig )
|
||||
{
|
||||
struct zrtp_ec_params params;
|
||||
zrtp_ec_init_params(¶ms, 521);
|
||||
return ECDSA_sign(self, dsa_cc, ¶ms,
|
||||
#ifdef ZRTP_TEST_VECTORS
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
#endif
|
||||
hash, hash_len, dsasig);
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Verify the signature on the hash value */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t EC521P_verify(struct zrtp_sig_scheme *self,
|
||||
zrtp_dsa_crypto_context_t *dsa_cc,
|
||||
uint8_t *hash, uint32_t hash_len,
|
||||
struct BigNum *dsasig )
|
||||
{
|
||||
struct zrtp_ec_params params;
|
||||
zrtp_ec_init_params(¶ms, 521);
|
||||
return ECDSA_verify(self, dsa_cc, ¶ms, hash, hash_len, dsasig);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*============================================================================*/
|
||||
/* Public Key support */
|
||||
/*============================================================================*/
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
zrtp_status_t zrtp_defaults_sig(zrtp_global_ctx_t* zrtp_global)
|
||||
{
|
||||
zrtp_sig_scheme_t* ec256p = zrtp_sys_alloc(sizeof(zrtp_sig_scheme_t));
|
||||
zrtp_sig_scheme_t* ec384p = zrtp_sys_alloc(sizeof(zrtp_sig_scheme_t));
|
||||
zrtp_sig_scheme_t* ec521p = zrtp_sys_alloc(sizeof(zrtp_sig_scheme_t));
|
||||
|
||||
if (!ec256p || !ec384p || !ec521p)
|
||||
{
|
||||
if(ec256p) zrtp_sys_free(ec256p);
|
||||
if(ec384p) zrtp_sys_free(ec384p);
|
||||
if(ec521p) zrtp_sys_free(ec521p);
|
||||
return zrtp_status_alloc_fail;
|
||||
}
|
||||
|
||||
zrtp_memset(ec256p, 0, sizeof(zrtp_sig_scheme_t));
|
||||
zrtp_memcpy(ec256p->base.type, ZRTP_EC256P, ZRTP_COMP_TYPE_SIZE);
|
||||
ec256p->base.id = ZRTP_SIGTYPE_EC256P;
|
||||
ec256p->base.zrtp_global = zrtp_global;
|
||||
ec256p->sv_length = 256/8;
|
||||
ec256p->pv_length = 2*256/8;
|
||||
ec256p->base.init = EC_dummy;
|
||||
ec256p->base.free = EC_dummy;
|
||||
ec256p->generate_key = EC256P_keygen;
|
||||
ec256p->sign = EC256P_sign;
|
||||
ec256p->verify = EC256P_verify;
|
||||
|
||||
zrtp_memset(ec384p, 0, sizeof(zrtp_sig_scheme_t));
|
||||
zrtp_memcpy(ec384p->base.type, ZRTP_EC384P, ZRTP_COMP_TYPE_SIZE);
|
||||
ec384p->base.id = ZRTP_SIGTYPE_EC384P;
|
||||
ec384p->base.zrtp_global = zrtp_global;
|
||||
ec384p->sv_length = 384/8;
|
||||
ec384p->pv_length = 2*384/8;
|
||||
ec384p->base.init = EC_dummy;
|
||||
ec384p->base.free = EC_dummy;
|
||||
ec384p->generate_key = EC384P_keygen;
|
||||
ec384p->sign = EC384P_sign;
|
||||
ec384p->verify = EC384P_verify;
|
||||
|
||||
zrtp_memset(ec521p, 0, sizeof(zrtp_sig_scheme_t));
|
||||
zrtp_memcpy(ec521p->base.type, ZRTP_EC521P, ZRTP_COMP_TYPE_SIZE);
|
||||
ec521p->base.id = ZRTP_SIGTYPE_EC521P;
|
||||
ec521p->base.zrtp_global = zrtp_global;
|
||||
ec521p->sv_length = 528/8;
|
||||
ec521p->pv_length = 2*528/8;
|
||||
ec521p->base.init = EC_dummy;
|
||||
ec521p->base.free = EC_dummy;
|
||||
ec521p->generate_key = EC521P_keygen;
|
||||
ec521p->sign = EC521P_sign;
|
||||
ec521p->verify = EC521P_verify;
|
||||
|
||||
zrtp_register_comp(ZRTP_CC_SIG, ec256p, zrtp_global);
|
||||
zrtp_register_comp(ZRTP_CC_SIG, ec384p, zrtp_global);
|
||||
zrtp_register_comp(ZRTP_CC_SIG, ec521p, zrtp_global);
|
||||
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
#endif /* don't have disgital signature ready for the moment*/
|
@ -214,9 +214,7 @@ static zrtp_status_t zrtp_dh_self_test(zrtp_pk_scheme_t *self)
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#if (defined(ZRTP_ENABLE_EC) && (ZRTP_ENABLE_EC == 1))
|
||||
extern zrtp_status_t zrtp_defaults_ec_pkt(zrtp_global_t* zrtp);
|
||||
#endif
|
||||
|
||||
zrtp_status_t zrtp_defaults_pkt(zrtp_global_t* zrtp)
|
||||
{
|
||||
@ -329,11 +327,7 @@ zrtp_status_t zrtp_defaults_pkt(zrtp_global_t* zrtp)
|
||||
presh->base.id = ZRTP_PKTYPE_PRESH;
|
||||
zrtp_comp_register(ZRTP_CC_PKT, presh, zrtp);
|
||||
|
||||
#if (defined(ZRTP_ENABLE_EC) && (ZRTP_ENABLE_EC == 1))
|
||||
return zrtp_defaults_ec_pkt(zrtp);
|
||||
#else
|
||||
return zrtp_status_ok;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
@ -56,7 +56,6 @@ static zrtp_status_t zrtp_cache_user_down();
|
||||
return zrtp_status_bad_param; \
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
zrtp_status_t zrtp_def_cache_init(zrtp_global_t* a_zrtp)
|
||||
{
|
||||
zrtp_status_t s = zrtp_status_ok;
|
||||
@ -83,7 +82,9 @@ void zrtp_def_cache_down()
|
||||
if (inited) {
|
||||
mlist_t *node = NULL, *tmp = NULL;
|
||||
|
||||
zrtp_cache_user_down();
|
||||
/* If automatic cache flushing enabled we don't need to store it in a disk as it should be already in sync. */
|
||||
if (!zrtp->cache_auto_store)
|
||||
zrtp_cache_user_down();
|
||||
|
||||
mlist_for_each_safe(node, tmp, &cache_head) {
|
||||
zrtp_sys_free(mlist_get_struct(zrtp_cache_elem_t, _mlist, node));
|
||||
@ -102,7 +103,7 @@ void zrtp_def_cache_down()
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
zrtp_status_t zrtp_def_cache_set_verified( const zrtp_stringn_t* one_ZID,
|
||||
const zrtp_stringn_t* another_ZID,
|
||||
uint32_t verified)
|
||||
@ -117,9 +118,11 @@ zrtp_status_t zrtp_def_cache_set_verified( const zrtp_stringn_t* one_ZID,
|
||||
new_elem = get_elem(id, 0);
|
||||
if (new_elem) {
|
||||
new_elem->verified = verified;
|
||||
}
|
||||
}
|
||||
zrtp_mutex_unlock(def_cache_protector);
|
||||
|
||||
if (zrtp->cache_auto_store) zrtp_def_cache_store(zrtp);
|
||||
|
||||
return (new_elem) ? zrtp_status_ok : zrtp_status_fail;
|
||||
}
|
||||
|
||||
@ -145,7 +148,6 @@ zrtp_status_t zrtp_def_cache_get_verified( const zrtp_stringn_t* one_ZID,
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t cache_put( const zrtp_stringn_t* one_ZID,
|
||||
const zrtp_stringn_t* another_ZID,
|
||||
zrtp_shared_secret_t *rss,
|
||||
@ -213,6 +215,8 @@ static zrtp_status_t cache_put( const zrtp_stringn_t* one_ZID,
|
||||
} while (0);
|
||||
zrtp_mutex_unlock(def_cache_protector);
|
||||
|
||||
if (zrtp->cache_auto_store) zrtp_def_cache_store(zrtp);
|
||||
|
||||
return (new_elem) ? zrtp_status_ok : zrtp_status_fail;
|
||||
}
|
||||
|
||||
@ -229,7 +233,6 @@ zrtp_status_t zrtp_def_cache_put_mitm( const zrtp_stringn_t* one_ZID,
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t cache_get( const zrtp_stringn_t* one_ZID,
|
||||
const zrtp_stringn_t* another_ZID,
|
||||
zrtp_shared_secret_t *rss,
|
||||
@ -288,7 +291,6 @@ zrtp_status_t zrtp_def_cache_get_mitm( const zrtp_stringn_t* one_ZID,
|
||||
return cache_get(one_ZID, another_ZID, rss, 0, 1);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
zrtp_status_t zrtp_def_cache_set_presh_counter( const zrtp_stringn_t* one_zid,
|
||||
const zrtp_stringn_t* another_zid,
|
||||
uint32_t counter)
|
||||
@ -308,6 +310,8 @@ zrtp_status_t zrtp_def_cache_set_presh_counter( const zrtp_stringn_t* one_zid,
|
||||
}
|
||||
zrtp_mutex_unlock(def_cache_protector);
|
||||
|
||||
if (zrtp->cache_auto_store) zrtp_def_cache_store(zrtp);
|
||||
|
||||
return (new_elem) ? zrtp_status_ok : zrtp_status_fail;
|
||||
}
|
||||
|
||||
@ -331,7 +335,6 @@ zrtp_status_t zrtp_def_cache_get_presh_counter( const zrtp_stringn_t* one_zid,
|
||||
return (new_elem) ? zrtp_status_ok : zrtp_status_fail;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
void zrtp_cache_create_id( const zrtp_stringn_t* first_ZID,
|
||||
const zrtp_stringn_t* second_ZID,
|
||||
zrtp_cache_id_t id )
|
||||
@ -346,13 +349,12 @@ zrtp_status_t zrtp_def_cache_get_presh_counter( const zrtp_stringn_t* one_zid,
|
||||
zrtp_memcpy((char*)id+sizeof(zrtp_zid_t), second_ZID->buffer, sizeof(zrtp_zid_t));
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
zrtp_cache_elem_t* zrtp_def_cache_get2(const zrtp_cache_id_t id, int is_mitm)
|
||||
{
|
||||
return get_elem(id, is_mitm);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
static zrtp_cache_elem_t* get_elem(const zrtp_cache_id_t id, uint8_t is_mitm)
|
||||
{
|
||||
mlist_t* node = NULL;
|
||||
@ -367,7 +369,6 @@ static zrtp_cache_elem_t* get_elem(const zrtp_cache_id_t id, uint8_t is_mitm)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void cache_make_cross(zrtp_cache_elem_t* from, zrtp_cache_elem_t* to, uint8_t is_upload)
|
||||
{
|
||||
if (!to) {
|
||||
@ -576,7 +577,7 @@ zrtp_status_t zrtp_cache_user_init()
|
||||
return s;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
#define ZRTP_DOWN_CACHE_RETURN(s, f) \
|
||||
{\
|
||||
if (zrtp_status_ok != s) { \
|
||||
@ -644,7 +645,7 @@ zrtp_status_t zrtp_cache_user_down()
|
||||
{
|
||||
FILE* cache_file = 0;
|
||||
mlist_t *node = 0;
|
||||
uint32_t count = 0;
|
||||
uint32_t count = 0, dirty_count=0;
|
||||
uint32_t pos = 0;
|
||||
|
||||
ZRTP_LOG(3,(_ZTU_,"\tStoring ZRTP cache to <%s>...\n", zrtp->def_cache_path.buffer));
|
||||
@ -686,7 +687,7 @@ zrtp_status_t zrtp_cache_user_down()
|
||||
*/
|
||||
pos = ftell(cache_file);
|
||||
|
||||
count = 0;
|
||||
count = 0; dirty_count = 0;
|
||||
fwrite(&count, sizeof(count), 1, cache_file);
|
||||
|
||||
mlist_for_each(node, &mitmcache_head) {
|
||||
@ -694,6 +695,7 @@ zrtp_status_t zrtp_cache_user_down()
|
||||
/* Store dirty values only. */
|
||||
if (g_needs_rewriting || elem->_is_dirty) {
|
||||
// printf("zrtp_cache_user_down: Store MiTM elem index=%u, not modified.\n", elem->_index);
|
||||
dirty_count++;
|
||||
if (zrtp_status_ok != flush_elem_(elem, cache_file, 1)) {
|
||||
ZRTP_DOWN_CACHE_RETURN(zrtp_status_write_fail, cache_file);
|
||||
}
|
||||
@ -709,7 +711,8 @@ zrtp_status_t zrtp_cache_user_down()
|
||||
ZRTP_DOWN_CACHE_RETURN(zrtp_status_write_fail, cache_file);
|
||||
}
|
||||
|
||||
ZRTP_LOG(3,(_ZTU_,"\t%u MiTM cache entries have been stored successfully.\n",zrtp_ntoh32(count)));
|
||||
if (dirty_count > 0)
|
||||
ZRTP_LOG(3,(_ZTU_,"\t%u out of %u MiTM cache entries have been flushed successfully.\n", dirty_count, zrtp_ntoh32(count)));
|
||||
|
||||
/*
|
||||
* Store regular secrets. Format: <secrets count>, <secrets' data>
|
||||
@ -722,7 +725,7 @@ zrtp_status_t zrtp_cache_user_down()
|
||||
|
||||
fseek(cache_file, pos, SEEK_SET);
|
||||
|
||||
count = 0;
|
||||
count = 0; dirty_count=0;
|
||||
fwrite(&count, sizeof(count), 1, cache_file);
|
||||
|
||||
mlist_for_each(node, &cache_head) {
|
||||
@ -731,6 +734,7 @@ zrtp_status_t zrtp_cache_user_down()
|
||||
/* Store dirty values only. */
|
||||
if (g_needs_rewriting || elem->_is_dirty) {
|
||||
// printf("zrtp_cache_user_down: Store RS elem index=%u, not modified.\n", elem->_index);
|
||||
dirty_count++;
|
||||
if (zrtp_status_ok != flush_elem_(elem, cache_file, 0)) {
|
||||
ZRTP_DOWN_CACHE_RETURN(zrtp_status_write_fail, cache_file);
|
||||
}
|
||||
@ -746,7 +750,9 @@ zrtp_status_t zrtp_cache_user_down()
|
||||
if (fwrite(&count, sizeof(count), 1, cache_file) != 1) {
|
||||
ZRTP_DOWN_CACHE_RETURN(zrtp_status_write_fail, cache_file);
|
||||
}
|
||||
ZRTP_LOG(3,(_ZTU_,"\t%u regular cache entries have been stored successfully.\n", zrtp_ntoh32(count)));
|
||||
|
||||
if (dirty_count > 0)
|
||||
ZRTP_LOG(3,(_ZTU_,"\t%u out of %u regular cache entries have been flushed successfully.\n", dirty_count, zrtp_ntoh32(count)));
|
||||
|
||||
g_needs_rewriting = 0;
|
||||
|
||||
@ -790,6 +796,8 @@ static zrtp_status_t put_name( const zrtp_stringn_t* one_ZID,
|
||||
} while (0);
|
||||
zrtp_mutex_unlock(def_cache_protector);
|
||||
|
||||
if (zrtp->cache_auto_store) zrtp_def_cache_store(zrtp);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -879,6 +887,8 @@ zrtp_status_t zrtp_def_cache_reset_since( const zrtp_stringn_t* one_zid,
|
||||
}
|
||||
zrtp_mutex_unlock(def_cache_protector);
|
||||
|
||||
if (zrtp->cache_auto_store) zrtp_def_cache_store(zrtp);
|
||||
|
||||
return (new_elem) ? zrtp_status_ok : zrtp_status_fail;
|
||||
}
|
||||
|
||||
@ -941,13 +951,10 @@ void zrtp_def_cache_foreach( zrtp_global_t *global,
|
||||
/*----------------------------------------------------------------------------*/
|
||||
zrtp_status_t zrtp_def_cache_store(zrtp_global_t *zrtp)
|
||||
{
|
||||
ZRTP_LOG(3,(_ZTU_,"Storing ZRTP Cache...\n"));
|
||||
|
||||
zrtp_mutex_lock(def_cache_protector);
|
||||
zrtp_cache_user_down();
|
||||
zrtp_mutex_unlock(def_cache_protector);
|
||||
|
||||
ZRTP_LOG(3,(_ZTU_,"Storing ZRTP Cache - DONE.\n"));
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ int zrtp_sleep(unsigned int msec)
|
||||
int zrtp_thread_create(zrtp_thread_routine_t start_routine, void *arg)
|
||||
{
|
||||
pthread_t thread;
|
||||
return pthread_create(&thread, NULL, start_routine, NULL);
|
||||
return pthread_create(&thread, NULL, start_routine, arg);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -46,14 +46,6 @@
|
||||
* derivative work of the FreeSWITCH code in the same work, the terms
|
||||
* of the AGPLv3 apply.
|
||||
*
|
||||
* You might have received some files with this library that are not
|
||||
* covered by this license grant. These files have a header
|
||||
* identifying the copyright holder as Philip R. Zimmermann and a
|
||||
* clear statement that the file is not freely available, such as,
|
||||
* "This is NOT licensed under the GPL or any other open source
|
||||
* license." This document grants you no right to distribute or use
|
||||
* these files.
|
||||
*
|
||||
* I, Phil Zimmermann, would like to make the following non-binding
|
||||
* request of any contributors to this library: please make your
|
||||
* changes available for me to sublicense. I support myself in part
|
||||
|
@ -51,8 +51,6 @@ void zrtp_log_set_log_engine(zrtp_log_engine *engine) {
|
||||
log_writer = engine;
|
||||
}
|
||||
|
||||
static const uint32_t zrtp_log_header_allign = 16;
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void zrtp_log(uint8_t is_clean, const char *sender, uint32_t level, const char *format, va_list marker)
|
||||
{
|
||||
|
@ -25,7 +25,8 @@ static void _send_and_resend_sasrelay(zrtp_stream_t *stream, zrtp_retry_task_t*
|
||||
ZRTP_LOG(1,(_ZTU_,"WARNING! SASRELAY Max retransmissions count reached. ID=%u\n", stream->id));
|
||||
_zrtp_machine_enter_initiatingerror(stream, zrtp_error_timeout, 0);
|
||||
} else if (task->_is_enabled) {
|
||||
zrtp_status_t s = _zrtp_packet_send_message(stream, ZRTP_SASRELAY, &stream->messages.sasrelay);
|
||||
|
||||
zrtp_status_t s = _zrtp_packet_send_message(stream, ZRTP_SASRELAY, &stream->messages.sasrelay);
|
||||
task->timeout = _zrtp_get_timeout((uint32_t)task->timeout, ZRTP_SASRELAY);
|
||||
if (zrtp_status_ok == s) {
|
||||
task->_retrys++;
|
||||
@ -87,13 +88,15 @@ static zrtp_status_t _create_sasrelay( zrtp_stream_t *stream,
|
||||
|
||||
s = session->blockcipher->encrypt( session->blockcipher,
|
||||
cipher_ctx,
|
||||
(uint8_t*)&sasrelay->pad,
|
||||
(uint8_t*)sasrelay->pad,
|
||||
encrypted_body_size );
|
||||
} while(0);
|
||||
if (cipher_ctx) {
|
||||
session->blockcipher->stop(session->blockcipher, cipher_ctx);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (zrtp_status_ok != s) {
|
||||
ZRTP_LOG(1,(_ZTU_,"\tERROR! Failed to encrypt SASRELAY Message status=%d. ID=%u\n", s, stream->id));
|
||||
return s;
|
||||
@ -130,10 +133,10 @@ zrtp_status_t _zrtp_machine_process_sasrelay(zrtp_stream_t *stream, zrtp_rtp_inf
|
||||
char zerosashash[32];
|
||||
unsigned sas_scheme_did_change = 0;
|
||||
unsigned sas_hash_did_change = 0;
|
||||
|
||||
|
||||
/* (padding + sig_len + flags) + SAS scheme and SAS hash */
|
||||
const uint8_t encrypted_body_size = (2 + 1 + 1) + 4 + 32;
|
||||
|
||||
|
||||
zrtp_memset(zerosashash, 0, sizeof(zerosashash));
|
||||
|
||||
/* Check if the remote endpoint is assigned to relay the SAS values */
|
||||
@ -141,7 +144,7 @@ zrtp_status_t _zrtp_machine_process_sasrelay(zrtp_stream_t *stream, zrtp_rtp_inf
|
||||
ZRTP_LOG(2,(_ZTU_, ZRTP_RELAYED_SAS_FROM_NONMITM_STR));
|
||||
return zrtp_status_fail;
|
||||
}
|
||||
|
||||
|
||||
/* Check the HMAC */
|
||||
s = session->hash->hmac_c( session->hash,
|
||||
stream->cc.peer_hmackey.buffer,
|
||||
@ -177,15 +180,15 @@ zrtp_status_t _zrtp_machine_process_sasrelay(zrtp_stream_t *stream, zrtp_rtp_inf
|
||||
break;
|
||||
}
|
||||
|
||||
s = session->blockcipher->encrypt( session->blockcipher,
|
||||
s = session->blockcipher->decrypt( session->blockcipher,
|
||||
cipher_ctx,
|
||||
(uint8_t*)&sasrelay->pad,
|
||||
(uint8_t*)sasrelay->pad,
|
||||
encrypted_body_size);
|
||||
} while(0);
|
||||
if (cipher_ctx) {
|
||||
session->blockcipher->stop(session->blockcipher, cipher_ctx);
|
||||
}
|
||||
|
||||
|
||||
if (zrtp_status_ok != s) {
|
||||
ZRTP_LOG(1,(_ZTU_,"\tERROR! Failed to decrypt Confirm. status=%d ID=%u\n", s, stream->id));
|
||||
return s;
|
||||
@ -215,7 +218,7 @@ zrtp_status_t _zrtp_machine_process_sasrelay(zrtp_stream_t *stream, zrtp_rtp_inf
|
||||
if (-1 == zrtp_profile_find(&session->profile, ZRTP_CC_SAS, rendering_id)) {
|
||||
ZRTP_LOG(1,(_ZTU_,"\tERROR! PBX Confirm packet with transferred SAS have unknown or"
|
||||
" unsupported rendering scheme %.4s.ID=%u\n", sasrelay->sas_scheme, stream->id));
|
||||
|
||||
|
||||
_zrtp_machine_enter_initiatingerror(stream, zrtp_error_invalid_packet, 1);
|
||||
return zrtp_status_fail;
|
||||
}
|
||||
@ -229,7 +232,7 @@ zrtp_status_t _zrtp_machine_process_sasrelay(zrtp_stream_t *stream, zrtp_rtp_inf
|
||||
}
|
||||
|
||||
if (session->secrets.matches & ZRTP_BIT_PBX) {
|
||||
if ( ( ((uint32_t) *sasrelay->sas_scheme) != (uint32_t)0x0L ) &&
|
||||
if ( (((uint32_t) *sasrelay->sas_scheme) != (uint32_t)0x0L) &&
|
||||
(0 != zrtp_memcmp(sasrelay->sashash, zerosashash, sizeof(sasrelay->sashash))) )
|
||||
{
|
||||
char buff[256];
|
||||
@ -237,10 +240,10 @@ zrtp_status_t _zrtp_machine_process_sasrelay(zrtp_stream_t *stream, zrtp_rtp_inf
|
||||
/* First 32 bits if sashash includes sasvalue */
|
||||
zrtp_memcpy(session->sasbin.buffer, sasrelay->sashash, session->sasbin.length);
|
||||
stream->mitm_mode = ZRTP_MITM_MODE_RECONFIRM_CLIENT;
|
||||
|
||||
|
||||
sas_hash_did_change = 1;
|
||||
ZRTP_LOG(3,(_ZTU_,"\tSasRelay: SAS value was updated to bin=%s.\n",
|
||||
hex2str(buff, sizeof(buff), session->sasbin.buffer, session->sasbin.length)));
|
||||
hex2str(session->sasbin.buffer, session->sasbin.length, buff, sizeof(buff))));
|
||||
}
|
||||
} else if (0 != zrtp_memcmp(sasrelay->sashash, zerosashash, sizeof(sasrelay->sashash))) {
|
||||
ZRTP_LOG(1,(_ZTU_,"\tWARNING! SAS Value was received from NOT Trusted MiTM. ID=%u\n", stream->id));
|
||||
@ -318,15 +321,15 @@ zrtp_status_t zrtp_stream_registration_start(zrtp_stream_t* stream, uint32_t ssr
|
||||
if (!stream) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
|
||||
ZRTP_LOG(3,(_ZTU_,"START REGISTRATION STREAM ID=%u mode=%s state=%s.\n",
|
||||
stream->id, zrtp_log_mode2str(stream->mode), zrtp_log_state2str(stream->state)));
|
||||
|
||||
|
||||
if (NULL == stream->zrtp->cb.cache_cb.on_get_mitm) {
|
||||
ZRTP_LOG(2,(_ZTU_,"WARNING: Can't use MiTM Functions with no ZRTP Cache.\n"));
|
||||
return zrtp_status_notavailable;
|
||||
}
|
||||
|
||||
|
||||
stream->mitm_mode = ZRTP_MITM_MODE_REG_SERVER;
|
||||
return zrtp_stream_start(stream, ssrc);
|
||||
}
|
||||
@ -336,15 +339,15 @@ zrtp_status_t zrtp_stream_registration_secure(zrtp_stream_t* stream)
|
||||
if (!stream) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
|
||||
ZRTP_LOG(3,(_ZTU_,"SECURE REGISTRATION STREAM ID=%u mode=%s state=%s.\n",
|
||||
stream->id, zrtp_log_mode2str(stream->mode), zrtp_log_state2str(stream->state)));
|
||||
|
||||
|
||||
if (NULL == stream->zrtp->cb.cache_cb.on_get_mitm) {
|
||||
ZRTP_LOG(2,(_ZTU_,"WARNING: Can't use MiTM Functions with no ZRTP Cache.\n"));
|
||||
return zrtp_status_notavailable;
|
||||
}
|
||||
|
||||
|
||||
stream->mitm_mode = ZRTP_MITM_MODE_REG_SERVER;
|
||||
return zrtp_stream_secure(stream);
|
||||
}
|
||||
@ -354,22 +357,22 @@ zrtp_status_t zrtp_register_with_trusted_mitm(zrtp_stream_t* stream)
|
||||
{
|
||||
zrtp_session_t *session = stream->session;
|
||||
zrtp_status_t s = zrtp_status_bad_param;
|
||||
|
||||
|
||||
if (!stream) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
|
||||
ZRTP_LOG(3,(_ZTU_,"MARKING this call as REGISTRATION ID=%u\n", stream->id));
|
||||
|
||||
|
||||
if (NULL == stream->zrtp->cb.cache_cb.on_get_mitm) {
|
||||
ZRTP_LOG(2,(_ZTU_,"WARNING: Can't use MiTM Functions with no ZRTP Cache.\n"));
|
||||
return zrtp_status_notavailable;
|
||||
}
|
||||
|
||||
|
||||
if (!stream->protocol) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
|
||||
/* Passive Client endpoint should NOT generate PBX Secret. */
|
||||
if ((stream->mitm_mode == ZRTP_MITM_MODE_REG_CLIENT) &&
|
||||
(ZRTP_LICENSE_MODE_PASSIVE == stream->zrtp->lic_mode)) {
|
||||
@ -387,7 +390,7 @@ zrtp_status_t zrtp_register_with_trusted_mitm(zrtp_stream_t* stream)
|
||||
zrtp_string32_t kdf_context = ZSTR_INIT_EMPTY(kdf_context);
|
||||
static const zrtp_string32_t trusted_mitm_key_label = ZSTR_INIT_WITH_CONST_CSTRING(ZRTP_TRUSTMITMKEY_STR);
|
||||
zrtp_string16_t *zidi, *zidr;
|
||||
|
||||
|
||||
if (stream->protocol->type == ZRTP_STATEMACHINE_INITIATOR) {
|
||||
zidi = &session->zid;
|
||||
zidr = &session->peer_zid;
|
||||
@ -395,29 +398,29 @@ zrtp_status_t zrtp_register_with_trusted_mitm(zrtp_stream_t* stream)
|
||||
zidi = &session->peer_zid;
|
||||
zidr = &session->zid;
|
||||
}
|
||||
|
||||
|
||||
zrtp_zstrcat(ZSTR_GV(kdf_context), ZSTR_GVP(zidi));
|
||||
zrtp_zstrcat(ZSTR_GV(kdf_context), ZSTR_GVP(zidr));
|
||||
|
||||
|
||||
_zrtp_kdf( stream,
|
||||
ZSTR_GV(session->zrtpsess),
|
||||
ZSTR_GV(trusted_mitm_key_label),
|
||||
ZSTR_GV(kdf_context),
|
||||
ZRTP_HASH_SIZE,
|
||||
ZSTR_GV(session->secrets.pbxs->value));
|
||||
|
||||
|
||||
session->secrets.pbxs->_cachedflag = 1;
|
||||
session->secrets.pbxs->lastused_at = (uint32_t)(zrtp_time_now()/1000);
|
||||
session->secrets.cached |= ZRTP_BIT_PBX;
|
||||
session->secrets.matches |= ZRTP_BIT_PBX;
|
||||
|
||||
s = zrtp_status_ok;
|
||||
if (session->zrtp->cb.cache_cb.on_put_mitm) {
|
||||
s = session->zrtp->cb.cache_cb.on_put_mitm( ZSTR_GV(session->zid),
|
||||
if (session->zrtp->cb.cache_cb.on_put_mitm) {
|
||||
s = session->zrtp->cb.cache_cb.on_put_mitm( ZSTR_GV(session->zid),
|
||||
ZSTR_GV(session->peer_zid),
|
||||
session->secrets.pbxs);
|
||||
}
|
||||
|
||||
|
||||
ZRTP_LOG(3,(_ZTU_,"Makring this call as REGISTRATION - DONE\n"));
|
||||
}
|
||||
|
||||
@ -430,46 +433,46 @@ zrtp_status_t zrtp_link_mitm_calls(zrtp_stream_t *stream1, zrtp_stream_t *stream
|
||||
if (!stream1 || !stream2) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
ZRTP_LOG(3,(_ZTU_,"Link to MiTM call together stream1=%u stream2=%u.\n", stream1->id, stream2->id));
|
||||
|
||||
|
||||
ZRTP_LOG(3,(_ZTU_,"Link to MiTM call together stream1=%u stream2=%u.\n", stream1->id, stream2->id));
|
||||
|
||||
/* This APi is for MiTM endpoints only. */
|
||||
if (stream1->zrtp->is_mitm) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
|
||||
stream1->linked_mitm = stream2;
|
||||
stream2->linked_mitm = stream1;
|
||||
|
||||
|
||||
{
|
||||
zrtp_stream_t *passive = NULL;
|
||||
zrtp_stream_t *unlimited = NULL;
|
||||
|
||||
|
||||
/* Check if we have at least one Unlimited endpoint. */
|
||||
if (stream1->peer_super_flag)
|
||||
unlimited = stream1;
|
||||
else if (stream2->peer_super_flag)
|
||||
unlimited = stream2;
|
||||
|
||||
|
||||
/* Check if the peer stream is Passive */
|
||||
if (unlimited) {
|
||||
passive = (stream1 == unlimited) ? stream2 : stream1;
|
||||
if (!passive->peer_passive)
|
||||
passive = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Ok, we haver Unlimited and Passive at two ends, let's make an exception and switch Passive to Secure. */
|
||||
if (unlimited && passive) {
|
||||
if (passive->state == ZRTP_STATE_CLEAR) {
|
||||
ZRTP_LOG(2,(_ZTU_,"INFO: zrtp_link_mitm_calls() stream with id=%u is Unlimited and"
|
||||
" Peer stream with id=%u is Passive in CLEAR state, switch the passive one to SECURE.\n"));
|
||||
|
||||
/* @note: don't use zrtp_secure_stream() wrapper as it checks for Active/Passive stuff. */
|
||||
|
||||
/* @note: don't use zrtp_secure_stream() wrapper as it checks for Active/Passive stuff. */
|
||||
_zrtp_machine_start_initiating_secure(passive);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
@ -483,16 +486,16 @@ zrtp_status_t zrtp_update_remote_options( zrtp_stream_t* stream,
|
||||
zrtp_retry_task_t* task = &stream->messages.sasrelay_task;
|
||||
zrtp_status_t s = zrtp_status_ok;
|
||||
char buff[256];
|
||||
|
||||
|
||||
if (!stream) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
|
||||
ZRTP_LOG(3,(_ZTU_,"UPDATE REMOTE SAS OPTIONS mode. ID=%u\n", stream->id));
|
||||
ZRTP_LOG(3,(_ZTU_,"transf_sas=%s scheme=%d.\n", transf_sas_value ?
|
||||
hex2str((const char*)transf_sas_value->buffer, transf_sas_value->length, (char*)buff, sizeof(buff)) : "NULL",
|
||||
transf_sas_scheme));
|
||||
|
||||
|
||||
if (NULL == stream->zrtp->cb.cache_cb.on_get_mitm) {
|
||||
ZRTP_LOG(2,(_ZTU_,"WARNING: Can't use MiTM Functions with no ZRTP Cache.\n"));
|
||||
return zrtp_status_notavailable;
|
||||
@ -507,7 +510,7 @@ zrtp_status_t zrtp_update_remote_options( zrtp_stream_t* stream,
|
||||
if (transf_sas_value && !(stream->session->secrets.matches & ZRTP_BIT_PBX)) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
|
||||
/* Don't allow to transfer the SAS if the library wasn't initialized as MiTM endpoint */
|
||||
if (!stream->zrtp->is_mitm) {
|
||||
ZRTP_LOG(3,(_ZTU_,"\tERROR! The endpoint can't transfer SAS values to other endpoints"
|
||||
@ -551,7 +554,7 @@ zrtp_status_t zrtp_resolve_mitm_call( zrtp_stream_t* stream1,
|
||||
zrtp_stream_t* non_enrolled = NULL;
|
||||
zrtp_sas_id_t mitm_sas_scheme = ZRTP_COMP_UNKN;
|
||||
zrtp_status_t s = zrtp_status_ok;
|
||||
|
||||
|
||||
if (!stream1 || !stream2) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
@ -562,7 +565,7 @@ zrtp_status_t zrtp_resolve_mitm_call( zrtp_stream_t* stream1,
|
||||
ZRTP_LOG(2,(_ZTU_,"WARNING: Can't use MiTM Functions with no ZRTP Cache.\n"));
|
||||
return zrtp_status_notavailable;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Both sides must be in the Secure state and at least one should be
|
||||
* enrolled.
|
||||
@ -667,7 +670,7 @@ uint8_t zrtp_is_user_enrolled(zrtp_stream_t* stream)
|
||||
if (!stream) {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
|
||||
|
||||
return ( (stream->session->secrets.cached & ZRTP_BIT_PBX) &&
|
||||
(stream->session->secrets.matches & ZRTP_BIT_PBX) );
|
||||
}
|
||||
@ -677,7 +680,7 @@ zrtp_stream_t* zrtp_choose_one_enrolled(zrtp_stream_t* stream1, zrtp_stream_t* s
|
||||
if (!stream1 || !stream2) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (zrtp_memcmp( stream1->session->zid.buffer,
|
||||
stream2->session->zid.buffer,
|
||||
stream1->session->zid.length) > 0) {
|
||||
|
@ -1086,7 +1086,7 @@ zrtp_status_t _zrtp_machine_enter_secure(zrtp_stream_t* stream)
|
||||
session->zrtp->cb.event_cb.on_zrtp_protocol_event(stream, ZRTP_EVENT_IS_SECURE_DONE);
|
||||
}
|
||||
|
||||
/* We have computed all subkeys from S0 and don't need it anylonger. */
|
||||
/* We have computed all subkeys from S0 and don't need it any longer. */
|
||||
zrtp_wipe_zstring(ZSTR_GV(cc->s0));
|
||||
|
||||
/* Clear DH crypto context */
|
||||
|
@ -343,3 +343,9 @@ int zrtp_randstr(zrtp_global_t* zrtp, unsigned char *buffer, uint32_t length)
|
||||
|
||||
return generated;
|
||||
}
|
||||
|
||||
int zrtp_randstr2(unsigned char *buffer, uint32_t length) {
|
||||
zrtp_global_t zrtp;
|
||||
zrtp.rand_initialized = 0;
|
||||
return zrtp_randstr(&zrtp, buffer, length);
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ const char* hex2str(const char* bin, int bin_size, char* buff, int buff_size)
|
||||
if (NULL == buff) {
|
||||
return "buffer is NULL";
|
||||
}
|
||||
if (buff_size < bin_size*2+1) {
|
||||
if (buff_size < bin_size*2) {
|
||||
return "buffer too small";
|
||||
}
|
||||
|
||||
@ -121,7 +121,8 @@ const char* hex2str(const char* bin, int bin_size, char* buff, int buff_size)
|
||||
nptr = hex2char(nptr, *bin++);
|
||||
}
|
||||
|
||||
*nptr = 0;
|
||||
if (buff_size >= bin_size*2+1)
|
||||
*nptr = 0;
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "zrtp.h"
|
||||
#include "cmockery/cmockery.h"
|
||||
@ -109,7 +109,7 @@ void cache_init_store_empty_test() {
|
||||
* Add few entries to the empty cache, flush it and then load again. Check if
|
||||
* all the entries were restored successfully.
|
||||
*/
|
||||
void cache_add2empty_test() {
|
||||
void cache_add2empty_test() {
|
||||
zrtp_status_t status;
|
||||
int intres;
|
||||
|
||||
@ -146,8 +146,8 @@ void cache_save_unchanged_test() {
|
||||
|
||||
/*
|
||||
* TEST: now let's store the cache making no changes to it.
|
||||
* After opening it should include all the secrets untouched.
|
||||
*/
|
||||
* After opening it should include all the secrets untouched.
|
||||
*/
|
||||
|
||||
printf("==> And the cache again, it should contain all the stored values.\n");
|
||||
|
||||
|
65
libs/libzrtp/test/cipher_test.c
Normal file
65
libs/libzrtp/test/cipher_test.c
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "zrtp.h"
|
||||
#include "cmockery/cmockery.h"
|
||||
|
||||
zrtp_global_t *zrtp;
|
||||
|
||||
void setup() {
|
||||
zrtp_status_t s;
|
||||
zrtp_config_t zrtp_config;
|
||||
|
||||
zrtp_config_defaults(&zrtp_config);
|
||||
|
||||
s = zrtp_init(&zrtp_config, &zrtp);
|
||||
assert_int_equal(s, zrtp_status_ok);
|
||||
}
|
||||
|
||||
void teardown() {
|
||||
zrtp_down(zrtp);
|
||||
}
|
||||
|
||||
static void aes128_ctr_test() {
|
||||
zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES128, zrtp);
|
||||
assert_non_null(cipher);
|
||||
cipher->self_test(cipher, ZRTP_CIPHER_MODE_CTR);
|
||||
}
|
||||
|
||||
static void aes128_cfb_test() {
|
||||
zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES128, zrtp);
|
||||
assert_non_null(cipher);
|
||||
cipher->self_test(cipher, ZRTP_CIPHER_MODE_CFB);
|
||||
}
|
||||
|
||||
static void aes256_ctr_test() {
|
||||
zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES256, zrtp);
|
||||
assert_non_null(cipher);
|
||||
cipher->self_test(cipher, ZRTP_CIPHER_MODE_CTR);
|
||||
}
|
||||
|
||||
static void aes256_cfb_test() {
|
||||
zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES256, zrtp);
|
||||
assert_non_null(cipher);
|
||||
cipher->self_test(cipher, ZRTP_CIPHER_MODE_CFB);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(aes128_ctr_test, setup, teardown),
|
||||
unit_test_setup_teardown(aes128_cfb_test, setup, teardown),
|
||||
unit_test_setup_teardown(aes256_ctr_test, setup, teardown),
|
||||
unit_test_setup_teardown(aes256_cfb_test, setup, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
}
|
@ -114,9 +114,6 @@ typedef unsigned long uintptr_t;
|
||||
* what's the right preprocessor symbol?
|
||||
typedef unsigned long long uintptr_t */
|
||||
|
||||
/* ILP32 and LP64 platforms */
|
||||
typedef unsigned long uintptr_t;
|
||||
|
||||
#endif /* _WIN32 */
|
||||
#endif /* _UINTPTR_T */
|
||||
|
||||
|
52
libs/libzrtp/test/dh_test.c
Normal file
52
libs/libzrtp/test/dh_test.c
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "zrtp.h"
|
||||
#include "cmockery/cmockery.h"
|
||||
|
||||
zrtp_global_t *zrtp;
|
||||
|
||||
void setup() {
|
||||
zrtp_status_t s;
|
||||
zrtp_config_t zrtp_config;
|
||||
|
||||
zrtp_config_defaults(&zrtp_config);
|
||||
|
||||
s = zrtp_init(&zrtp_config, &zrtp);
|
||||
assert_int_equal(s, zrtp_status_ok);
|
||||
}
|
||||
|
||||
void teardown() {
|
||||
zrtp_down(zrtp);
|
||||
}
|
||||
|
||||
static void dh2k_test() {
|
||||
zrtp_pk_scheme_t *pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_DH2048, zrtp);
|
||||
assert_non_null(pks);
|
||||
pks->self_test(pks);
|
||||
}
|
||||
|
||||
static void dh3k_test() {
|
||||
zrtp_pk_scheme_t *pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_DH3072, zrtp);
|
||||
assert_non_null(pks);
|
||||
pks->self_test(pks);
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(dh2k_test, setup, teardown),
|
||||
unit_test_setup_teardown(dh3k_test, setup, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
}
|
140
libs/libzrtp/test/dk_test.c
Normal file
140
libs/libzrtp/test/dk_test.c
Normal file
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "zrtp.h"
|
||||
#include "cmockery/cmockery.h"
|
||||
|
||||
zrtp_global_t *zrtp;
|
||||
|
||||
extern zrtp_dk_ctx *zrtp_dk_init(zrtp_cipher_t *cipher, zrtp_stringn_t *key, zrtp_stringn_t *salt);
|
||||
extern zrtp_status_t zrtp_derive_key(zrtp_dk_ctx *ctx, zrtp_srtp_prf_label label, zrtp_stringn_t *result_key);
|
||||
extern void zrtp_dk_deinit(zrtp_dk_ctx *ctx);
|
||||
|
||||
static uint8_t dk_master_key[16] = {
|
||||
0xE1, 0xF9, 0x7A, 0x0D, 0x3E, 0x01, 0x8B, 0xE0,
|
||||
0xD6, 0x4F, 0xA3, 0x2C, 0x06, 0xDE, 0x41, 0x39
|
||||
};
|
||||
|
||||
static uint8_t dk_master_salt[14] = {
|
||||
0x0E, 0xC6, 0x75, 0xAD, 0x49, 0x8A, 0xFE, 0xEB,
|
||||
0xB6, 0x96, 0x0B, 0x3A, 0xAB, 0xE6
|
||||
};
|
||||
|
||||
|
||||
static uint8_t dk_cipher_key[16] = {
|
||||
0xC6, 0x1E, 0x7A, 0x93, 0x74, 0x4F, 0x39, 0xEE,
|
||||
0x10, 0x73, 0x4A, 0xFE, 0x3F, 0xF7, 0xA0, 0x87
|
||||
};
|
||||
|
||||
static uint8_t dk_cipher_salt[14] = {
|
||||
0x30, 0xCB, 0xBC, 0x08, 0x86, 0x3D, 0x8C, 0x85,
|
||||
0xD4, 0x9D, 0xB3, 0x4A, 0x9A, 0xE1
|
||||
};
|
||||
|
||||
static uint8_t dk_auth_key[94] = {
|
||||
0xCE, 0xBE, 0x32, 0x1F, 0x6F, 0xF7, 0x71, 0x6B,
|
||||
0x6F, 0xD4, 0xAB, 0x49, 0xAF, 0x25, 0x6A, 0x15,
|
||||
0x6D, 0x38, 0xBA, 0xA4, 0x8F, 0x0A, 0x0A, 0xCF,
|
||||
0x3C, 0x34, 0xE2, 0x35, 0x9E, 0x6C, 0xDB, 0xCE,
|
||||
0xE0, 0x49, 0x64, 0x6C, 0x43, 0xD9, 0x32, 0x7A,
|
||||
0xD1, 0x75, 0x57, 0x8E, 0xF7, 0x22, 0x70, 0x98,
|
||||
0x63, 0x71, 0xC1, 0x0C, 0x9A, 0x36, 0x9A, 0xC2,
|
||||
0xF9, 0x4A, 0x8C, 0x5F, 0xBC, 0xDD, 0xDC, 0x25,
|
||||
0x6D, 0x6E, 0x91, 0x9A, 0x48, 0xB6, 0x10, 0xEF,
|
||||
0x17, 0xC2, 0x04, 0x1E, 0x47, 0x40, 0x35, 0x76,
|
||||
0x6B, 0x68, 0x64, 0x2C, 0x59, 0xBB, 0xFC, 0x2F,
|
||||
0x34, 0xDB, 0x60, 0xDB, 0xDF, 0xB2
|
||||
};
|
||||
|
||||
|
||||
void setup() {
|
||||
zrtp_status_t s;
|
||||
zrtp_config_t zrtp_config;
|
||||
|
||||
zrtp_config_defaults(&zrtp_config);
|
||||
|
||||
s = zrtp_init(&zrtp_config, &zrtp);
|
||||
assert_int_equal(s, zrtp_status_ok);
|
||||
}
|
||||
|
||||
void teardown() {
|
||||
zrtp_down(zrtp);
|
||||
}
|
||||
|
||||
zrtp_status_t hex_cmp(uint8_t *a, uint8_t *b, uint32_t len)
|
||||
{
|
||||
uint32_t i;
|
||||
zrtp_status_t res = zrtp_status_ok;
|
||||
for (i = 0; i<len; i++) {
|
||||
if (a[i] != b[i]) {
|
||||
res = zrtp_status_fail;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static void dk_test() {
|
||||
|
||||
zrtp_status_t res;
|
||||
zrtp_string16_t master_key, master_salt, cipher_key, cipher_salt;
|
||||
zrtp_string128_t auth_key;
|
||||
zrtp_dk_ctx *ctx;
|
||||
|
||||
zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES128, zrtp);
|
||||
assert_non_null(cipher);
|
||||
|
||||
master_key.length = master_key.max_length = 16;
|
||||
zrtp_memcpy(master_key.buffer, dk_master_key, 16);
|
||||
|
||||
master_salt.length = 14;
|
||||
master_salt.max_length = 16;
|
||||
zrtp_memcpy(master_salt.buffer, dk_master_salt, 14);
|
||||
|
||||
|
||||
ctx = zrtp_dk_init(cipher, (zrtp_stringn_t*)&master_key, (zrtp_stringn_t*)&master_salt);
|
||||
assert_non_null(ctx);
|
||||
|
||||
cipher_key.length = 16;
|
||||
cipher_key.max_length = 16;
|
||||
|
||||
zrtp_derive_key(ctx, label_rtp_encryption, (zrtp_stringn_t*)&cipher_key);
|
||||
res = hex_cmp((uint8_t*)cipher_key.buffer, dk_cipher_key, cipher_key.length);
|
||||
assert_int_equal(res, zrtp_status_ok);
|
||||
|
||||
|
||||
cipher_salt.length = 14;
|
||||
cipher_salt.max_length = 16;
|
||||
|
||||
zrtp_derive_key(ctx, label_rtp_salt, (zrtp_stringn_t*)&cipher_salt);
|
||||
res = hex_cmp((uint8_t*)cipher_salt.buffer, dk_cipher_salt, cipher_salt.length);
|
||||
assert_int_equal(res, zrtp_status_ok);
|
||||
|
||||
|
||||
auth_key.length = 94;
|
||||
auth_key.max_length = 128;
|
||||
|
||||
zrtp_derive_key(ctx, label_rtp_msg_auth, (zrtp_stringn_t*)&auth_key);
|
||||
res = hex_cmp((uint8_t*)auth_key.buffer, dk_auth_key, auth_key.length);
|
||||
assert_int_equal(res, zrtp_status_ok);
|
||||
|
||||
zrtp_dk_deinit(ctx);
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(dk_test, setup, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
}
|
60
libs/libzrtp/test/ecdh_test.c
Normal file
60
libs/libzrtp/test/ecdh_test.c
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "zrtp.h"
|
||||
#include "cmockery/cmockery.h"
|
||||
|
||||
zrtp_global_t *zrtp;
|
||||
|
||||
void setup() {
|
||||
zrtp_status_t s;
|
||||
zrtp_config_t zrtp_config;
|
||||
|
||||
zrtp_config_defaults(&zrtp_config);
|
||||
|
||||
s = zrtp_init(&zrtp_config, &zrtp);
|
||||
assert_int_equal(s, zrtp_status_ok);
|
||||
}
|
||||
|
||||
void teardown() {
|
||||
zrtp_down(zrtp);
|
||||
}
|
||||
|
||||
|
||||
static void ecdh256_test() {
|
||||
zrtp_pk_scheme_t *pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_EC256P, zrtp);
|
||||
assert_non_null(pks);
|
||||
pks->self_test(pks);
|
||||
}
|
||||
|
||||
static void ecdh384_test() {
|
||||
zrtp_pk_scheme_t *pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_EC384P, zrtp);
|
||||
assert_non_null(pks);
|
||||
pks->self_test(pks);
|
||||
}
|
||||
|
||||
static void ecdh512_test() {
|
||||
zrtp_pk_scheme_t *pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_EC521P, zrtp);
|
||||
assert_non_null(pks);
|
||||
pks->self_test(pks);
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(ecdh256_test, setup, teardown),
|
||||
unit_test_setup_teardown(ecdh384_test, setup, teardown),
|
||||
unit_test_setup_teardown(ecdh512_test, setup, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
}
|
69
libs/libzrtp/test/engine_helpers.c
Normal file
69
libs/libzrtp/test/engine_helpers.c
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include <setjmp.h> /*chmockery dependency*/
|
||||
#include <stdio.h> /*chmockery dependency*/
|
||||
#include <unistd.h> /*for usleep*/
|
||||
|
||||
#include "cmockery/cmockery.h"
|
||||
#include "test_engine.h"
|
||||
|
||||
static zrtp_test_id_t g_alice, g_bob;
|
||||
static zrtp_test_id_t g_alice_sid, g_bob_sid;
|
||||
static zrtp_test_id_t g_secure_audio_channel;
|
||||
|
||||
|
||||
static void prepare_alice_bob() {
|
||||
zrtp_status_t s;
|
||||
|
||||
zrtp_test_session_cfg_t session_config;
|
||||
zrtp_test_session_config_defaults(&session_config);
|
||||
|
||||
/*
|
||||
* Create two test sessions, one for Alice and one for Bob and link them
|
||||
* into test secure channel
|
||||
*/
|
||||
s = zrtp_test_session_create(g_alice, &session_config, &g_alice_sid);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice_sid);
|
||||
|
||||
s = zrtp_test_session_create(g_bob, &session_config, &g_bob_sid);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob_sid);
|
||||
|
||||
s = zrtp_test_channel_create2(g_alice_sid, g_bob_sid, 0, &g_secure_audio_channel);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_secure_audio_channel);
|
||||
}
|
||||
|
||||
static void release_alice_bob() {
|
||||
zrtp_test_session_destroy(g_alice_sid);
|
||||
zrtp_test_session_destroy(g_bob_sid);
|
||||
|
||||
zrtp_test_channel_destroy(g_secure_audio_channel);
|
||||
}
|
||||
|
||||
static void start_alice_bob_and_wait4secure() {
|
||||
zrtp_status_t s;
|
||||
zrtp_test_channel_info_t channel_info;
|
||||
|
||||
/* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
|
||||
s = zrtp_test_channel_start(g_secure_audio_channel);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
unsigned i = 30;
|
||||
for (; i>0; i--) {
|
||||
usleep(100*1000);
|
||||
}
|
||||
|
||||
s = zrtp_test_channel_get(g_secure_audio_channel, &channel_info);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
assert_true(channel_info.is_secure);
|
||||
}
|
81
libs/libzrtp/test/enroll_test_helpers.c
Normal file
81
libs/libzrtp/test/enroll_test_helpers.c
Normal file
@ -0,0 +1,81 @@
|
||||
|
||||
static zrtp_test_id_t g_alice, g_bob, g_pbx;
|
||||
static zrtp_test_id_t g_alice_sid, g_bob_sid, g_pbxa_sid, g_pbxb_sid;
|
||||
static zrtp_test_id_t g_alice2pbx_channel, g_bob2pbx_channel;
|
||||
|
||||
static void pbx_setup() {
|
||||
zrtp_status_t s;
|
||||
|
||||
zrtp_test_endpoint_cfg_t endpoint_cfg;
|
||||
zrtp_test_endpoint_config_defaults(&endpoint_cfg);
|
||||
|
||||
s = zrtp_test_endpoint_create(&endpoint_cfg, "Alice", &g_alice);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice);
|
||||
|
||||
s = zrtp_test_endpoint_create(&endpoint_cfg, "Bob", &g_bob);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob);
|
||||
|
||||
endpoint_cfg.zrtp.is_mitm = 1;
|
||||
s = zrtp_test_endpoint_create(&endpoint_cfg, "PBX", &g_pbx);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_pbx);
|
||||
}
|
||||
|
||||
static void pbx_teardown() {
|
||||
zrtp_test_endpoint_destroy(g_alice);
|
||||
zrtp_test_endpoint_destroy(g_bob);
|
||||
zrtp_test_endpoint_destroy(g_pbx);
|
||||
}
|
||||
|
||||
|
||||
static void prepare_alice_pbx_bob_setup(zrtp_test_session_cfg_t *alice_sconfig,
|
||||
zrtp_test_session_cfg_t *bob_sconfig,
|
||||
zrtp_test_session_cfg_t *pbxa_sconfig,
|
||||
zrtp_test_session_cfg_t *pbxb_sconfig) {
|
||||
zrtp_status_t s;
|
||||
|
||||
if (alice_sconfig) {
|
||||
assert_non_null(pbxa_sconfig);
|
||||
|
||||
s = zrtp_test_session_create(g_alice, alice_sconfig, &g_alice_sid);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice_sid);
|
||||
|
||||
s = zrtp_test_session_create(g_pbx, pbxa_sconfig, &g_pbxa_sid);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_pbxa_sid);
|
||||
|
||||
s = zrtp_test_channel_create2(g_alice_sid, g_pbxa_sid, 0, &g_alice2pbx_channel);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice2pbx_channel);
|
||||
}
|
||||
|
||||
if (bob_sconfig) {
|
||||
assert_non_null(pbxb_sconfig);
|
||||
|
||||
s = zrtp_test_session_create(g_bob, bob_sconfig, &g_bob_sid);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob_sid);
|
||||
|
||||
s = zrtp_test_session_create(g_pbx, pbxb_sconfig, &g_pbxb_sid);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_pbxb_sid);
|
||||
|
||||
s = zrtp_test_channel_create2(g_bob_sid, g_pbxb_sid, 0, &g_bob2pbx_channel);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob2pbx_channel);
|
||||
}
|
||||
}
|
||||
|
||||
static void cleanup_alice_pbx_bob_setup() {
|
||||
zrtp_test_session_destroy(g_alice_sid);
|
||||
zrtp_test_session_destroy(g_bob_sid);
|
||||
zrtp_test_session_destroy(g_pbxa_sid);
|
||||
zrtp_test_session_destroy(g_pbxb_sid);
|
||||
|
||||
zrtp_test_channel_destroy(g_alice2pbx_channel);
|
||||
zrtp_test_channel_destroy(g_bob2pbx_channel);
|
||||
}
|
||||
|
101
libs/libzrtp/test/enrollment_test.c
Normal file
101
libs/libzrtp/test/enrollment_test.c
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include <setjmp.h> /*chmockery dependency*/
|
||||
#include <stdio.h> /*chmockery dependency*/
|
||||
#include <unistd.h> /*for usleep*/
|
||||
|
||||
#include "cmockery/cmockery.h"
|
||||
#include "test_engine.h"
|
||||
|
||||
#include "enroll_test_helpers.c"
|
||||
|
||||
static void enrollment_test() {
|
||||
zrtp_status_t s;
|
||||
|
||||
zrtp_test_channel_info_t a2pbx_channel_info;
|
||||
zrtp_test_session_cfg_t session_config, session_config_enroll;
|
||||
zrtp_test_session_config_defaults(&session_config);
|
||||
zrtp_test_session_config_defaults(&session_config_enroll);
|
||||
|
||||
session_config_enroll.is_enrollment = 1;
|
||||
|
||||
/**************************************************************************
|
||||
* Enroll Alice to PBX and check triggered events.
|
||||
*/
|
||||
prepare_alice_pbx_bob_setup(&session_config, NULL, &session_config_enroll, NULL);
|
||||
|
||||
/* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
|
||||
s = zrtp_test_channel_start(g_alice2pbx_channel);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
int i = 30;
|
||||
for (; i>0; i--) {
|
||||
usleep(100*1000);
|
||||
}
|
||||
|
||||
s = zrtp_test_channel_get(g_alice2pbx_channel, &a2pbx_channel_info);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
/* Both, Alice and PBX should switch secure */
|
||||
assert_true(a2pbx_channel_info.is_secure);
|
||||
|
||||
/* Alice should receive Enrollment notification */
|
||||
zrtp_test_id_t alice2pbx_stream = zrtp_test_session_get_stream_by_idx(g_alice_sid, 0);
|
||||
assert_true(zrtp_stream_did_event_receive(alice2pbx_stream, ZRTP_EVENT_IS_CLIENT_ENROLLMENT));
|
||||
|
||||
/* PBX streams should receive incoming enrollment notification */
|
||||
zrtp_test_id_t pbx2alice_stream = zrtp_test_session_get_stream_by_idx(g_pbxa_sid, 0);
|
||||
assert_true(zrtp_stream_did_event_receive(pbx2alice_stream, ZRTP_EVENT_NEW_USER_ENROLLED));
|
||||
|
||||
/* Confirm enrollment at the PBX side */
|
||||
s = zrtp_register_with_trusted_mitm(zrtp_stream_for_test_stream(alice2pbx_stream));
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
/* Clean-up */
|
||||
cleanup_alice_pbx_bob_setup();
|
||||
|
||||
/**************************************************************************
|
||||
* Try to make one more enrollment call. This time it should say "Already enrolled"
|
||||
*/
|
||||
prepare_alice_pbx_bob_setup(&session_config, NULL, &session_config_enroll, NULL);
|
||||
|
||||
/* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
|
||||
s = zrtp_test_channel_start(g_alice2pbx_channel);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
i = 30;
|
||||
for (; i>0; i--) {
|
||||
usleep(100*1000);
|
||||
}
|
||||
|
||||
s = zrtp_test_channel_get(g_alice2pbx_channel, &a2pbx_channel_info);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
assert_true(a2pbx_channel_info.is_secure);
|
||||
|
||||
/* Alice should receive Enrollment notification */
|
||||
alice2pbx_stream = zrtp_test_session_get_stream_by_idx(g_alice_sid, 0);
|
||||
assert_true(zrtp_stream_did_event_receive(alice2pbx_stream, ZRTP_EVENT_IS_CLIENT_ENROLLMENT));
|
||||
|
||||
/* PBX streams should receive incoming enrollment notification */
|
||||
pbx2alice_stream = zrtp_test_session_get_stream_by_idx(g_pbxa_sid, 0);
|
||||
assert_true(zrtp_stream_did_event_receive(pbx2alice_stream, ZRTP_EVENT_USER_ALREADY_ENROLLED));
|
||||
|
||||
// TODO: check if we have PBX secret cached
|
||||
// TODO: test zrtp_is_user_enrolled()
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(enrollment_test, pbx_setup, pbx_teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
}
|
99
libs/libzrtp/test/go_secure_test.c
Normal file
99
libs/libzrtp/test/go_secure_test.c
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include "engine_helpers.c"
|
||||
|
||||
static void setup() {
|
||||
zrtp_status_t s;
|
||||
|
||||
zrtp_test_endpoint_cfg_t endpoint_cfg;
|
||||
zrtp_test_endpoint_config_defaults(&endpoint_cfg);
|
||||
|
||||
s = zrtp_test_endpoint_create(&endpoint_cfg, "Alice", &g_alice);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice);
|
||||
|
||||
s = zrtp_test_endpoint_create(&endpoint_cfg, "Bob", &g_bob);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob);
|
||||
}
|
||||
|
||||
static void teardown() {
|
||||
zrtp_test_endpoint_destroy(g_alice);
|
||||
zrtp_test_endpoint_destroy(g_bob);
|
||||
}
|
||||
|
||||
|
||||
static void go_secure_test() {
|
||||
/*
|
||||
* Create two test sessions, one for Alice and one for Bob and link them
|
||||
* into test secure channel
|
||||
*/
|
||||
prepare_alice_bob();
|
||||
start_alice_bob_and_wait4secure();
|
||||
release_alice_bob();
|
||||
}
|
||||
|
||||
static void go_secure_flags_test() {
|
||||
zrtp_status_t s;
|
||||
zrtp_test_session_info_t alice_ses_info;
|
||||
|
||||
prepare_alice_bob();
|
||||
|
||||
start_alice_bob_and_wait4secure();
|
||||
|
||||
/* All flags should be clear */
|
||||
s = zrtp_test_session_get(g_alice_sid, &alice_ses_info);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
assert_int_equal(0, alice_ses_info.zrtp.matches_flags);
|
||||
assert_int_equal(0, alice_ses_info.zrtp.cached_flags);
|
||||
assert_int_equal(0, alice_ses_info.zrtp.wrongs_flags);
|
||||
|
||||
/*
|
||||
* Now let's make one more call, RS1 should match and cached
|
||||
*/
|
||||
release_alice_bob();
|
||||
|
||||
prepare_alice_bob();
|
||||
|
||||
start_alice_bob_and_wait4secure();
|
||||
|
||||
s = zrtp_test_session_get(g_alice_sid, &alice_ses_info);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
assert_int_equal((int)ZRTP_BIT_RS1, alice_ses_info.zrtp.matches_flags);
|
||||
assert_int_equal((int)ZRTP_BIT_RS1, alice_ses_info.zrtp.cached_flags);
|
||||
assert_int_equal(0, alice_ses_info.zrtp.wrongs_flags);
|
||||
|
||||
/*
|
||||
* And one more time.. both RS1 and RS2 should be cached and should match.
|
||||
*/
|
||||
release_alice_bob();
|
||||
|
||||
prepare_alice_bob();
|
||||
|
||||
start_alice_bob_and_wait4secure();
|
||||
|
||||
s = zrtp_test_session_get(g_alice_sid, &alice_ses_info);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
assert_int_equal((int)(ZRTP_BIT_RS1 | ZRTP_BIT_RS2) , alice_ses_info.zrtp.matches_flags);
|
||||
assert_int_equal((int)(ZRTP_BIT_RS1 | ZRTP_BIT_RS2), alice_ses_info.zrtp.cached_flags);
|
||||
assert_int_equal(0, alice_ses_info.zrtp.wrongs_flags);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(go_secure_test, setup, teardown),
|
||||
unit_test_setup_teardown(go_secure_flags_test, setup, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
}
|
80
libs/libzrtp/test/hash_test.c
Normal file
80
libs/libzrtp/test/hash_test.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "zrtp.h"
|
||||
#include "cmockery/cmockery.h"
|
||||
|
||||
zrtp_global_t *zrtp;
|
||||
|
||||
void setup() {
|
||||
zrtp_status_t s;
|
||||
zrtp_config_t zrtp_config;
|
||||
|
||||
zrtp_config_defaults(&zrtp_config);
|
||||
|
||||
s = zrtp_init(&zrtp_config, &zrtp);
|
||||
assert_int_equal(s, zrtp_status_ok);
|
||||
}
|
||||
|
||||
void teardown() {
|
||||
zrtp_down(zrtp);
|
||||
}
|
||||
|
||||
static void sha1_hash_test() {
|
||||
zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_SRTP_HASH_HMAC_SHA1, zrtp);
|
||||
assert_non_null(hash);
|
||||
hash->hash_self_test(hash);
|
||||
}
|
||||
|
||||
static void sha1_hmac_test() {
|
||||
zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_SRTP_HASH_HMAC_SHA1, zrtp);
|
||||
assert_non_null(hash);
|
||||
hash->hmac_self_test(hash);
|
||||
}
|
||||
|
||||
static void sha256_hash_test() {
|
||||
zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA256, zrtp);
|
||||
assert_non_null(hash);
|
||||
hash->hash_self_test(hash);
|
||||
}
|
||||
|
||||
static void sha256_hmac_test() {
|
||||
zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA256, zrtp);
|
||||
assert_non_null(hash);
|
||||
hash->hmac_self_test(hash);
|
||||
}
|
||||
|
||||
static void sha384_hash_test() {
|
||||
zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA384, zrtp);
|
||||
assert_non_null(hash);
|
||||
hash->hash_self_test(hash);
|
||||
}
|
||||
|
||||
static void sha384_hmac_test() {
|
||||
zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA384, zrtp);
|
||||
assert_non_null(hash);
|
||||
hash->hmac_self_test(hash);
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(sha1_hash_test, setup, teardown),
|
||||
unit_test_setup_teardown(sha1_hmac_test, setup, teardown),
|
||||
unit_test_setup_teardown(sha256_hash_test, setup, teardown),
|
||||
unit_test_setup_teardown(sha256_hmac_test, setup, teardown),
|
||||
unit_test_setup_teardown(sha384_hash_test, setup, teardown),
|
||||
unit_test_setup_teardown(sha384_hmac_test, setup, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
}
|
92
libs/libzrtp/test/minor_bugs_test.c
Normal file
92
libs/libzrtp/test/minor_bugs_test.c
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "zrtp.h"
|
||||
#include "cmockery/cmockery.h"
|
||||
|
||||
zrtp_global_t *zrtp;
|
||||
|
||||
void setup() {
|
||||
zrtp_status_t s;
|
||||
zrtp_config_t zrtp_config;
|
||||
|
||||
zrtp_config_defaults(&zrtp_config);
|
||||
|
||||
s = zrtp_init(&zrtp_config, &zrtp);
|
||||
assert_int_equal(s, zrtp_status_ok);
|
||||
}
|
||||
|
||||
void teardown() {
|
||||
zrtp_down(zrtp);
|
||||
}
|
||||
|
||||
|
||||
static void session_init_fails_with_no_dh2k() {
|
||||
zrtp_profile_t profile;
|
||||
zrtp_status_t s;
|
||||
|
||||
zrtp_session_t *new_session;
|
||||
|
||||
/* Let's initialize ZRTP session with default profile first */
|
||||
zrtp_profile_defaults(&profile, zrtp);
|
||||
|
||||
new_session = NULL;
|
||||
s = zrtp_session_init(zrtp,
|
||||
&profile,
|
||||
ZRTP_SIGNALING_ROLE_INITIATOR,
|
||||
&new_session);
|
||||
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_non_null(new_session);
|
||||
|
||||
/* Then disable DH2K and leave just mandatory parameters */
|
||||
profile.pk_schemes[0] = ZRTP_PKTYPE_DH3072;
|
||||
profile.pk_schemes[1] = ZRTP_PKTYPE_MULT;
|
||||
profile.pk_schemes[2] = 0;
|
||||
|
||||
new_session = NULL;
|
||||
s = zrtp_session_init(zrtp,
|
||||
&profile,
|
||||
ZRTP_SIGNALING_ROLE_INITIATOR,
|
||||
&new_session);
|
||||
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_non_null(new_session);
|
||||
|
||||
/* Let's try to disable Multi key exchange, it should produce an error. */
|
||||
profile.pk_schemes[0] = ZRTP_PKTYPE_DH3072;
|
||||
profile.pk_schemes[1] = 0;
|
||||
|
||||
new_session = NULL;
|
||||
s = zrtp_session_init(zrtp,
|
||||
&profile,
|
||||
ZRTP_SIGNALING_ROLE_INITIATOR,
|
||||
&new_session);
|
||||
|
||||
assert_int_not_equal(zrtp_status_ok, s);
|
||||
assert_null(new_session);
|
||||
|
||||
/* Profile checking with one of mandatory components missing should return error too. */
|
||||
s = zrtp_profile_check(&profile, zrtp);
|
||||
assert_int_not_equal(zrtp_status_ok, s);
|
||||
|
||||
/* NOTE: we ignore memory leaks and don't destroy ZRTP sessions to make test sources cleaner */
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(session_init_fails_with_no_dh2k, setup, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
}
|
@ -1,866 +0,0 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include "zrtp.h"
|
||||
|
||||
#include "zrtp_test_core.h"
|
||||
#include "zrtp_test_queue.h"
|
||||
|
||||
#if (ZRTP_PLATFORM == ZP_WIN32) || (ZRTP_PLATFORM == ZP_WINCE)
|
||||
#include <windows.h>
|
||||
#elif (ZRTP_PLATFORM == ZP_DARWIN) || (ZRTP_PLATFORM == ZP_LINUX)
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
#define _ZTU_ "TEST"
|
||||
#define ZRTP_TEST_PACKET_MAX_SIZE 256
|
||||
#define ZRTP_TEST_STREAMS_COUNT 1
|
||||
|
||||
#define ZRTP_ENABLE_TEST 0
|
||||
|
||||
extern uint8_t hash_word_list_odd[256][12];
|
||||
extern uint8_t hash_word_list_even[256][10];
|
||||
|
||||
/*! Global data storage */
|
||||
typedef struct zrtp_test_global
|
||||
{
|
||||
mlist_t channels_head; /*! List of test channels*/
|
||||
zrtp_mutex_t* channels_protector; /*! Protector from list modifications */
|
||||
unsigned char is_log_enabled; /*! Allows debug messages logging */
|
||||
unsigned packets_rate; /*! Delay in miliseconds between RTP injection */
|
||||
unsigned channels_count; /*! Active channels count */
|
||||
unsigned secure_count; /*! Active channels count */
|
||||
zrtp_queue_t* queue; /*! Queue which emulate communication channel between ZRTP endpoints */
|
||||
unsigned char is_running; /*! Main test loop work while this is not 0 */
|
||||
} zrtp_test_global_t;
|
||||
|
||||
zrtp_test_global_t test_global; /*! zrtp test global data */
|
||||
zrtp_global_t* zrtp_global; /*! libzrtp global data */
|
||||
|
||||
|
||||
typedef struct zrtp_test_session zrtp_test_session_t;
|
||||
typedef struct zrtp_test_stream zrtp_test_stream_t;
|
||||
typedef struct zrtp_test_channel zrtp_test_channel_t;
|
||||
|
||||
#define ZRTP_TEST_PACKET_HEADER_LENGTH 16
|
||||
|
||||
|
||||
typedef struct zrtp_test_packet
|
||||
{
|
||||
uint32_t is_rtp; /*! Defines is packet RTP or RTCP */
|
||||
uint32_t length; /*! Packet Length in bytes */
|
||||
char body[1024]; /*! Packet body */
|
||||
} zrtp_test_packet_t;
|
||||
|
||||
struct zrtp_test_stream
|
||||
{
|
||||
zrtp_stream_t* zrtp_stream; /*! ZRTP stream associated test stream */
|
||||
zrtp_test_session_t* session; /*! Pointer to the parent test session */
|
||||
uint16_t seq; /*! RTP sequence number for media packets construction */
|
||||
uint32_t ssrc; /*! RTP local SSRC for media packets exchanging */
|
||||
uint32_t peer_ssrc; /*! RTP remote SSRC for media packets exchanging */
|
||||
};
|
||||
|
||||
struct zrtp_test_session
|
||||
{
|
||||
zrtp_test_stream_t streams[ZRTP_MAX_STREAMS_PER_SESSION]; /*! Streams array */
|
||||
unsigned streams_count; /*! Active streams counter */
|
||||
zrtp_session_t* zrtp_session; /*! ZRTP session associated test session */
|
||||
zrtp_test_channel_t *channel;
|
||||
mlist_t _list;
|
||||
};
|
||||
|
||||
struct zrtp_test_channel
|
||||
{
|
||||
zrtp_test_channel_id_t id; /*! Channel ID*/
|
||||
zrtp_test_session_t ses_left; /*! Left test session */
|
||||
zrtp_test_session_t ses_right; /*! Right test session */
|
||||
mlist_t _mlist;
|
||||
};
|
||||
|
||||
|
||||
zrtp_test_channel_t* find_channel_by_index(zrtp_test_channel_id_t chan_id);
|
||||
zrtp_test_channel_t* find_channel_with_closest_index(zrtp_test_channel_id_t chan_id);
|
||||
zrtp_test_stream_t* find_peer_stream_by_ssrc(uint32_t ssrc);
|
||||
|
||||
|
||||
/*============================================================================*/
|
||||
/* ZRTP Interfaces */
|
||||
/*============================================================================*/
|
||||
|
||||
static void on_zrtp_protocol_event(zrtp_stream_t *ctx, zrtp_protocol_event_t event)
|
||||
{
|
||||
}
|
||||
|
||||
static void on_zrtp_security_event(zrtp_stream_t *ctx, zrtp_security_event_t event)
|
||||
{
|
||||
}
|
||||
|
||||
static void on_zrtp_secure(zrtp_stream_t *ctx)
|
||||
{
|
||||
zrtp_test_stream_t *stream = (zrtp_test_stream_t*) zrtp_stream_get_userdata(ctx);
|
||||
zrtp_test_channel_t *channel = stream->session->channel;
|
||||
unsigned i = 0;
|
||||
unsigned char not_secure = 0;
|
||||
|
||||
ZRTP_LOG(1, (_ZTU_,"Stream is SECURE ssrc=%u ctx=%d\n", ctx->media_ctx.ssrc, ctx));
|
||||
|
||||
for (i=0; i<channel->ses_left.streams_count; i++) {
|
||||
if (ZRTP_STATE_SECURE != channel->ses_left.streams[i].zrtp_stream->state) {
|
||||
not_secure = 1;
|
||||
}
|
||||
}
|
||||
if (0 == not_secure) {
|
||||
for (i=0; i<channel->ses_right.streams_count; i++) {
|
||||
if (ZRTP_STATE_SECURE != channel->ses_right.streams[i].zrtp_stream->state) {
|
||||
not_secure = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == not_secure) {
|
||||
zrtp_session_info_t session_info;
|
||||
zrtp_stream_info_t a_stream_info;
|
||||
|
||||
test_global.secure_count++;
|
||||
|
||||
ZRTP_LOG(1, (_ZTU_,"===================================================\n"));
|
||||
ZRTP_LOG(1, (_ZTU_,"Entire Channel is SECURE. Total Secure count=%d\n", test_global.secure_count));
|
||||
ZRTP_LOG(1, (_ZTU_,"===================================================\n"));
|
||||
|
||||
zrtp_session_get(channel->ses_left.zrtp_session, &session_info);
|
||||
zrtp_stream_get(channel->ses_left.streams[0].zrtp_stream , &a_stream_info);
|
||||
|
||||
zrtp_log_print_sessioninfo(&session_info);
|
||||
zrtp_log_print_streaminfo(&a_stream_info);
|
||||
}
|
||||
}
|
||||
|
||||
static int on_send_packet(const zrtp_stream_t* ctx, char* message, unsigned int length)
|
||||
{
|
||||
zrtp_queue_elem_t* elem = zrtp_sys_alloc(sizeof(zrtp_queue_elem_t));
|
||||
if (elem) {
|
||||
zrtp_test_packet_t* packet = (zrtp_test_packet_t*) elem->data;
|
||||
elem->size = length;
|
||||
|
||||
packet->is_rtp = 1;
|
||||
packet->length = length;
|
||||
zrtp_memcpy(packet->body, message, length);
|
||||
|
||||
ZRTP_LOG(1, (_ZTU_,"\tSend message to ssrc=%u length=%d\n", ctx->media_ctx.ssrc, length));
|
||||
zrtp_test_queue_push(test_global.queue, elem);
|
||||
return zrtp_status_ok;
|
||||
} else {
|
||||
return zrtp_status_alloc_fail;
|
||||
}
|
||||
}
|
||||
|
||||
void zrtp_def_get_cache_path(char *path, uint32_t length)
|
||||
{
|
||||
#if (ZRTP_PLATFORM == ZP_WIN32) || (ZRTP_PLATFORM == ZP_WINCE)
|
||||
strncpy_s(path, length, "./zrtp_test_cache.dat", length);
|
||||
#else
|
||||
strncpy(path, "./zrtp_test_cache.dat", length);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*============================================================================*/
|
||||
/* Sessions Life-Cycle Logic */
|
||||
/*============================================================================*/
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#if (ZRTP_PLATFORM == ZP_WIN32) || (ZRTP_PLATFORM == ZP_WINCE)
|
||||
DWORD WINAPI process_incoming(void *param)
|
||||
#else
|
||||
void *process_incoming(void *param)
|
||||
#endif
|
||||
{
|
||||
ZRTP_LOG(1, (_ZTU_,"======> STARTING Incoming processor\n"));
|
||||
while (test_global.is_running)
|
||||
{
|
||||
zrtp_test_packet_t* packet = NULL;
|
||||
zrtp_queue_elem_t* elem = NULL;
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
zrtp_test_stream_t *stream = NULL;
|
||||
int is_protocol = 0;
|
||||
|
||||
/* Get packet from the "Network" and find aapropriate stream to process it */
|
||||
elem = zrtp_test_queue_pop(test_global.queue);
|
||||
packet = (zrtp_test_packet_t*) elem->data;
|
||||
|
||||
/* We have ssrc in the packet, which indetifies stream that had send it to us.
|
||||
* so now we have to find appropriate stream which has to process that packet.
|
||||
*/
|
||||
if (packet->is_rtp) {
|
||||
ZRTP_UNALIGNED(zrtp_rtp_hdr_t) *hdr = (zrtp_rtp_hdr_t*) (packet->body);
|
||||
if (ZRTP_PACKETS_MAGIC == zrtp_ntoh32(hdr->ts)) {
|
||||
is_protocol = 1;
|
||||
ZRTP_LOG(1, (_ZTU_,"\n"));
|
||||
}
|
||||
stream = find_peer_stream_by_ssrc(hdr->ssrc);
|
||||
} else {
|
||||
ZRTP_UNALIGNED(zrtp_rtcp_hdr_t) *hdr = (zrtp_rtcp_hdr_t*) (packet->body);
|
||||
stream = find_peer_stream_by_ssrc(hdr->ssrc);
|
||||
}
|
||||
|
||||
if (!stream) {
|
||||
zrtp_sys_free(elem);
|
||||
ZRTP_LOG(1, (_ZTU_,"process_incoming(): ERROR! can't found peer stream!\n"));
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Process incoming packet by libzrtp. Is this a RTP media packet - copy it to the buffer
|
||||
* to print out later.
|
||||
*/
|
||||
if (packet->is_rtp) {
|
||||
s = zrtp_process_srtp(stream->zrtp_stream, packet->body, &packet->length);
|
||||
} else {
|
||||
s = zrtp_process_srtcp(stream->zrtp_stream, packet->body, &packet->length);
|
||||
}
|
||||
|
||||
|
||||
if (!is_protocol)
|
||||
{
|
||||
char *body;
|
||||
if (packet->is_rtp) {
|
||||
body = packet->body + sizeof(zrtp_rtp_hdr_t);
|
||||
body[packet->length - sizeof(zrtp_rtp_hdr_t)] = 0;
|
||||
} else {
|
||||
body = packet->body + sizeof(zrtp_rtcp_hdr_t);
|
||||
body[packet->length - sizeof(zrtp_rtcp_hdr_t)] = 0;
|
||||
}
|
||||
|
||||
switch (s)
|
||||
{
|
||||
case zrtp_status_ok: {
|
||||
ZRTP_LOG(1, (_ZTU_,"Incoming: (%s) [%p:ssrc=%u] INPUT. <%s> decrypted %d bytes.\n",
|
||||
zrtp_log_state2str(stream->zrtp_stream->state), stream->zrtp_stream, stream->ssrc, body, packet->length));
|
||||
} break;
|
||||
|
||||
case zrtp_status_drop: {
|
||||
ZRTP_LOG(1, (_ZTU_,"Incoming: (%s) [%p:ssrc=%u] INPUT DROPPED. <%s>\n",
|
||||
zrtp_log_state2str(stream->zrtp_stream->state), stream->zrtp_stream, stream->ssrc, body));
|
||||
} break;
|
||||
|
||||
case zrtp_status_fail: {
|
||||
ZRTP_LOG(1, (_ZTU_,"Incoming: (%s) [%p:ssrc=%u] DECRYPT FAILED. <%s>\n",
|
||||
zrtp_log_state2str(stream->zrtp_stream->state), stream->zrtp_stream, stream->ssrc, body));
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
zrtp_sys_free(elem);
|
||||
|
||||
/*
|
||||
* When zrtp_stream is in the pending clear state and other side wants to send plain
|
||||
* traffic. We have to call zrtp_clear_stream().
|
||||
*/
|
||||
if (stream->zrtp_stream->state == ZRTP_STATE_PENDINGCLEAR) {
|
||||
zrtp_stream_clear(stream->zrtp_stream);
|
||||
}
|
||||
} /* while is running */
|
||||
|
||||
#if (ZRTP_PLATFORM == ZP_WIN32) || (ZRTP_PLATFORM == ZP_WINCE)
|
||||
return 0;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#if (ZRTP_PLATFORM == ZP_WIN32) || (ZRTP_PLATFORM == ZP_WINCE)
|
||||
DWORD WINAPI process_outgoing(void *param)
|
||||
#else
|
||||
void *process_outgoing(void *param)
|
||||
#endif
|
||||
{
|
||||
unsigned packets_counter = 0;
|
||||
|
||||
ZRTP_LOG(1, (_ZTU_,"======> STARTING Outgoing processor\n"));
|
||||
while (test_global.is_running)
|
||||
{
|
||||
zrtp_test_channel_id_t channel_id = 0;
|
||||
zrtp_test_channel_t* channel = NULL;
|
||||
zrtp_test_session_t* session = NULL;
|
||||
unsigned i;
|
||||
|
||||
zrtp_sleep(test_global.packets_rate);
|
||||
|
||||
if ((0 == test_global.channels_count) || (0 == test_global.secure_count)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Get random channel to operate with and select random peer */
|
||||
zrtp_randstr(zrtp_global, (unsigned char*)&channel_id, sizeof(zrtp_test_channel_id_t));
|
||||
channel = find_channel_with_closest_index(channel_id);
|
||||
if (!channel) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ZRTP_LOG(1, (_ZTU_,"\n"));
|
||||
ZRTP_LOG(1, (_ZTU_,"Out. Generate packet by channel N=%u and %s session.\n",
|
||||
channel->id, ((channel_id % 100) > 50) ? "RIGHT": "LEFT"));
|
||||
|
||||
session = ((channel_id % 100) > 50) ? &channel->ses_right : &channel->ses_left;
|
||||
|
||||
/* Generate RTP or RTCP packet for every stream within the session */
|
||||
for (i=0; i<session->streams_count; i++)
|
||||
{
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
zrtp_test_packet_t* packet;
|
||||
zrtp_queue_elem_t* elem;
|
||||
zrtp_test_stream_t* stream = &session->streams[i];
|
||||
char* word = NULL;
|
||||
|
||||
elem = zrtp_sys_alloc(sizeof(zrtp_queue_elem_t));
|
||||
if (!elem) {
|
||||
break;
|
||||
}
|
||||
packet = (zrtp_test_packet_t*) elem->data;
|
||||
packet->is_rtp = (packets_counter++ % 20); /* Every 20-th packet is RTCP */
|
||||
|
||||
/*
|
||||
* Construct RTP/RTCP Packet
|
||||
*/
|
||||
if (packet->is_rtp)
|
||||
{
|
||||
ZRTP_UNALIGNED(zrtp_rtp_hdr_t) *rtp_hdr = (zrtp_rtp_hdr_t*)packet->body;
|
||||
|
||||
/* Fill RTP Header according to the specification */
|
||||
zrtp_memset(rtp_hdr, 0, sizeof(zrtp_rtp_hdr_t));
|
||||
rtp_hdr->version = 2; /* Current RTP version 2 */
|
||||
rtp_hdr->pt = 0; /* PCMU padding type */
|
||||
rtp_hdr->ssrc = stream->ssrc; /* Use ssrc for addressing like in real RTP */
|
||||
if (stream->seq >= 0xFFFF) {
|
||||
stream->seq = 0;
|
||||
}
|
||||
rtp_hdr->seq = zrtp_hton16(stream->seq++);
|
||||
rtp_hdr->ts = zrtp_hton32((uint32_t)(zrtp_time_now()/1000));
|
||||
|
||||
/* Get RTP body from PGP words lists */
|
||||
word = (char*)(i ? hash_word_list_odd[packets_counter % 256] : hash_word_list_even[packets_counter % 256]);
|
||||
|
||||
zrtp_memcpy(packet->body + sizeof(zrtp_rtp_hdr_t), word, (uint32_t)strlen(word));
|
||||
packet->length = sizeof(zrtp_rtp_hdr_t) + (uint32_t)strlen(word);
|
||||
|
||||
/* Process RTP media with libzrtp */
|
||||
s = zrtp_process_rtp(stream->zrtp_stream, packet->body, &packet->length);
|
||||
}
|
||||
else
|
||||
{
|
||||
ZRTP_UNALIGNED(zrtp_rtcp_hdr_t) *rtcp_hdr = (zrtp_rtcp_hdr_t*)packet->body;
|
||||
|
||||
/* Fill RTCP Header according to the specification */
|
||||
rtcp_hdr->rc = 0;
|
||||
rtcp_hdr->version = 2;
|
||||
rtcp_hdr->ssrc = stream->ssrc;
|
||||
|
||||
/* Get RTP body from PGP words lists. Put RTCP marker at the beginning */
|
||||
zrtp_memcpy(packet->body + sizeof(zrtp_rtcp_hdr_t), "RTCP", 4);
|
||||
word = (char*)( i ? hash_word_list_odd[packets_counter % 256] : hash_word_list_even[packets_counter % 256]);
|
||||
|
||||
zrtp_memcpy(packet->body + sizeof(zrtp_rtcp_hdr_t) + 4, word, (uint32_t)strlen(word));
|
||||
packet->length = sizeof(zrtp_rtcp_hdr_t) + (uint32_t)strlen(word) + 4;
|
||||
/* RTCP packets sould be 32 byes aligned */
|
||||
packet->length += (packet->length % 4) ? (4 - packet->length % 4) : 0;
|
||||
|
||||
/* Process RTCP control with libzrtp */
|
||||
s = zrtp_process_rtcp(stream->zrtp_stream, packet->body, &packet->length);
|
||||
}
|
||||
|
||||
/* Handle zrtp_process_xxx() instructions */
|
||||
switch (s)
|
||||
{
|
||||
/* Put the packet to the queue ==> send packet to the other side pear */
|
||||
case zrtp_status_ok: {
|
||||
ZRTP_LOG(3, (_ZTU_,"Outgoing: (%s) [%p:ssrc=%u] OUTPUT. <%s%s> encrypted %d bytes.\n",
|
||||
zrtp_log_state2str(stream->zrtp_stream->state), stream->zrtp_stream, stream->ssrc, packet->is_rtp ? "" : "RTCP", word, packet->length));
|
||||
zrtp_test_queue_push(test_global.queue, elem);
|
||||
} break;
|
||||
|
||||
case zrtp_status_drop: {
|
||||
ZRTP_LOG(1, (_ZTU_,"Outgoing: (%s) [%p:ssrc=%u] OUTPUT DROPPED.\n",
|
||||
zrtp_log_state2str(stream->zrtp_stream->state), stream->zrtp_stream, stream->ssrc));
|
||||
} break;
|
||||
|
||||
case zrtp_status_fail: {
|
||||
ZRTP_LOG(1, (_ZTU_,"Outgoing: (%s) [%p:ssrc=%u] ENCRYPT FAILED.\n",
|
||||
zrtp_log_state2str(stream->zrtp_stream->state), stream->zrtp_stream, stream->ssrc));
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (zrtp_status_ok != s) {
|
||||
zrtp_sys_free(packet);
|
||||
}
|
||||
|
||||
} /* for (every stream within the session) */
|
||||
} /* while is running */
|
||||
|
||||
#if (ZRTP_PLATFORM == ZP_WIN32) || (ZRTP_PLATFORM == ZP_WINCE)
|
||||
return 0;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static zrtp_status_t init_test_session( zrtp_test_session_t *session,
|
||||
zrtp_profile_t *zrtp_profile,
|
||||
unsigned nstreams)
|
||||
{
|
||||
unsigned i = 0;
|
||||
g_zrtp_cfg zid;
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
|
||||
session->streams_count = nstreams;
|
||||
|
||||
/* Allocate ZRTP session */
|
||||
zrtp_randstr(zrtp_global, (unsigned char*)&zid, sizeof(g_zrtp_cfg));
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"INITIALIZE NEW SESSION ctx=%p:\n", session));
|
||||
ZRTP_LOG(3, (_ZTU_,"---------------------------------------------------\n"));
|
||||
|
||||
s = zrtp_session_init(zrtp_global, zrtp_profile, zid, 1, &session->zrtp_session);
|
||||
if (zrtp_status_ok != s) {
|
||||
ZRTP_LOG(3, (_ZTU_,"ERROR! can't initalize ZRTP session d=%d.\n", s));
|
||||
return s;
|
||||
}
|
||||
|
||||
zrtp_session_set_userdata(session->zrtp_session, session);
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"Attach %d ZRTP streams.\n", session->streams_count));
|
||||
/* ZRTP session is ready for use. Now it's time to attach streams to it */
|
||||
for (i=0; i<session->streams_count; i++)
|
||||
{
|
||||
zrtp_test_stream_t *stream = &session->streams[i];
|
||||
|
||||
/* Create random sequence number and ssrc for packets generation */
|
||||
zrtp_randstr(zrtp_global, (unsigned char*)&stream->seq, sizeof(stream->seq));
|
||||
zrtp_randstr(zrtp_global, (unsigned char*)&stream->ssrc, sizeof(stream->ssrc));
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"Created stream N%d ssrc=%u seq=%d ctx=%p\n", i, stream->ssrc, stream->seq, stream));
|
||||
|
||||
/* Attach zrtp_stream to zrtp_session */
|
||||
s = zrtp_stream_attach(session->zrtp_session, &stream->zrtp_stream);
|
||||
if (zrtp_status_ok != s) {
|
||||
ZRTP_LOG(3, (_ZTU_,"ERROR! can't attach ZRTP stream.\n"));
|
||||
break;
|
||||
}
|
||||
zrtp_stream_set_userdata(stream->zrtp_stream, stream);
|
||||
stream->session = session;
|
||||
}
|
||||
|
||||
if (i != session->streams_count) {
|
||||
zrtp_session_down(session->zrtp_session);
|
||||
return zrtp_status_fail;
|
||||
}
|
||||
|
||||
return zrtp_status_ok;
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int zrtp_test_channel_create( const zrtp_test_channel_config_t* config,
|
||||
zrtp_test_channel_id_t* chan_id)
|
||||
{
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
zrtp_test_channel_t* channel = NULL;
|
||||
unsigned streams_number = 1;
|
||||
|
||||
|
||||
/*
|
||||
* Create two connection for each side of the call.
|
||||
* They will have the same id in order to simplify calls managing.
|
||||
*/
|
||||
channel = zrtp_sys_alloc(sizeof(zrtp_test_channel_t));
|
||||
if (!channel) {
|
||||
return -1;
|
||||
}
|
||||
zrtp_memset(channel, 0, sizeof(zrtp_test_channel_t));
|
||||
|
||||
/* Generate new unique ID for the channel */
|
||||
zrtp_randstr(zrtp_global, (unsigned char*)chan_id, sizeof(zrtp_test_channel_id_t));
|
||||
|
||||
ZRTP_LOG(1, (_ZTU_,"=====> CREATE NEW CHANNEL ID=%u ctx=%p.\n", chan_id, channel));
|
||||
|
||||
/*
|
||||
* Alloacte and initalize ZRTP crypto stuffs
|
||||
*/
|
||||
do {
|
||||
zrtp_profile_t zrtp_profile;
|
||||
unsigned i = 0;
|
||||
|
||||
/*
|
||||
* Use default ZRTP configuration with slitely changes:
|
||||
* - enable "allowclear" to be able to test more scenarios
|
||||
*/
|
||||
zrtp_profile_defaults(&zrtp_profile, zrtp_global);
|
||||
zrtp_profile.allowclear = 1;
|
||||
zrtp_profile.autosecure = 1;
|
||||
|
||||
channel->ses_left.streams_count = streams_number;
|
||||
#if (ZRTP_ENABLE_TEST == 1)
|
||||
zrtp_profile.pk_schemes[0] = ZRTP_PKTYPE_EC384P;
|
||||
zrtp_profile.pk_schemes[1] = ZRTP_PKTYPE_DH3072;
|
||||
zrtp_profile.pk_schemes[2] = ZRTP_PKTYPE_MULT;
|
||||
zrtp_profile.pk_schemes[3] = 0;
|
||||
#endif
|
||||
s = init_test_session(&channel->ses_left, &zrtp_profile, 1);
|
||||
if (zrtp_status_ok != s) {
|
||||
break;
|
||||
}
|
||||
channel->ses_left.channel = channel;
|
||||
|
||||
channel->ses_right.streams_count = streams_number;
|
||||
#if (ZRTP_ENABLE_TEST == 1)
|
||||
zrtp_profile.autosecure = 1;
|
||||
zrtp_profile.pk_schemes[0] = ZRTP_PKTYPE_EC384P;
|
||||
zrtp_profile.pk_schemes[1] = ZRTP_PKTYPE_DH2048;
|
||||
zrtp_profile.pk_schemes[2] = ZRTP_PKTYPE_DH3072;
|
||||
zrtp_profile.pk_schemes[3] = ZRTP_PKTYPE_MULT;
|
||||
zrtp_profile.pk_schemes[4] = 0;
|
||||
#endif
|
||||
s = init_test_session(&channel->ses_right, &zrtp_profile, 1);
|
||||
if (zrtp_status_ok != s) {
|
||||
break;
|
||||
}
|
||||
channel->ses_right.channel = channel;
|
||||
|
||||
/* Make cross-references to allow left stream to communicate with the right one. */
|
||||
for (i=0; i<streams_number; i++) {
|
||||
channel->ses_left.streams[i].peer_ssrc = channel->ses_right.streams[i].ssrc;
|
||||
channel->ses_right.streams[i].peer_ssrc = channel->ses_left.streams[i].ssrc;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
if (zrtp_status_ok != s) {
|
||||
zrtp_sys_free(channel);
|
||||
} else {
|
||||
channel->id = *chan_id;
|
||||
zrtp_mutex_lock(test_global.channels_protector);
|
||||
mlist_add(&test_global.channels_head, &channel->_mlist);
|
||||
zrtp_mutex_unlock(test_global.channels_protector);
|
||||
}
|
||||
|
||||
test_global.channels_count++;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static void down_test_session(zrtp_test_session_t *session)
|
||||
{
|
||||
zrtp_session_down(session->zrtp_session);
|
||||
};
|
||||
|
||||
int zrtp_test_channel_delete(zrtp_test_channel_id_t chan_id)
|
||||
{
|
||||
zrtp_test_channel_t* channel = find_channel_by_index(chan_id);
|
||||
if (channel)
|
||||
{
|
||||
test_global.channels_count--;
|
||||
|
||||
zrtp_mutex_lock(test_global.channels_protector);
|
||||
mlist_del(&channel->_mlist);
|
||||
zrtp_mutex_unlock(test_global.channels_protector);
|
||||
|
||||
down_test_session(&channel->ses_left);
|
||||
down_test_session(&channel->ses_right);
|
||||
|
||||
zrtp_sys_free(channel);
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
typedef enum
|
||||
{
|
||||
TEST_ACTION_START = 0,
|
||||
TEST_ACTION_SECURE,
|
||||
TEST_ACTION_CLEAR,
|
||||
TEST_ACTION_STOP
|
||||
} zrtp_test_session_action_t;
|
||||
|
||||
static void test_session_do_action(zrtp_test_session_t *session, zrtp_test_session_action_t action)
|
||||
{
|
||||
unsigned i = 0;
|
||||
if (session->zrtp_session)
|
||||
{
|
||||
for (i=0; i<session->streams_count; i++) {
|
||||
switch (action) {
|
||||
case TEST_ACTION_START:
|
||||
{
|
||||
char buff[65];
|
||||
ZRTP_LOG(1, (_ZTU_,"=====> START TEST SESSION ID=%u ctx=%p.\n", session->channel->id, session->channel));
|
||||
zrtp_stream_start(session->streams[i].zrtp_stream, zrtp_ntoh32(session->streams[i].ssrc));
|
||||
zrtp_signaling_hash_get(session->streams[i].zrtp_stream, buff, sizeof(buff));
|
||||
break;
|
||||
}
|
||||
case TEST_ACTION_STOP:
|
||||
ZRTP_LOG(1, (_ZTU_,"=====> STOP TEST SESSION ID=%u ctx=%p.\n", session->channel->id, session->channel));
|
||||
zrtp_stream_stop(session->streams[i].zrtp_stream);
|
||||
break;
|
||||
case TEST_ACTION_SECURE:
|
||||
ZRTP_LOG(1, (_ZTU_,"=====> SECURE TEST SESSION ID=%u ctx=%p.\n", session->channel->id, session->channel));
|
||||
zrtp_stream_secure(session->streams[i].zrtp_stream);
|
||||
break;
|
||||
case TEST_ACTION_CLEAR:
|
||||
ZRTP_LOG(1, (_ZTU_,"=====> CLEAR TEST SESSION ID=%u ctx=%p.\n", session->channel->id, session->channel));
|
||||
zrtp_stream_clear(session->streams[i].zrtp_stream);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static int test_channel_do_action(zrtp_test_channel_id_t chan_id, zrtp_test_session_action_t action)
|
||||
{
|
||||
zrtp_test_channel_t* channel = find_channel_by_index(chan_id);
|
||||
if (channel) {
|
||||
test_session_do_action(&channel->ses_left, action);
|
||||
test_session_do_action(&channel->ses_right, action);
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int zrtp_test_channel_start(zrtp_test_channel_id_t chan_id) {
|
||||
return test_channel_do_action(chan_id, TEST_ACTION_START);
|
||||
}
|
||||
|
||||
int zrtp_test_channel_secure(zrtp_test_channel_id_t chan_id) {
|
||||
return test_channel_do_action(chan_id, TEST_ACTION_SECURE);
|
||||
}
|
||||
|
||||
int zrtp_test_channel_clear(zrtp_test_channel_id_t chan_id) {
|
||||
return test_channel_do_action(chan_id, TEST_ACTION_CLEAR);
|
||||
}
|
||||
|
||||
int zrtp_test_channel_stop(zrtp_test_channel_id_t chan_id) {
|
||||
return test_channel_do_action(chan_id, TEST_ACTION_STOP);
|
||||
}
|
||||
|
||||
|
||||
/*============================================================================*/
|
||||
/* Test Routine */
|
||||
/*============================================================================*/
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int start_processors(int count)
|
||||
{
|
||||
int32_t i;
|
||||
for (i = 0; i<count; i++)
|
||||
{
|
||||
if (0 != zrtp_thread_create(process_incoming, NULL)) {
|
||||
return -1;
|
||||
}
|
||||
if (0 != zrtp_thread_create(process_outgoing, NULL)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int zrtp_test_zrtp_init()
|
||||
{
|
||||
int result = -1;
|
||||
zrtp_status_t s = zrtp_status_ok;
|
||||
zrtp_config_t zrtp_config;
|
||||
|
||||
ZRTP_LOG(1, (_ZTU_,"=====>Start ZRTP Test-Unite Core initalization.\n"));
|
||||
|
||||
zrtp_memset(&test_global, 0, sizeof(test_global));
|
||||
|
||||
ZRTP_LOG(1, (_ZTU_,"Create internal components...\n"));
|
||||
do {
|
||||
/* Create global objects: channels list and communication queue */
|
||||
init_mlist(&test_global.channels_head);
|
||||
|
||||
s = zrtp_mutex_init(&test_global.channels_protector);
|
||||
if (zrtp_status_ok != s) {
|
||||
ZRTP_LOG(1, (_ZTU_,"ERROR! Can't create channels protector %d\n", s));
|
||||
break;
|
||||
}
|
||||
|
||||
s = zrtp_test_queue_create(&test_global.queue);
|
||||
if (zrtp_status_ok != s) {
|
||||
ZRTP_LOG(1, (_ZTU_,"ERROR! Can't create global queue: %s\n", s));
|
||||
break;
|
||||
}
|
||||
|
||||
/* Start several threads to process test zrtp channels */
|
||||
test_global.is_running = 1;
|
||||
result = start_processors(ZRTP_TEST_STREAMS_COUNT);
|
||||
if (0 != result) {
|
||||
break;
|
||||
}
|
||||
|
||||
ZRTP_LOG(1, (_ZTU_,"Configuring and Initalizing ZRTP engine...\n"));
|
||||
/* Reset global values to defaults */
|
||||
test_global.is_log_enabled = 1;
|
||||
test_global.packets_rate = 500;
|
||||
test_global.channels_count = 0;
|
||||
|
||||
/* Initalize ZRTP Engine */
|
||||
zrtp_config_defaults(&zrtp_config);
|
||||
zrtp_config.lic_mode = ZRTP_LICENSE_MODE_ACTIVE;
|
||||
zrtp_memcpy(zrtp_config.client_id, "ZRTP Test Unite!", 16);
|
||||
|
||||
zrtp_config.cb.event_cb.on_zrtp_secure = on_zrtp_secure;
|
||||
zrtp_config.cb.event_cb.on_zrtp_security_event = on_zrtp_security_event;
|
||||
zrtp_config.cb.event_cb.on_zrtp_protocol_event = on_zrtp_protocol_event;
|
||||
zrtp_config.cb.misc_cb.on_send_packet = on_send_packet;
|
||||
|
||||
s = zrtp_init(&zrtp_config, &zrtp_global);
|
||||
if (zrtp_status_ok != s) {
|
||||
ZRTP_LOG(1, (_ZTU_,"ERROR! zrtp_init() failed with status=%d.\n", s));
|
||||
break;
|
||||
}
|
||||
|
||||
result = 0;
|
||||
} while (0);
|
||||
|
||||
if (0 != result) {
|
||||
if (!test_global.channels_protector) {
|
||||
zrtp_mutex_destroy(test_global.channels_protector);
|
||||
}
|
||||
if (!test_global.queue) {
|
||||
zrtp_test_queue_destroy(test_global.queue);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int zrtp_test_zrtp_down()
|
||||
{
|
||||
mlist_t* node = NULL,* tmp = NULL;
|
||||
|
||||
ZRTP_LOG(1, (_ZTU_,"=====> Destroying ZRTP Test Application:\n"));
|
||||
ZRTP_LOG(1, (_ZTU_,"Stop all running threads.\n"));
|
||||
|
||||
/* Stop Main Processing Loop */
|
||||
test_global.is_running = 0;
|
||||
|
||||
ZRTP_LOG(1, (_ZTU_,"Destroy all active connections.\n"));
|
||||
/* Stop and destroy all active sessions */
|
||||
zrtp_mutex_lock(test_global.channels_protector);
|
||||
mlist_for_each_safe(node, tmp, &test_global.channels_head) {
|
||||
zrtp_test_channel_t* result = (zrtp_test_channel_t*) mlist_get_struct(zrtp_test_channel_t, _mlist, node);
|
||||
zrtp_test_channel_delete(result->id);
|
||||
}
|
||||
zrtp_mutex_unlock(test_global.channels_protector);
|
||||
|
||||
ZRTP_LOG(1, (_ZTU_,"Destroy ZRTP Engine.\n"));
|
||||
/* Destroy libzrtp and all utility components */
|
||||
zrtp_down(zrtp_global);
|
||||
|
||||
if (!test_global.channels_protector) {
|
||||
zrtp_mutex_destroy(test_global.channels_protector);
|
||||
}
|
||||
if (!test_global.queue) {
|
||||
zrtp_test_queue_destroy(test_global.queue);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
zrtp_test_channel_t* find_channel_by_index(zrtp_test_channel_id_t chan_id)
|
||||
{
|
||||
unsigned char is_found = 0;
|
||||
mlist_t* node = NULL,* tmp = NULL;
|
||||
zrtp_test_channel_t* result = NULL;
|
||||
|
||||
zrtp_mutex_lock(test_global.channels_protector);
|
||||
mlist_for_each_safe(node, tmp, &test_global.channels_head) {
|
||||
result = (zrtp_test_channel_t*) mlist_get_struct(zrtp_test_channel_t, _mlist, node);
|
||||
if (result->id == chan_id) {
|
||||
is_found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
zrtp_mutex_unlock(test_global.channels_protector);
|
||||
|
||||
return (is_found) ? result : NULL;
|
||||
}
|
||||
|
||||
zrtp_test_channel_t* find_channel_with_closest_index(zrtp_test_channel_id_t chan_id)
|
||||
{
|
||||
unsigned char is_found = 0;
|
||||
mlist_t* node = NULL,* tmp = NULL;
|
||||
zrtp_test_channel_t* result = NULL;
|
||||
zrtp_test_channel_t* left = NULL;
|
||||
|
||||
zrtp_mutex_lock(test_global.channels_protector);
|
||||
mlist_for_each_safe(node, tmp, &test_global.channels_head) {
|
||||
result = (zrtp_test_channel_t*) mlist_get_struct(zrtp_test_channel_t, _mlist, node);
|
||||
if (result->id > chan_id) {
|
||||
is_found = 1;
|
||||
break;
|
||||
} else {
|
||||
left = result;
|
||||
}
|
||||
}
|
||||
zrtp_mutex_unlock(test_global.channels_protector);
|
||||
|
||||
return (is_found) ? result : left;
|
||||
}
|
||||
|
||||
zrtp_test_stream_t* find_peer_stream_by_ssrc(uint32_t ssrc)
|
||||
{
|
||||
unsigned char is_found = 0;
|
||||
mlist_t *node = NULL, *tmp = NULL;
|
||||
zrtp_test_stream_t *result = NULL;
|
||||
|
||||
zrtp_mutex_lock(test_global.channels_protector);
|
||||
mlist_for_each_safe(node, tmp, &test_global.channels_head)
|
||||
{
|
||||
zrtp_test_channel_t *channel = (zrtp_test_channel_t*) mlist_get_struct(zrtp_test_channel_t, _mlist, node);
|
||||
unsigned i = 0;
|
||||
|
||||
for (i=0; i<channel->ses_left.streams_count; i++) {
|
||||
zrtp_test_stream_t *stream = &channel->ses_left.streams[i];
|
||||
if (stream->ssrc == ssrc) {
|
||||
is_found = 1;
|
||||
result = &channel->ses_right.streams[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i<channel->ses_right.streams_count; i++) {
|
||||
zrtp_test_stream_t *stream = &channel->ses_right.streams[i];
|
||||
if (stream->ssrc == ssrc) {
|
||||
is_found = 1;
|
||||
result = &channel->ses_left.streams[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
zrtp_mutex_unlock(test_global.channels_protector);
|
||||
|
||||
return (is_found) ? result : NULL;
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#ifndef __ZRTP_TEST_CORE_H__
|
||||
#define __ZRTP_TEST_CORE_H__
|
||||
|
||||
#include "zrtp.h"
|
||||
|
||||
extern zrtp_global_t* zrtp_global;
|
||||
|
||||
typedef uint32_t zrtp_test_channel_id_t;
|
||||
|
||||
typedef struct zrtp_test_channel_config
|
||||
{
|
||||
unsigned streams_count;
|
||||
unsigned char is_autosecure;
|
||||
unsigned char is_preshared;
|
||||
} zrtp_test_channel_config_t;
|
||||
|
||||
void zrtp_test_crypto(zrtp_global_t* zrtp);
|
||||
|
||||
int zrtp_test_zrtp_init();
|
||||
int zrtp_test_zrtp_down();
|
||||
|
||||
int zrtp_test_channel_create( const zrtp_test_channel_config_t* config,
|
||||
zrtp_test_channel_id_t* chan_id);
|
||||
int zrtp_test_channel_delete(zrtp_test_channel_id_t chan_id);
|
||||
int zrtp_test_channel_start(zrtp_test_channel_id_t chan_id);
|
||||
int zrtp_test_channel_secure(zrtp_test_channel_id_t chan_id);
|
||||
int zrtp_test_channel_clear(zrtp_test_channel_id_t chan_id);
|
||||
|
||||
#endif /*__ZRTP_TEST_CORE_H__*/
|
@ -1,447 +0,0 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include "zrtp.h"
|
||||
|
||||
#define _ZTU_ "libzrtp_test"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void cipher_test(zrtp_global_t *zrtp)
|
||||
{
|
||||
zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES128, zrtp);
|
||||
if (NULL == cipher) {
|
||||
ZRTP_LOG(1, (_ZTU_,"ERROR! can't find ZRTP_CIPHER_AES128 cipher component\n"));
|
||||
} else {
|
||||
cipher->self_test(cipher, ZRTP_CIPHER_MODE_CFB);
|
||||
cipher->self_test(cipher, ZRTP_CIPHER_MODE_CTR);
|
||||
}
|
||||
|
||||
cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES256, zrtp);
|
||||
if (NULL == cipher) {
|
||||
ZRTP_LOG(1, (_ZTU_,"ERROR! can't find ZRTP_CIPHER_AES256 cipher component\n"));
|
||||
} else {
|
||||
cipher->self_test(cipher, ZRTP_CIPHER_MODE_CFB);
|
||||
cipher->self_test(cipher, ZRTP_CIPHER_MODE_CTR);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static zrtp_status_t hash_test(zrtp_global_t *zrtp)
|
||||
{
|
||||
zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_SRTP_HASH_HMAC_SHA1, zrtp);
|
||||
if (NULL == hash) {
|
||||
ZRTP_LOG(1, (_ZTU_,"ERROR! can't find ZRTP_SRTP_HASH_HMAC_SHA1 component\n"));
|
||||
} else {
|
||||
hash->hash_self_test(hash);
|
||||
hash->hmac_self_test(hash);
|
||||
}
|
||||
|
||||
hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA256, zrtp);
|
||||
if (NULL == hash) {
|
||||
ZRTP_LOG(1, (_ZTU_,"ERROR! can't find ZRTP_HASH_SHA256 component\n"));
|
||||
} else {
|
||||
hash->hash_self_test(hash);
|
||||
hash->hmac_self_test(hash);
|
||||
}
|
||||
|
||||
hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA384, zrtp);
|
||||
if (NULL == hash) {
|
||||
ZRTP_LOG(1, (_ZTU_,"ERROR! can't find ZRTP_HASH_SHA384 component\n"));
|
||||
} else {
|
||||
hash->hash_self_test(hash);
|
||||
hash->hmac_self_test(hash);
|
||||
}
|
||||
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static zrtp_status_t dh_test(zrtp_global_t *zrtp)
|
||||
{
|
||||
zrtp_pk_scheme_t *pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_DH2048, zrtp);
|
||||
if (!pks) {
|
||||
ZRTP_LOG(1, (_ZTU_,"ERROR! can't find ZRTP_PKTYPE_DH2048 component\n"));
|
||||
} else {
|
||||
pks->self_test(pks);
|
||||
}
|
||||
|
||||
pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_DH3072, zrtp);
|
||||
if (!pks) {
|
||||
ZRTP_LOG(1, (_ZTU_,"ERROR! can't find ZRTP_PKTYPE_DH3072 component\n"));
|
||||
} else {
|
||||
pks->self_test(pks);
|
||||
}
|
||||
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static zrtp_status_t ecdh_test(zrtp_global_t *zrtp)
|
||||
{
|
||||
zrtp_pk_scheme_t *pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_EC256P, zrtp);
|
||||
if (!pks) {
|
||||
ZRTP_LOG(1, (_ZTU_,"ERROR! can't find ZRTP_PKTYPE_EC256P component\n"));
|
||||
} else {
|
||||
pks->self_test(pks);
|
||||
}
|
||||
|
||||
pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_EC384P, zrtp);
|
||||
if (!pks) {
|
||||
ZRTP_LOG(1, (_ZTU_,"ERROR! can't find ZRTP_PKTYPE_EC384P component\n"));
|
||||
} else {
|
||||
pks->self_test(pks);
|
||||
}
|
||||
|
||||
pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_EC521P, zrtp);
|
||||
if (!pks) {
|
||||
ZRTP_LOG(1, (_ZTU_,"ERROR! can't find ZRTP_PKTYPE_EC521P component\n"));
|
||||
} else {
|
||||
pks->self_test(pks);
|
||||
}
|
||||
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if (defined(ZRTP_USE_EXTERN_SRTP) && (ZRTP_USE_EXTERN_SRTP == 1))
|
||||
#else
|
||||
|
||||
static uint8_t dk_master_key[16] = {
|
||||
0xE1, 0xF9, 0x7A, 0x0D, 0x3E, 0x01, 0x8B, 0xE0,
|
||||
0xD6, 0x4F, 0xA3, 0x2C, 0x06, 0xDE, 0x41, 0x39
|
||||
};
|
||||
|
||||
static uint8_t dk_master_salt[14] = {
|
||||
0x0E, 0xC6, 0x75, 0xAD, 0x49, 0x8A, 0xFE, 0xEB,
|
||||
0xB6, 0x96, 0x0B, 0x3A, 0xAB, 0xE6
|
||||
};
|
||||
|
||||
|
||||
static uint8_t dk_cipher_key[16] = {
|
||||
0xC6, 0x1E, 0x7A, 0x93, 0x74, 0x4F, 0x39, 0xEE,
|
||||
0x10, 0x73, 0x4A, 0xFE, 0x3F, 0xF7, 0xA0, 0x87
|
||||
};
|
||||
|
||||
static uint8_t dk_cipher_salt[14] = {
|
||||
0x30, 0xCB, 0xBC, 0x08, 0x86, 0x3D, 0x8C, 0x85,
|
||||
0xD4, 0x9D, 0xB3, 0x4A, 0x9A, 0xE1
|
||||
};
|
||||
|
||||
static uint8_t dk_auth_key[94] = {
|
||||
0xCE, 0xBE, 0x32, 0x1F, 0x6F, 0xF7, 0x71, 0x6B,
|
||||
0x6F, 0xD4, 0xAB, 0x49, 0xAF, 0x25, 0x6A, 0x15,
|
||||
0x6D, 0x38, 0xBA, 0xA4, 0x8F, 0x0A, 0x0A, 0xCF,
|
||||
0x3C, 0x34, 0xE2, 0x35, 0x9E, 0x6C, 0xDB, 0xCE,
|
||||
0xE0, 0x49, 0x64, 0x6C, 0x43, 0xD9, 0x32, 0x7A,
|
||||
0xD1, 0x75, 0x57, 0x8E, 0xF7, 0x22, 0x70, 0x98,
|
||||
0x63, 0x71, 0xC1, 0x0C, 0x9A, 0x36, 0x9A, 0xC2,
|
||||
0xF9, 0x4A, 0x8C, 0x5F, 0xBC, 0xDD, 0xDC, 0x25,
|
||||
0x6D, 0x6E, 0x91, 0x9A, 0x48, 0xB6, 0x10, 0xEF,
|
||||
0x17, 0xC2, 0x04, 0x1E, 0x47, 0x40, 0x35, 0x76,
|
||||
0x6B, 0x68, 0x64, 0x2C, 0x59, 0xBB, 0xFC, 0x2F,
|
||||
0x34, 0xDB, 0x60, 0xDB, 0xDF, 0xB2
|
||||
};
|
||||
|
||||
extern zrtp_dk_ctx *zrtp_dk_init(zrtp_cipher_t *cipher, zrtp_stringn_t *key, zrtp_stringn_t *salt);
|
||||
extern zrtp_status_t zrtp_derive_key(zrtp_dk_ctx *ctx, zrtp_srtp_prf_label label, zrtp_stringn_t *result_key);
|
||||
extern void zrtp_dk_deinit(zrtp_dk_ctx *ctx);
|
||||
|
||||
zrtp_status_t hex_cmp(uint8_t *a, uint8_t *b, uint32_t len)
|
||||
{
|
||||
uint32_t i;
|
||||
zrtp_status_t res = zrtp_status_ok;
|
||||
for (i = 0; i<len; i++) {
|
||||
if (a[i] != b[i]) {
|
||||
res = zrtp_status_fail;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
zrtp_status_t dk_test(zrtp_global_t *zrtp)
|
||||
{
|
||||
zrtp_status_t res;
|
||||
zrtp_string16_t master_key, master_salt, cipher_key, cipher_salt;
|
||||
zrtp_string128_t auth_key;
|
||||
zrtp_dk_ctx *ctx;
|
||||
|
||||
zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES128, zrtp);
|
||||
|
||||
if(NULL == cipher){
|
||||
return zrtp_status_fail;
|
||||
}
|
||||
|
||||
master_key.length = master_key.max_length = 16;
|
||||
zrtp_memcpy(master_key.buffer, dk_master_key, 16);
|
||||
|
||||
master_salt.length = 14;
|
||||
master_salt.max_length = 16;
|
||||
zrtp_memcpy(master_salt.buffer, dk_master_salt, 14);
|
||||
|
||||
|
||||
ctx = zrtp_dk_init(cipher, (zrtp_stringn_t*)&master_key, (zrtp_stringn_t*)&master_salt);
|
||||
if(NULL == ctx){
|
||||
return zrtp_status_fail;
|
||||
}
|
||||
|
||||
cipher_key.length = 16;
|
||||
cipher_key.max_length = 16;
|
||||
|
||||
zrtp_derive_key(ctx, label_rtp_encryption, (zrtp_stringn_t*)&cipher_key);
|
||||
res = hex_cmp((uint8_t*)cipher_key.buffer, dk_cipher_key, cipher_key.length);
|
||||
ZRTP_LOG(3, (_ZTU_,"cipher key check...%s\n", zrtp_status_ok==res?"OK":"FAIL"));
|
||||
|
||||
|
||||
cipher_salt.length = 14;
|
||||
cipher_salt.max_length = 16;
|
||||
|
||||
zrtp_derive_key(ctx, label_rtp_salt, (zrtp_stringn_t*)&cipher_salt);
|
||||
res = hex_cmp((uint8_t*)cipher_salt.buffer, dk_cipher_salt, cipher_salt.length);
|
||||
ZRTP_LOG(3, (_ZTU_,"cipher salt check...%s\n", zrtp_status_ok==res?"OK":"FAIL"));
|
||||
|
||||
|
||||
auth_key.length = 94;
|
||||
auth_key.max_length = 128;
|
||||
|
||||
zrtp_derive_key(ctx, label_rtp_msg_auth, (zrtp_stringn_t*)&auth_key);
|
||||
res = hex_cmp((uint8_t*)auth_key.buffer, dk_auth_key, auth_key.length);
|
||||
ZRTP_LOG(3, (_ZTU_,"auth key check...%s\n", zrtp_status_ok==res?"OK":"FAIL"));
|
||||
|
||||
zrtp_dk_deinit(ctx);
|
||||
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define TEST_MAP_WIDTH 64
|
||||
#if TEST_MAP_WIDTH%8
|
||||
# define TEST_MAP_WIDTH_BYTES TEST_MAP_WIDTH/8+1
|
||||
#else
|
||||
# define TEST_MAP_WIDTH_BYTES TEST_MAP_WIDTH/8
|
||||
#endif
|
||||
|
||||
#define FIRST_TEST_MAP_INIT_WIDTH 24
|
||||
|
||||
extern zrtp_rp_node_t *get_rp_node_non_lock(zrtp_rp_ctx_t *ctx, uint8_t direction, uint32_t ssrc);
|
||||
extern zrtp_rp_node_t *add_rp_node(zrtp_srtp_ctx_t *srtp_ctx, zrtp_rp_ctx_t *ctx, uint8_t direction, uint32_t ssrc);
|
||||
extern zrtp_status_t zrtp_srtp_rp_check(zrtp_srtp_rp_t *srtp_rp, zrtp_rtp_info_t *packet);
|
||||
extern zrtp_status_t zrtp_srtp_rp_add(zrtp_srtp_rp_t *srtp_rp, zrtp_rtp_info_t *packet);
|
||||
|
||||
void print_map(uint8_t *map, int width_bytes)
|
||||
{
|
||||
int i;
|
||||
for(i=width_bytes-1; i >= 0; i--) {
|
||||
ZRTP_LOGC(3, ("%i%i%i%i%i%i%i%i",
|
||||
zrtp_bitmap_get_bit(map, 8*i+7),
|
||||
zrtp_bitmap_get_bit(map, 8*i+6),
|
||||
zrtp_bitmap_get_bit(map, 8*i+5),
|
||||
zrtp_bitmap_get_bit(map, 8*i+4),
|
||||
zrtp_bitmap_get_bit(map, 8*i+3),
|
||||
zrtp_bitmap_get_bit(map, 8*i+2),
|
||||
zrtp_bitmap_get_bit(map, 8*i+1),
|
||||
zrtp_bitmap_get_bit(map, 8*i+0)));
|
||||
}
|
||||
ZRTP_LOG(3, (_ZTU_, "\n"));
|
||||
}
|
||||
|
||||
void init_random_map(uint8_t *map, int width, zrtp_global_t *zrtp)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<width; i++) {
|
||||
uint32_t rnd = 0;
|
||||
zrtp_randstr(zrtp, (uint8_t*)&rnd, sizeof(rnd));
|
||||
if(rnd%10 < 5) {
|
||||
zrtp_bitmap_set_bit(map, i);
|
||||
} else {
|
||||
zrtp_bitmap_clear_bit(map, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void inject_from_map( zrtp_srtp_global_t *srtp_global,
|
||||
uint32_t ssrc,
|
||||
uint8_t *src_map, uint8_t *dst_map, int width)
|
||||
{
|
||||
zrtp_rp_node_t *rp_node;
|
||||
int i;
|
||||
zrtp_rtp_info_t pkt;
|
||||
|
||||
rp_node = get_rp_node_non_lock(srtp_global->rp_ctx, RP_INCOMING_DIRECTION, ssrc);
|
||||
if (NULL == rp_node) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i=0; i< width; i++) {
|
||||
if (1 == zrtp_bitmap_get_bit(src_map, i)) {
|
||||
pkt.seq = i;
|
||||
if (zrtp_status_ok == zrtp_srtp_rp_check(&rp_node->rtp_rp, &pkt)) {
|
||||
zrtp_bitmap_set_bit(dst_map, i);
|
||||
zrtp_srtp_rp_add(&rp_node->rtp_rp, &pkt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int srtp_replay_protection_test(zrtp_global_t *zrtp)
|
||||
{
|
||||
int res = 0;
|
||||
uint32_t ssrc = 1;
|
||||
int i = 0;
|
||||
uint8_t test_map[TEST_MAP_WIDTH_BYTES];
|
||||
uint8_t result_map[TEST_MAP_WIDTH_BYTES];
|
||||
uint8_t tmp_window[ZRTP_SRTP_WINDOW_WIDTH_BYTES];
|
||||
uint32_t tmp_seq;
|
||||
int delta, shift;
|
||||
|
||||
zrtp_rp_node_t *rp_node;
|
||||
zrtp_srtp_global_t *srtp = zrtp->srtp_global;
|
||||
|
||||
rp_node = add_rp_node(NULL, srtp->rp_ctx, RP_INCOMING_DIRECTION, ssrc);
|
||||
if (NULL == rp_node) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i=0; i< TEST_MAP_WIDTH_BYTES; i++) {
|
||||
test_map[i] = 0;
|
||||
result_map[i] = 0;
|
||||
}
|
||||
/*
|
||||
* 1st test
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
init_random_map(test_map, FIRST_TEST_MAP_INIT_WIDTH, zrtp);
|
||||
inject_from_map(srtp, ssrc, test_map, result_map, TEST_MAP_WIDTH);
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"1st test. Wnd[%i]...\n", ZRTP_SRTP_WINDOW_WIDTH));
|
||||
|
||||
tmp_seq = rp_node->rtp_rp.seq;
|
||||
for (i=0; i<ZRTP_SRTP_WINDOW_WIDTH_BYTES; i++) {
|
||||
tmp_window[i] = rp_node->rtp_rp.window[i];
|
||||
}
|
||||
|
||||
delta = tmp_seq-ZRTP_SRTP_WINDOW_WIDTH + 1;
|
||||
if (delta > 0) {
|
||||
ZRTP_LOG(3, (_ZTU_,"after wnd: (%i;0]\n", delta));
|
||||
ZRTP_LOG(3, (_ZTU_,"inside wnd: [%i;%i]\n", tmp_seq, delta));
|
||||
} else {
|
||||
ZRTP_LOG(3, (_ZTU_,"after wnd: (0;0)\n"));
|
||||
ZRTP_LOG(3, (_ZTU_,"inside wnd: [%i;0]\n", tmp_seq));
|
||||
}
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"before wnd: [%i;%i)\n", TEST_MAP_WIDTH-1, tmp_seq));
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"Test map: "));
|
||||
print_map(test_map, TEST_MAP_WIDTH_BYTES);
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"Res map: "));
|
||||
print_map(result_map, TEST_MAP_WIDTH_BYTES);
|
||||
|
||||
shift = TEST_MAP_WIDTH;
|
||||
shift -= rp_node->rtp_rp.seq + 1;
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"Window : "));
|
||||
for(i=shift; i > 0; i--){
|
||||
ZRTP_LOGC(3, (" "));
|
||||
}
|
||||
print_map(rp_node->rtp_rp.window, ZRTP_SRTP_WINDOW_WIDTH_BYTES);
|
||||
|
||||
/*
|
||||
* 2nd test
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
for(i=0; i< TEST_MAP_WIDTH_BYTES; i++){
|
||||
test_map[i] = 0;
|
||||
result_map[i] = 0;
|
||||
}
|
||||
|
||||
init_random_map(test_map, TEST_MAP_WIDTH, zrtp);
|
||||
inject_from_map(srtp, ssrc, test_map, result_map, TEST_MAP_WIDTH);
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"2nd test. Wnd[%i]...\n", ZRTP_SRTP_WINDOW_WIDTH));
|
||||
ZRTP_LOG(3, (_ZTU_,"Test map: "));
|
||||
print_map(test_map, TEST_MAP_WIDTH_BYTES);
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"Res map: "));
|
||||
print_map(result_map, TEST_MAP_WIDTH_BYTES);
|
||||
|
||||
shift = TEST_MAP_WIDTH;
|
||||
shift -= rp_node->rtp_rp.seq + 1;
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"Window : "));
|
||||
for (i=shift; i > 0; i--) {
|
||||
//zrtp_print_log(ZRTP_LOG_DEBUG, " ");
|
||||
}
|
||||
print_map(rp_node->rtp_rp.window, ZRTP_SRTP_WINDOW_WIDTH_BYTES);
|
||||
|
||||
|
||||
/*
|
||||
in result map:
|
||||
- after window we should to have all zeroes
|
||||
- into the window we should have ones only if window have zero at appropriate position
|
||||
- before window we should have equal values of test map and result map bits
|
||||
*/
|
||||
for (i=0; i < TEST_MAP_WIDTH; i++) {
|
||||
if (delta > 0 && i < delta) {
|
||||
/* After window */
|
||||
if (0 != zrtp_bitmap_get_bit(result_map, i)) {
|
||||
ZRTP_LOG(3, (_ZTU_,"After window. %i bit should be 0\n", i));
|
||||
res = -1;
|
||||
}
|
||||
} else if (i <= (int)tmp_seq && i >= delta) {
|
||||
/* inside window */
|
||||
|
||||
/* check window filtering */
|
||||
if(1 == zrtp_bitmap_get_bit(result_map, i)) {
|
||||
if (1 == zrtp_bitmap_get_bit(tmp_window, i - (tmp_seq-ZRTP_SRTP_WINDOW_WIDTH) - 1)) {
|
||||
ZRTP_LOG(3, (_ZTU_,"Inside window. Window filtering fail. %i bit should be 0\n", i));
|
||||
res = -1;
|
||||
}
|
||||
}
|
||||
/* check test vs result maps */
|
||||
if ( zrtp_bitmap_get_bit(result_map, i) != zrtp_bitmap_get_bit(test_map, i) &&
|
||||
!zrtp_bitmap_get_bit(tmp_window, i - (tmp_seq-ZRTP_SRTP_WINDOW_WIDTH) - 1)) {
|
||||
ZRTP_LOG(3, (_ZTU_, "Inside window. Test map isn't equal to result at bit %i\n", i));
|
||||
res = -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
/* after window */
|
||||
if (zrtp_bitmap_get_bit(result_map, i) != zrtp_bitmap_get_bit(test_map, i)) {
|
||||
ZRTP_LOG(3, (_ZTU_,"Before window. Test map isn't equal to result at bit %i\n", i));
|
||||
res = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (0 == res) {
|
||||
ZRTP_LOG(3, (_ZTU_,"Test passed successfully\n"));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void zrtp_test_crypto(zrtp_global_t* zrtp)
|
||||
{
|
||||
ZRTP_LOG(3, (_ZTU_,"====================CIPHERS TESTS====================\n"));
|
||||
cipher_test(zrtp);
|
||||
ZRTP_LOG(3, (_ZTU_,"=====================HASHES TESTS====================\n"));
|
||||
hash_test(zrtp);
|
||||
ZRTP_LOG(3, (_ZTU_,"================PUBLIC KEY SCHEMES TESTS==============\n"));
|
||||
dh_test(zrtp);
|
||||
ecdh_test(zrtp);
|
||||
ZRTP_LOG(3, (_ZTU_,"===============SRTP Key derivation TESTS==============\n"));
|
||||
dk_test(zrtp);
|
||||
ZRTP_LOG(3, (_ZTU_,"==============SRTP Replay protection TESTS============\n")) ;
|
||||
srtp_replay_protection_test(zrtp);
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include "zrtp_test_core.h"
|
||||
|
||||
#ifndef ZRTP_TEST_ENABLE_CRYPTO_SELFTESTS
|
||||
#define ZRTP_TEST_ENABLE_CRYPTO_SELFTESTS 0
|
||||
#endif
|
||||
|
||||
static zrtp_test_channel_id_t tmp_id;
|
||||
|
||||
void do_create()
|
||||
{
|
||||
zrtp_test_channel_config_t config;
|
||||
int status = 0;
|
||||
|
||||
config.is_autosecure = 1;
|
||||
config.is_preshared = 0;
|
||||
config.streams_count = 1;
|
||||
|
||||
status = zrtp_test_channel_create(&config, &tmp_id);
|
||||
}
|
||||
|
||||
void do_delete()
|
||||
{
|
||||
zrtp_test_channel_delete(tmp_id);
|
||||
}
|
||||
|
||||
void do_quit()
|
||||
{
|
||||
zrtp_test_zrtp_down();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int status;
|
||||
|
||||
status = zrtp_test_zrtp_init();
|
||||
if (0 != status) {
|
||||
return status;
|
||||
}
|
||||
#if (ZRTP_TEST_ENABLE_CRYPTO_SELFTESTS == 1)
|
||||
zrtp_test_crypto(zrtp_global);
|
||||
#endif
|
||||
|
||||
{
|
||||
zrtp_test_channel_id_t id;
|
||||
zrtp_test_channel_config_t sconfig;
|
||||
|
||||
sconfig.is_autosecure = 0;
|
||||
sconfig.is_preshared = 0;
|
||||
sconfig.streams_count = 1;
|
||||
|
||||
status = zrtp_test_channel_create(&sconfig, &id);
|
||||
|
||||
if (0 == status) {
|
||||
zrtp_test_channel_start(id);
|
||||
}
|
||||
}
|
||||
|
||||
while (1) {
|
||||
zrtp_sleep(1000);
|
||||
}
|
||||
|
||||
|
||||
do_quit();
|
||||
|
||||
return 0;
|
||||
}
|
@ -8,10 +8,9 @@
|
||||
*/
|
||||
|
||||
#include "zrtp.h"
|
||||
#include "zrtp_test_queue.h"
|
||||
#include "queue.h"
|
||||
|
||||
struct zrtp_queue
|
||||
{
|
||||
struct zrtp_queue {
|
||||
zrtp_sem_t* size_sem;
|
||||
zrtp_sem_t* main_sem;
|
||||
zrtp_mutex_t* mutex;
|
||||
@ -19,9 +18,9 @@ struct zrtp_queue
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
zrtp_status_t zrtp_test_queue_create(zrtp_queue_t** queue)
|
||||
{
|
||||
|
||||
zrtp_status_t zrtp_test_queue_create(zrtp_queue_t** queue) {
|
||||
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
zrtp_queue_t* new_queue = (zrtp_queue_t*) zrtp_sys_alloc(sizeof(zrtp_queue_t));
|
||||
if (! new_queue) {
|
||||
@ -67,8 +66,7 @@ zrtp_status_t zrtp_test_queue_create(zrtp_queue_t** queue)
|
||||
return s;
|
||||
}
|
||||
|
||||
void zrtp_test_queue_destroy(zrtp_queue_t* queue)
|
||||
{
|
||||
void zrtp_test_queue_destroy(zrtp_queue_t* queue) {
|
||||
if (queue->size_sem) {
|
||||
zrtp_sem_destroy(queue->size_sem);
|
||||
}
|
||||
@ -80,9 +78,8 @@ void zrtp_test_queue_destroy(zrtp_queue_t* queue)
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void zrtp_test_queue_push(zrtp_queue_t* queue, zrtp_queue_elem_t* elem)
|
||||
{
|
||||
|
||||
void zrtp_test_queue_push(zrtp_queue_t* queue, zrtp_queue_elem_t* elem) {
|
||||
zrtp_sem_wait(queue->size_sem);
|
||||
|
||||
zrtp_mutex_lock(queue->mutex);
|
||||
@ -93,8 +90,7 @@ void zrtp_test_queue_push(zrtp_queue_t* queue, zrtp_queue_elem_t* elem)
|
||||
zrtp_sem_post(queue->main_sem);
|
||||
}
|
||||
|
||||
zrtp_queue_elem_t* zrtp_test_queue_pop(zrtp_queue_t* queue)
|
||||
{
|
||||
zrtp_queue_elem_t* zrtp_test_queue_pop(zrtp_queue_t* queue) {
|
||||
zrtp_queue_elem_t* res = NULL;
|
||||
zrtp_sem_wait(queue->main_sem);
|
||||
|
@ -14,8 +14,7 @@
|
||||
|
||||
#define ZRTP_QUEUE_SIZE 2000
|
||||
|
||||
typedef struct zrtp_queue_elem
|
||||
{
|
||||
typedef struct zrtp_queue_elem {
|
||||
char data[1500];
|
||||
uint32_t size;
|
||||
mlist_t _mlist;
|
123
libs/libzrtp/test/sasrelay_test.c
Normal file
123
libs/libzrtp/test/sasrelay_test.c
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include <setjmp.h> /*chmockery dependency*/
|
||||
#include <stdio.h> /*chmockery dependency*/
|
||||
#include <unistd.h> /*for usleep*/
|
||||
|
||||
#include "cmockery/cmockery.h"
|
||||
#include "test_engine.h"
|
||||
|
||||
#include "enroll_test_helpers.c"
|
||||
|
||||
static void enrollment_test() {
|
||||
zrtp_status_t s;
|
||||
|
||||
zrtp_test_channel_info_t a2pbx_channel_info, b2pbx_channel_info;
|
||||
zrtp_test_session_cfg_t session_config, session_config_enroll;
|
||||
zrtp_test_session_config_defaults(&session_config);
|
||||
zrtp_test_session_config_defaults(&session_config_enroll);
|
||||
|
||||
session_config_enroll.is_enrollment = 1;
|
||||
|
||||
/**************************************************************************
|
||||
* Enroll both Alice and Bob to PBX
|
||||
*/
|
||||
prepare_alice_pbx_bob_setup(&session_config, &session_config, &session_config_enroll, &session_config_enroll);
|
||||
|
||||
/* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
|
||||
s = zrtp_test_channel_start(g_alice2pbx_channel);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
s = zrtp_test_channel_start(g_bob2pbx_channel);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
int i = 30;
|
||||
for (; i>0; i--) {
|
||||
usleep(100*1000);
|
||||
}
|
||||
|
||||
s = zrtp_test_channel_get(g_alice2pbx_channel, &a2pbx_channel_info);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
s = zrtp_test_channel_get(g_bob2pbx_channel, &b2pbx_channel_info);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
/* Both, Alice and Bob should switch secure and ready for enrollment */
|
||||
assert_true(a2pbx_channel_info.is_secure);
|
||||
assert_true(b2pbx_channel_info.is_secure);
|
||||
|
||||
/* Confirm enrollment for both, Alice and Bob */
|
||||
zrtp_test_id_t alice2pbx_stream = zrtp_test_session_get_stream_by_idx(g_alice_sid, 0);
|
||||
zrtp_test_id_t bob2pbx_stream = zrtp_test_session_get_stream_by_idx(g_bob_sid, 0);
|
||||
|
||||
s = zrtp_register_with_trusted_mitm(zrtp_stream_for_test_stream(alice2pbx_stream));
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
s = zrtp_register_with_trusted_mitm(zrtp_stream_for_test_stream(bob2pbx_stream));
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
/* Clean-up */
|
||||
cleanup_alice_pbx_bob_setup();
|
||||
|
||||
/**************************************************************************
|
||||
* Now, when we have two enrolled parties, make one more call and initiate
|
||||
* SAS Relay at the PBX side. Both endpoints should received SASRelay, but
|
||||
* just one should get ZRTP_EVENT_LOCAL_SAS_UPDATED event.
|
||||
*/
|
||||
|
||||
prepare_alice_pbx_bob_setup(&session_config, &session_config, &session_config, &session_config);
|
||||
|
||||
/* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
|
||||
s = zrtp_test_channel_start(g_alice2pbx_channel);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
s = zrtp_test_channel_start(g_bob2pbx_channel);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
i = 30;
|
||||
for (; i>0; i--) {
|
||||
usleep(100*1000);
|
||||
}
|
||||
|
||||
s = zrtp_test_channel_get(g_alice2pbx_channel, &a2pbx_channel_info);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
s = zrtp_test_channel_get(g_bob2pbx_channel, &b2pbx_channel_info);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
/* Both, Alice and Bob should switch secure */
|
||||
assert_true(a2pbx_channel_info.is_secure);
|
||||
assert_true(b2pbx_channel_info.is_secure);
|
||||
|
||||
zrtp_test_id_t pbx2alice_stream = zrtp_test_session_get_stream_by_idx(g_pbxa_sid, 0);
|
||||
zrtp_test_id_t pbx2bob_stream = zrtp_test_session_get_stream_by_idx(g_pbxb_sid, 0);
|
||||
alice2pbx_stream = zrtp_test_session_get_stream_by_idx(g_alice_sid, 0);
|
||||
bob2pbx_stream = zrtp_test_session_get_stream_by_idx(g_bob_sid, 0);
|
||||
|
||||
/* Resolve MiTM call! */
|
||||
s = zrtp_resolve_mitm_call(zrtp_stream_for_test_stream(pbx2alice_stream),
|
||||
zrtp_stream_for_test_stream(pbx2bob_stream));
|
||||
|
||||
i = 20;
|
||||
for (; i>0; i--) {
|
||||
usleep(100*1000);
|
||||
}
|
||||
|
||||
/* Alice and Bob should receive Enrollment notification */
|
||||
unsigned sas_update1 = zrtp_stream_did_event_receive(alice2pbx_stream, ZRTP_EVENT_LOCAL_SAS_UPDATED);
|
||||
unsigned sas_update2 = zrtp_stream_did_event_receive(bob2pbx_stream, ZRTP_EVENT_LOCAL_SAS_UPDATED);
|
||||
assert_true(sas_update1 ^ sas_update2);
|
||||
|
||||
/* Clean-up */
|
||||
cleanup_alice_pbx_bob_setup();
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(enrollment_test, pbx_setup, pbx_teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
}
|
240
libs/libzrtp/test/srtp_replay_test.c
Normal file
240
libs/libzrtp/test/srtp_replay_test.c
Normal file
@ -0,0 +1,240 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "zrtp.h"
|
||||
#include "cmockery/cmockery.h"
|
||||
|
||||
#define _ZTU_ "srtp replay test"
|
||||
|
||||
zrtp_global_t *zrtp;
|
||||
|
||||
#define TEST_MAP_WIDTH 64
|
||||
#if TEST_MAP_WIDTH%8
|
||||
# define TEST_MAP_WIDTH_BYTES TEST_MAP_WIDTH/8+1
|
||||
#else
|
||||
# define TEST_MAP_WIDTH_BYTES TEST_MAP_WIDTH/8
|
||||
#endif
|
||||
|
||||
#define FIRST_TEST_MAP_INIT_WIDTH 24
|
||||
|
||||
extern zrtp_rp_node_t *get_rp_node_non_lock(zrtp_rp_ctx_t *ctx, uint8_t direction, uint32_t ssrc);
|
||||
extern zrtp_rp_node_t *add_rp_node(zrtp_srtp_ctx_t *srtp_ctx, zrtp_rp_ctx_t *ctx, uint8_t direction, uint32_t ssrc);
|
||||
extern zrtp_status_t zrtp_srtp_rp_check(zrtp_srtp_rp_t *srtp_rp, zrtp_rtp_info_t *packet);
|
||||
extern zrtp_status_t zrtp_srtp_rp_add(zrtp_srtp_rp_t *srtp_rp, zrtp_rtp_info_t *packet);
|
||||
|
||||
|
||||
void setup() {
|
||||
zrtp_status_t s;
|
||||
zrtp_config_t zrtp_config;
|
||||
|
||||
zrtp_config_defaults(&zrtp_config);
|
||||
|
||||
s = zrtp_init(&zrtp_config, &zrtp);
|
||||
assert_int_equal(s, zrtp_status_ok);
|
||||
}
|
||||
|
||||
void teardown() {
|
||||
zrtp_down(zrtp);
|
||||
}
|
||||
|
||||
static void print_map(uint8_t *map, int width_bytes)
|
||||
{
|
||||
int i;
|
||||
for(i=width_bytes-1; i >= 0; i--) {
|
||||
ZRTP_LOGC(3, ("%i%i%i%i%i%i%i%i",
|
||||
zrtp_bitmap_get_bit(map, 8*i+7),
|
||||
zrtp_bitmap_get_bit(map, 8*i+6),
|
||||
zrtp_bitmap_get_bit(map, 8*i+5),
|
||||
zrtp_bitmap_get_bit(map, 8*i+4),
|
||||
zrtp_bitmap_get_bit(map, 8*i+3),
|
||||
zrtp_bitmap_get_bit(map, 8*i+2),
|
||||
zrtp_bitmap_get_bit(map, 8*i+1),
|
||||
zrtp_bitmap_get_bit(map, 8*i+0)));
|
||||
}
|
||||
ZRTP_LOG(3, (_ZTU_, "\n"));
|
||||
}
|
||||
|
||||
static void init_random_map(uint8_t *map, int width, zrtp_global_t *zrtp) {
|
||||
int i;
|
||||
for(i=0; i<width; i++) {
|
||||
uint32_t rnd = 0;
|
||||
zrtp_randstr(zrtp, (uint8_t*)&rnd, sizeof(rnd));
|
||||
if(rnd%10 < 5) {
|
||||
zrtp_bitmap_set_bit(map, i);
|
||||
} else {
|
||||
zrtp_bitmap_clear_bit(map, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void inject_from_map( zrtp_srtp_global_t *srtp_global,
|
||||
uint32_t ssrc,
|
||||
uint8_t *src_map, uint8_t *dst_map, int width) {
|
||||
zrtp_rp_node_t *rp_node;
|
||||
int i;
|
||||
zrtp_rtp_info_t pkt;
|
||||
|
||||
rp_node = get_rp_node_non_lock(srtp_global->rp_ctx, RP_INCOMING_DIRECTION, ssrc);
|
||||
if (NULL == rp_node) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i=0; i< width; i++) {
|
||||
if (1 == zrtp_bitmap_get_bit(src_map, i)) {
|
||||
pkt.seq = i;
|
||||
if (zrtp_status_ok == zrtp_srtp_rp_check(&rp_node->rtp_rp, &pkt)) {
|
||||
zrtp_bitmap_set_bit(dst_map, i);
|
||||
zrtp_srtp_rp_add(&rp_node->rtp_rp, &pkt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: split test into several, more atomic tests
|
||||
static void srtp_replay_test() {
|
||||
int res = 0;
|
||||
uint32_t ssrc = 1;
|
||||
int i = 0;
|
||||
uint8_t test_map[TEST_MAP_WIDTH_BYTES];
|
||||
uint8_t result_map[TEST_MAP_WIDTH_BYTES];
|
||||
uint8_t tmp_window[ZRTP_SRTP_WINDOW_WIDTH_BYTES];
|
||||
uint32_t tmp_seq;
|
||||
int delta, shift;
|
||||
|
||||
zrtp_rp_node_t *rp_node;
|
||||
zrtp_srtp_global_t *srtp = zrtp->srtp_global;
|
||||
|
||||
rp_node = add_rp_node(NULL, srtp->rp_ctx, RP_INCOMING_DIRECTION, ssrc);
|
||||
assert_non_null(rp_node);
|
||||
|
||||
for (i=0; i< TEST_MAP_WIDTH_BYTES; i++) {
|
||||
test_map[i] = 0;
|
||||
result_map[i] = 0;
|
||||
}
|
||||
/*
|
||||
* 1st test
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
init_random_map(test_map, FIRST_TEST_MAP_INIT_WIDTH, zrtp);
|
||||
inject_from_map(srtp, ssrc, test_map, result_map, TEST_MAP_WIDTH);
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"1st test. Wnd[%i]...\n", ZRTP_SRTP_WINDOW_WIDTH));
|
||||
|
||||
tmp_seq = rp_node->rtp_rp.seq;
|
||||
for (i=0; i<ZRTP_SRTP_WINDOW_WIDTH_BYTES; i++) {
|
||||
tmp_window[i] = rp_node->rtp_rp.window[i];
|
||||
}
|
||||
|
||||
delta = tmp_seq-ZRTP_SRTP_WINDOW_WIDTH + 1;
|
||||
if (delta > 0) {
|
||||
ZRTP_LOG(3, (_ZTU_,"after wnd: (%i;0]\n", delta));
|
||||
ZRTP_LOG(3, (_ZTU_,"inside wnd: [%i;%i]\n", tmp_seq, delta));
|
||||
} else {
|
||||
ZRTP_LOG(3, (_ZTU_,"after wnd: (0;0)\n"));
|
||||
ZRTP_LOG(3, (_ZTU_,"inside wnd: [%i;0]\n", tmp_seq));
|
||||
}
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"before wnd: [%i;%i)\n", TEST_MAP_WIDTH-1, tmp_seq));
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"Test map: "));
|
||||
print_map(test_map, TEST_MAP_WIDTH_BYTES);
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"Res map: "));
|
||||
print_map(result_map, TEST_MAP_WIDTH_BYTES);
|
||||
|
||||
shift = TEST_MAP_WIDTH;
|
||||
shift -= rp_node->rtp_rp.seq + 1;
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"Window : "));
|
||||
for(i=shift; i > 0; i--){
|
||||
ZRTP_LOGC(3, (" "));
|
||||
}
|
||||
print_map(rp_node->rtp_rp.window, ZRTP_SRTP_WINDOW_WIDTH_BYTES);
|
||||
|
||||
/*
|
||||
* 2nd test
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
for(i=0; i< TEST_MAP_WIDTH_BYTES; i++){
|
||||
test_map[i] = 0;
|
||||
result_map[i] = 0;
|
||||
}
|
||||
|
||||
init_random_map(test_map, TEST_MAP_WIDTH, zrtp);
|
||||
inject_from_map(srtp, ssrc, test_map, result_map, TEST_MAP_WIDTH);
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"2nd test. Wnd[%i]...\n", ZRTP_SRTP_WINDOW_WIDTH));
|
||||
ZRTP_LOG(3, (_ZTU_,"Test map: "));
|
||||
print_map(test_map, TEST_MAP_WIDTH_BYTES);
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"Res map: "));
|
||||
print_map(result_map, TEST_MAP_WIDTH_BYTES);
|
||||
|
||||
shift = TEST_MAP_WIDTH;
|
||||
shift -= rp_node->rtp_rp.seq + 1;
|
||||
|
||||
ZRTP_LOG(3, (_ZTU_,"Window : "));
|
||||
for (i=shift; i > 0; i--) {
|
||||
//zrtp_print_log(ZRTP_LOG_DEBUG, " ");
|
||||
}
|
||||
print_map(rp_node->rtp_rp.window, ZRTP_SRTP_WINDOW_WIDTH_BYTES);
|
||||
|
||||
|
||||
/*
|
||||
in result map:
|
||||
- after window we should to have all zeroes
|
||||
- into the window we should have ones only if window have zero at appropriate position
|
||||
- before window we should have equal values of test map and result map bits
|
||||
*/
|
||||
for (i=0; i < TEST_MAP_WIDTH; i++) {
|
||||
if (delta > 0 && i < delta) {
|
||||
/* After window */
|
||||
if (0 != zrtp_bitmap_get_bit(result_map, i)) {
|
||||
ZRTP_LOG(3, (_ZTU_,"After window. %i bit should be 0\n", i));
|
||||
res = -1;
|
||||
}
|
||||
} else if (i <= (int)tmp_seq && i >= delta) {
|
||||
/* inside window */
|
||||
|
||||
/* check window filtering */
|
||||
if(1 == zrtp_bitmap_get_bit(result_map, i)) {
|
||||
if (1 == zrtp_bitmap_get_bit(tmp_window, i - (tmp_seq-ZRTP_SRTP_WINDOW_WIDTH) - 1)) {
|
||||
ZRTP_LOG(3, (_ZTU_,"Inside window. Window filtering fail. %i bit should be 0\n", i));
|
||||
res = -1;
|
||||
}
|
||||
}
|
||||
/* check test vs result maps */
|
||||
if ( zrtp_bitmap_get_bit(result_map, i) != zrtp_bitmap_get_bit(test_map, i) &&
|
||||
!zrtp_bitmap_get_bit(tmp_window, i - (tmp_seq-ZRTP_SRTP_WINDOW_WIDTH) - 1)) {
|
||||
ZRTP_LOG(3, (_ZTU_, "Inside window. Test map isn't equal to result at bit %i\n", i));
|
||||
res = -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
/* after window */
|
||||
if (zrtp_bitmap_get_bit(result_map, i) != zrtp_bitmap_get_bit(test_map, i)) {
|
||||
ZRTP_LOG(3, (_ZTU_,"Before window. Test map isn't equal to result at bit %i\n", i));
|
||||
res = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert_int_equal(res, 0);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(srtp_replay_test, setup, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
}
|
854
libs/libzrtp/test/test_engine.c
Normal file
854
libs/libzrtp/test/test_engine.c
Normal file
@ -0,0 +1,854 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include <stdio.h> /* for sprintf(), remove() */
|
||||
#include <string.h> /* for string operations */
|
||||
|
||||
#include "test_engine.h"
|
||||
#include "queue.h"
|
||||
|
||||
#define _ZTU_ "test engine"
|
||||
|
||||
#define K_ZRTP_TEST_MAX_ENDPOINTS 10
|
||||
#define K_ZRTP_TEST_MAX_SESSIONS_PER_ENDPOINT 100
|
||||
#define K_ZRTP_TEST_MAX_CHANNELS (K_ZRTP_TEST_MAX_ENDPOINTS * K_ZRTP_TEST_MAX_ENDPOINTS * ZRTP_MAX_STREAMS_PER_SESSION)
|
||||
|
||||
#define K_ZRTP_TEST_PROCESSORS_COUNT 2
|
||||
#define K_ZRTP_TEST_RTP_RATE 200
|
||||
|
||||
extern uint8_t hash_word_list_odd[256][12];
|
||||
extern uint8_t hash_word_list_even[256][10];
|
||||
|
||||
typedef struct {
|
||||
zrtp_test_id_t id;
|
||||
zrtp_test_id_t session_id;
|
||||
zrtp_test_id_t channel_id;
|
||||
zrtp_test_id_t endpoint_id;
|
||||
zrtp_stream_t *zrtp;
|
||||
uint16_t seq;
|
||||
zrtp_queue_t *input;
|
||||
zrtp_queue_t *output;
|
||||
unsigned zrtp_events_queueu[128];
|
||||
unsigned zrtp_events_count;
|
||||
} zrtp_test_stream_t;
|
||||
|
||||
typedef struct {
|
||||
zrtp_test_id_t id;
|
||||
zrtp_test_id_t endpoint_id;
|
||||
zrtp_test_session_cfg_t cfg;
|
||||
zrtp_session_t *zrtp;
|
||||
zrtp_test_stream_t streams[ZRTP_MAX_STREAMS_PER_SESSION];
|
||||
unsigned streams_count;
|
||||
} zrtp_test_session_t;
|
||||
|
||||
typedef struct {
|
||||
zrtp_test_id_t id;
|
||||
char name[ZRTP_TEST_STR_LEN];
|
||||
zrtp_zid_t zid;
|
||||
zrtp_test_endpoint_cfg_t cfg;
|
||||
zrtp_test_session_t sessions[K_ZRTP_TEST_MAX_SESSIONS_PER_ENDPOINT];
|
||||
unsigned sessions_count;
|
||||
zrtp_global_t *zrtp;
|
||||
unsigned is_running;
|
||||
zrtp_queue_t *input_queue;
|
||||
} zrtp_endpoint_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
zrtp_test_id_t id;
|
||||
zrtp_test_stream_t *left;
|
||||
zrtp_test_stream_t *right;
|
||||
unsigned is_attached;
|
||||
unsigned is_secure;
|
||||
} zrtp_test_channel_t;
|
||||
|
||||
typedef struct zrtp_test_packet {
|
||||
uint32_t is_rtp; /*! Defines is packet RTP or RTCP */
|
||||
uint32_t length; /*! Packet Length in bytes */
|
||||
char body[1024]; /*! Packet body */
|
||||
} zrtp_test_packet_t;
|
||||
|
||||
|
||||
static zrtp_endpoint_t g_test_endpoints[K_ZRTP_TEST_MAX_ENDPOINTS];
|
||||
static unsigned g_test_endpoints_count = 0;
|
||||
|
||||
static zrtp_test_channel_t g_test_channels[K_ZRTP_TEST_MAX_CHANNELS];
|
||||
static unsigned g_test_channels_count = 0;
|
||||
|
||||
static int g_endpoints_counter = 7;
|
||||
static int g_channels_counter = 7;
|
||||
static int g_sessions_counter = 7;
|
||||
static int g_streams_counter = 7;
|
||||
|
||||
|
||||
zrtp_endpoint_t *zrtp_test_endpoint_by_id(zrtp_test_id_t id);
|
||||
zrtp_test_stream_t *zrtp_test_stream_by_id(zrtp_test_id_t id);
|
||||
zrtp_test_stream_t *zrtp_test_stream_by_peerid(zrtp_test_id_t id);
|
||||
zrtp_test_session_t *zrtp_test_session_by_id(zrtp_test_id_t id);
|
||||
zrtp_test_channel_t *zrtp_test_channel_by_id(zrtp_test_id_t id);
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* libzrtp interface implementation
|
||||
*/
|
||||
|
||||
static void on_zrtp_event(zrtp_stream_t *ctx, zrtp_protocol_event_t event) {
|
||||
zrtp_test_id_t *stream_id = zrtp_stream_get_userdata(ctx);
|
||||
zrtp_test_stream_t *stream = zrtp_test_stream_by_id(*stream_id);
|
||||
|
||||
stream->zrtp_events_queueu[stream->zrtp_events_count++] = event;
|
||||
}
|
||||
|
||||
|
||||
static void on_zrtp_secure(zrtp_stream_t *ctx) {
|
||||
zrtp_test_id_t *stream_id = zrtp_stream_get_userdata(ctx);
|
||||
zrtp_test_stream_t *stream = zrtp_test_stream_by_id(*stream_id);
|
||||
zrtp_test_channel_t *channel = zrtp_test_channel_by_id(stream->channel_id);
|
||||
zrtp_test_stream_t *remote_stream = (channel->left == stream) ? channel->right : channel->left;
|
||||
|
||||
if (stream->zrtp->state == ZRTP_STATE_SECURE &&
|
||||
remote_stream->zrtp->state == ZRTP_STATE_SECURE) {
|
||||
channel->is_secure = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int on_send_packet(const zrtp_stream_t* ctx, char* message, unsigned int length) {
|
||||
zrtp_queue_elem_t* elem = zrtp_sys_alloc(sizeof(zrtp_queue_elem_t));
|
||||
if (elem) {
|
||||
zrtp_test_packet_t* packet = (zrtp_test_packet_t*) elem->data;
|
||||
elem->size = length;
|
||||
|
||||
packet->is_rtp = 1;
|
||||
packet->length = length;
|
||||
zrtp_memcpy(packet->body, message, length);
|
||||
|
||||
zrtp_test_id_t *stream_id = zrtp_stream_get_userdata(ctx);
|
||||
zrtp_test_stream_t *stream = zrtp_test_stream_by_id(*stream_id);
|
||||
if (stream) {
|
||||
zrtp_test_queue_push(stream->output, elem);
|
||||
return zrtp_status_ok;
|
||||
} else {
|
||||
return zrtp_status_fail;
|
||||
}
|
||||
} else {
|
||||
return zrtp_status_alloc_fail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Processing Loop
|
||||
*/
|
||||
|
||||
static zrtp_test_stream_t *get_stream_to_process_(zrtp_endpoint_t *endpoint) {
|
||||
zrtp_test_id_t all_streams[K_ZRTP_TEST_MAX_SESSIONS_PER_ENDPOINT*ZRTP_MAX_STREAMS_PER_SESSION];
|
||||
unsigned streams_count = 0;
|
||||
unsigned i, j;
|
||||
|
||||
for (i=0; i<endpoint->sessions_count; i++) {
|
||||
for (j=0; j<endpoint->sessions[i].streams_count; j++) {
|
||||
zrtp_test_stream_t *stream = &endpoint->sessions[i].streams[j];
|
||||
if (stream->input && stream->output)
|
||||
all_streams[streams_count++] = stream->id;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == streams_count)
|
||||
return NULL;
|
||||
|
||||
zrtp_randstr(endpoint->zrtp, (unsigned char*)&i, sizeof(i));
|
||||
j = (unsigned)i;
|
||||
j = j % streams_count;
|
||||
|
||||
//printf("trace>>> CHOOSE stream Endpoint=%u IDX=%u ID=%u\n", endpoint->id, j, all_streams[j]);
|
||||
return zrtp_test_stream_by_id(all_streams[j]);
|
||||
}
|
||||
|
||||
|
||||
#if (ZRTP_PLATFORM == ZP_WIN32) || (ZRTP_PLATFORM == ZP_WINCE)
|
||||
DWORD WINAPI process_incoming(void *param)
|
||||
#else
|
||||
void *process_incoming(void *param)
|
||||
#endif
|
||||
{
|
||||
zrtp_endpoint_t *the_endpoint = (zrtp_endpoint_t *)param;
|
||||
|
||||
while (the_endpoint->is_running) {
|
||||
zrtp_test_packet_t* packet = NULL;
|
||||
zrtp_queue_elem_t* elem = NULL;
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
zrtp_test_stream_t *stream;
|
||||
int is_protocol = 0;
|
||||
|
||||
// TODO: use peak to not to block processing if queue for this stream is empty
|
||||
elem = zrtp_test_queue_pop(the_endpoint->input_queue);
|
||||
if (!elem || elem->size <= 0) {
|
||||
if (elem) zrtp_sys_free(elem);
|
||||
break;
|
||||
}
|
||||
|
||||
packet = (zrtp_test_packet_t*) elem->data;
|
||||
zrtp_test_id_t stream_id;
|
||||
{
|
||||
if (packet->is_rtp) {
|
||||
ZRTP_UNALIGNED(zrtp_rtp_hdr_t) *rtp_hdr = (zrtp_rtp_hdr_t*)packet->body;
|
||||
stream_id = zrtp_ntoh32(rtp_hdr->ssrc); /* remember, we use stream Id as it's RTP SSRC */
|
||||
} else {
|
||||
ZRTP_UNALIGNED(zrtp_rtcp_hdr_t) *rtcp_hdr = (zrtp_rtcp_hdr_t*)packet->body;
|
||||
stream_id = zrtp_ntoh32(rtcp_hdr->ssrc); /* remember, we use stream Id as it's RTP SSRC */
|
||||
}
|
||||
stream = zrtp_test_stream_by_peerid(stream_id);
|
||||
}
|
||||
|
||||
/*
|
||||
* Process incoming packet by libzrtp. Is this a RTP media packet - copy it to the buffer
|
||||
* to print out later.
|
||||
*/
|
||||
if (packet->is_rtp) {
|
||||
s = zrtp_process_srtp(stream->zrtp, packet->body, &packet->length);
|
||||
} else {
|
||||
s = zrtp_process_srtcp(stream->zrtp, packet->body, &packet->length);
|
||||
}
|
||||
|
||||
if (!is_protocol) {
|
||||
char *body;
|
||||
if (packet->is_rtp) {
|
||||
body = packet->body + sizeof(zrtp_rtp_hdr_t);
|
||||
body[packet->length - sizeof(zrtp_rtp_hdr_t)] = 0;
|
||||
} else {
|
||||
body = packet->body + sizeof(zrtp_rtcp_hdr_t);
|
||||
body[packet->length - sizeof(zrtp_rtcp_hdr_t)] = 0;
|
||||
}
|
||||
|
||||
switch (s)
|
||||
{
|
||||
case zrtp_status_ok: {
|
||||
ZRTP_LOG(1, (_ZTU_,"Incoming: (%s) [%p:ssrc=%u] OK. <%s> decrypted %d bytes.\n",
|
||||
zrtp_log_state2str(stream->zrtp->state), stream->zrtp, stream->id, body, packet->length));
|
||||
} break;
|
||||
|
||||
case zrtp_status_drop: {
|
||||
ZRTP_LOG(1, (_ZTU_,"Incoming: (%s) [%p:ssrc=%u] DROPPED. <%s>\n",
|
||||
zrtp_log_state2str(stream->zrtp->state), stream->zrtp, stream->id, body));
|
||||
} break;
|
||||
|
||||
case zrtp_status_fail: {
|
||||
ZRTP_LOG(1, (_ZTU_,"Incoming: (%s) [%p:ssrc=%u] DECRYPT FAILED. <%s>\n",
|
||||
zrtp_log_state2str(stream->zrtp->state), stream->zrtp, stream->id, body));
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
zrtp_sys_free(elem);
|
||||
|
||||
/*
|
||||
* When zrtp_stream is in the pending clear state and other side wants to send plain
|
||||
* traffic. We have to call zrtp_clear_stream().
|
||||
*/
|
||||
if (stream->zrtp->state == ZRTP_STATE_PENDINGCLEAR) {
|
||||
zrtp_stream_clear(stream->zrtp);
|
||||
}
|
||||
}
|
||||
#if (ZRTP_PLATFORM == ZP_WIN32) || (ZRTP_PLATFORM == ZP_WINCE)
|
||||
return 0;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (ZRTP_PLATFORM == ZP_WIN32) || (ZRTP_PLATFORM == ZP_WINCE)
|
||||
DWORD WINAPI process_outgoing(void *param)
|
||||
#else
|
||||
void *process_outgoing(void *param)
|
||||
#endif
|
||||
{
|
||||
unsigned packets_counter = 0;
|
||||
zrtp_endpoint_t *the_endpoint = (zrtp_endpoint_t *)param;
|
||||
|
||||
while (the_endpoint->is_running) {
|
||||
zrtp_test_stream_t* stream = NULL;
|
||||
unsigned i;
|
||||
|
||||
zrtp_status_t s = zrtp_status_fail;
|
||||
zrtp_test_packet_t* packet;
|
||||
zrtp_queue_elem_t* elem;
|
||||
char* word = NULL;
|
||||
|
||||
zrtp_sleep(K_ZRTP_TEST_RTP_RATE);
|
||||
|
||||
/* Get random channel to operate with and select random peer */
|
||||
stream = get_stream_to_process_(the_endpoint);
|
||||
if (!stream) {
|
||||
continue;
|
||||
}
|
||||
|
||||
elem = zrtp_sys_alloc(sizeof(zrtp_queue_elem_t));
|
||||
if (!elem) {
|
||||
break;
|
||||
}
|
||||
packet = (zrtp_test_packet_t*) elem->data;
|
||||
packet->is_rtp = (packets_counter++ % 20); /* Every 20-th packet is RTCP */
|
||||
|
||||
/*
|
||||
* Construct RTP/RTCP Packet
|
||||
*/
|
||||
if (packet->is_rtp)
|
||||
{
|
||||
ZRTP_UNALIGNED(zrtp_rtp_hdr_t) *rtp_hdr = (zrtp_rtp_hdr_t*)packet->body;
|
||||
|
||||
/* Fill RTP Header according to the specification */
|
||||
zrtp_memset(rtp_hdr, 0, sizeof(zrtp_rtp_hdr_t));
|
||||
rtp_hdr->version = 2; /* Current RTP version 2 */
|
||||
rtp_hdr->pt = 0; /* PCMU padding type */
|
||||
rtp_hdr->ssrc = zrtp_hton32(stream->id); /* Use stream Identifier as it's SSRC */
|
||||
if (stream->seq >= 0xFFFF) {
|
||||
stream->seq = 0;
|
||||
}
|
||||
rtp_hdr->seq = zrtp_hton16(stream->seq++);
|
||||
rtp_hdr->ts = zrtp_hton32((uint32_t)(zrtp_time_now()/1000));
|
||||
|
||||
/* Get RTP body from PGP words lists */
|
||||
word = (char*)(i ? hash_word_list_odd[packets_counter % 256] : hash_word_list_even[packets_counter % 256]);
|
||||
|
||||
zrtp_memcpy(packet->body + sizeof(zrtp_rtp_hdr_t), word, (uint32_t)strlen(word));
|
||||
packet->length = sizeof(zrtp_rtp_hdr_t) + (uint32_t)strlen(word);
|
||||
|
||||
/* Process RTP media with libzrtp */
|
||||
s = zrtp_process_rtp(stream->zrtp, packet->body, &packet->length);
|
||||
}
|
||||
else {
|
||||
ZRTP_UNALIGNED(zrtp_rtcp_hdr_t) *rtcp_hdr = (zrtp_rtcp_hdr_t*)packet->body;
|
||||
|
||||
/* Fill RTCP Header according to the specification */
|
||||
rtcp_hdr->rc = 0;
|
||||
rtcp_hdr->version = 2;
|
||||
rtcp_hdr->ssrc = stream->id;
|
||||
|
||||
/* Get RTP body from PGP words lists. Put RTCP marker at the beginning */
|
||||
zrtp_memcpy(packet->body + sizeof(zrtp_rtcp_hdr_t), "RTCP", 4);
|
||||
word = (char*)( i ? hash_word_list_odd[packets_counter % 256] : hash_word_list_even[packets_counter % 256]);
|
||||
|
||||
zrtp_memcpy(packet->body + sizeof(zrtp_rtcp_hdr_t) + 4, word, (uint32_t)strlen(word));
|
||||
packet->length = sizeof(zrtp_rtcp_hdr_t) + (uint32_t)strlen(word) + 4;
|
||||
/* RTCP packets sould be 32 byes aligned */
|
||||
packet->length += (packet->length % 4) ? (4 - packet->length % 4) : 0;
|
||||
|
||||
/* Process RTCP control with libzrtp */
|
||||
s = zrtp_process_rtcp(stream->zrtp, packet->body, &packet->length);
|
||||
}
|
||||
|
||||
elem->size = packet->length;
|
||||
|
||||
/* Handle zrtp_process_xxx() instructions */
|
||||
switch (s) {
|
||||
/* Put the packet to the queue ==> send packet to the other side pear */
|
||||
case zrtp_status_ok: {
|
||||
ZRTP_LOG(3, (_ZTU_,"Outgoing: (%s) [%p:ssrc=%u] OK. <%s%s> encrypted %d bytes.\n",
|
||||
zrtp_log_state2str(stream->zrtp->state), stream->zrtp, stream->id, packet->is_rtp ? "" : "RTCP", word, packet->length));
|
||||
zrtp_test_queue_push(stream->output, elem);
|
||||
} break;
|
||||
|
||||
case zrtp_status_drop: {
|
||||
ZRTP_LOG(1, (_ZTU_,"Outgoing: (%s) [%p:ssrc=%u] DROPPED.\n",
|
||||
zrtp_log_state2str(stream->zrtp->state), stream->zrtp, stream->id));
|
||||
} break;
|
||||
|
||||
case zrtp_status_fail: {
|
||||
ZRTP_LOG(1, (_ZTU_,"Outgoing: (%s) [%p:ssrc=%u] ENCRYPT FAILED.\n",
|
||||
zrtp_log_state2str(stream->zrtp->state), stream->zrtp, stream->id));
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (zrtp_status_ok != s) {
|
||||
zrtp_sys_free(packet);
|
||||
}
|
||||
}
|
||||
#if (ZRTP_PLATFORM == ZP_WIN32) || (ZRTP_PLATFORM == ZP_WINCE)
|
||||
return 0;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Test Engine Public API
|
||||
*/
|
||||
|
||||
void zrtp_test_endpoint_config_defaults(zrtp_test_endpoint_cfg_t* cfg) {
|
||||
|
||||
zrtp_memset(cfg, 0, sizeof(zrtp_test_endpoint_cfg_t));
|
||||
|
||||
cfg->generate_traffic = 0;
|
||||
|
||||
/* It's always a good idea to start with default values */
|
||||
zrtp_config_defaults(&cfg->zrtp);
|
||||
|
||||
/* Set ZRTP client id */
|
||||
strcpy(cfg->zrtp.client_id, "zrtp-test-engine");
|
||||
|
||||
cfg->zrtp.is_mitm = 0;
|
||||
cfg->zrtp.lic_mode = ZRTP_LICENSE_MODE_ACTIVE;
|
||||
|
||||
cfg->zrtp.cb.event_cb.on_zrtp_secure = &on_zrtp_secure;
|
||||
cfg->zrtp.cb.event_cb.on_zrtp_security_event = &on_zrtp_event;
|
||||
cfg->zrtp.cb.event_cb.on_zrtp_protocol_event = &on_zrtp_event;
|
||||
cfg->zrtp.cb.misc_cb.on_send_packet = &on_send_packet;
|
||||
}
|
||||
|
||||
zrtp_status_t zrtp_test_endpoint_create(zrtp_test_endpoint_cfg_t* cfg,
|
||||
const char *name,
|
||||
zrtp_test_id_t* id) {
|
||||
zrtp_status_t s;
|
||||
unsigned i;
|
||||
char cache_file_path[ZRTP_TEST_STR_LEN];
|
||||
zrtp_endpoint_t *new_endpoint;
|
||||
|
||||
if (g_test_endpoints_count >= K_ZRTP_TEST_MAX_ENDPOINTS)
|
||||
return zrtp_status_alloc_fail;
|
||||
|
||||
new_endpoint = &g_test_endpoints[g_test_endpoints_count++];
|
||||
zrtp_memset(new_endpoint, 0, sizeof(zrtp_endpoint_t));
|
||||
|
||||
/* Copy configuration, we will use it later to clean up after ourselves */
|
||||
zrtp_memcpy(&new_endpoint->cfg, cfg, sizeof(zrtp_test_endpoint_cfg_t));
|
||||
|
||||
/* Remember endpoint name */
|
||||
strcpy(new_endpoint->name, name);
|
||||
|
||||
new_endpoint->id = g_endpoints_counter++;
|
||||
|
||||
/* Adjust cache file path so each endpoint will use it's own file. */
|
||||
sprintf(cache_file_path, "./%s_cache.dat", name);
|
||||
zrtp_zstrcpyc(ZSTR_GV(new_endpoint->cfg.zrtp.def_cache_path), cache_file_path);
|
||||
|
||||
/* Initialize libzrtp engine for this endpoint */
|
||||
s = zrtp_init(&new_endpoint->cfg.zrtp, &new_endpoint->zrtp);
|
||||
if (zrtp_status_ok == s) {
|
||||
*id = new_endpoint->id;
|
||||
|
||||
/* Generate random ZID */
|
||||
zrtp_randstr(new_endpoint->zrtp, new_endpoint->zid, sizeof(new_endpoint->zid));
|
||||
}
|
||||
|
||||
/* Create Input queue*/
|
||||
s = zrtp_test_queue_create(&new_endpoint->input_queue);
|
||||
if (zrtp_status_ok != s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Start processing loop */
|
||||
new_endpoint->is_running = 1;
|
||||
|
||||
for (i = 0; i<K_ZRTP_TEST_PROCESSORS_COUNT; i++) {
|
||||
if (0 != zrtp_thread_create(process_incoming, new_endpoint)) {
|
||||
return zrtp_status_fail;
|
||||
}
|
||||
|
||||
if (cfg->generate_traffic) {
|
||||
if (0 != zrtp_thread_create(process_outgoing, new_endpoint)) {
|
||||
return zrtp_status_fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
zrtp_status_t zrtp_test_endpoint_destroy(zrtp_test_id_t id) {
|
||||
unsigned i;
|
||||
zrtp_status_t s = zrtp_status_ok;
|
||||
zrtp_endpoint_t *endpoint = zrtp_test_endpoint_by_id(id);
|
||||
|
||||
endpoint->is_running = 0;
|
||||
|
||||
if (endpoint->input_queue) {
|
||||
/* Push faked element to the queue to unlock incoming threads */
|
||||
for (i=0; i<K_ZRTP_TEST_PROCESSORS_COUNT; i++) {
|
||||
zrtp_queue_elem_t *elem = malloc(sizeof(zrtp_queue_elem_t));
|
||||
elem->size = 0;
|
||||
zrtp_test_queue_push(endpoint->input_queue, elem);
|
||||
}
|
||||
zrtp_sleep(0.5*1000);
|
||||
|
||||
zrtp_test_queue_destroy(endpoint->input_queue);
|
||||
}
|
||||
|
||||
for (i=0; i<20; i++) zrtp_sleep(100);
|
||||
|
||||
if (endpoint) {
|
||||
/* Shut down libzrtp */
|
||||
if (endpoint->zrtp)
|
||||
s = zrtp_down(endpoint->zrtp);
|
||||
|
||||
/* Clean-up ZRTP cache after ourselves */
|
||||
remove(endpoint->cfg.zrtp.def_cache_path.buffer);
|
||||
} else {
|
||||
s = zrtp_status_fail;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
zrtp_status_t zrtp_test_stream_get(zrtp_test_id_t id,
|
||||
zrtp_test_stream_info_t* info) {
|
||||
|
||||
zrtp_test_stream_t *stream = zrtp_test_stream_by_id(id);
|
||||
if (stream) {
|
||||
zrtp_status_t s;
|
||||
zrtp_memset(info, 0, sizeof(zrtp_test_stream_info_t));
|
||||
|
||||
zrtp_memcpy(info->zrtp_events_queueu, stream->zrtp_events_queueu, sizeof(info->zrtp_events_queueu));
|
||||
info->zrtp_events_count = stream->zrtp_events_count;
|
||||
|
||||
s = zrtp_stream_get(stream->zrtp, &info->zrtp);
|
||||
return s;
|
||||
} else {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
}
|
||||
|
||||
void zrtp_test_session_config_defaults(zrtp_test_session_cfg_t* cfg) {
|
||||
cfg->streams_count = 1;
|
||||
cfg->role = ZRTP_SIGNALING_ROLE_UNKNOWN;
|
||||
cfg->is_enrollment = 0;
|
||||
|
||||
zrtp_profile_defaults(&cfg->zrtp, NULL);
|
||||
}
|
||||
|
||||
zrtp_status_t zrtp_test_session_create(zrtp_test_id_t endpoint_id,
|
||||
zrtp_test_session_cfg_t* cfg,
|
||||
zrtp_test_id_t* id) {
|
||||
zrtp_status_t s;
|
||||
unsigned i;
|
||||
zrtp_test_session_t *the_session;
|
||||
zrtp_endpoint_t *the_endpoint = zrtp_test_endpoint_by_id(endpoint_id);
|
||||
|
||||
if (!the_endpoint)
|
||||
return zrtp_status_fail;
|
||||
|
||||
if (the_endpoint->sessions_count >= K_ZRTP_TEST_MAX_SESSIONS_PER_ENDPOINT)
|
||||
return zrtp_status_fail;
|
||||
|
||||
the_session = &the_endpoint->sessions[the_endpoint->sessions_count++];
|
||||
|
||||
zrtp_memset(the_session, 0, sizeof(zrtp_test_session_t));
|
||||
|
||||
zrtp_memcpy(&the_session->cfg, cfg, sizeof(zrtp_test_session_cfg_t));
|
||||
|
||||
the_session->id = g_sessions_counter++;
|
||||
the_session->endpoint_id = endpoint_id;
|
||||
|
||||
s = zrtp_session_init(the_endpoint->zrtp,
|
||||
&cfg->zrtp,
|
||||
the_endpoint->zid,
|
||||
cfg->role,
|
||||
&the_session->zrtp);
|
||||
|
||||
if (zrtp_status_ok == s) {
|
||||
|
||||
zrtp_session_set_userdata(the_session->zrtp, &the_session->id);
|
||||
|
||||
for (i=0; i<cfg->streams_count; i++) {
|
||||
zrtp_test_stream_t *the_stream = &the_session->streams[i];
|
||||
zrtp_memset(the_stream, 0, sizeof(zrtp_test_stream_t));
|
||||
|
||||
the_stream->id = g_streams_counter++;
|
||||
the_stream->session_id = the_session->id;
|
||||
the_stream->endpoint_id = endpoint_id;
|
||||
|
||||
s = zrtp_stream_attach(the_session->zrtp, &the_stream->zrtp);
|
||||
if (zrtp_status_ok == s) {
|
||||
zrtp_stream_set_userdata(the_stream->zrtp, &the_stream->id);
|
||||
the_session->streams_count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (zrtp_status_ok == s) {
|
||||
*id = the_session->id;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
zrtp_status_t zrtp_test_session_destroy(zrtp_test_id_t id) {
|
||||
zrtp_test_session_t *session = zrtp_test_session_by_id(id);
|
||||
if (session) {
|
||||
/* NOTE: we don't release session slots here due to nature of testing
|
||||
* engine: test configuration constructed from scratch for every single test.
|
||||
*/
|
||||
zrtp_session_down(session->zrtp);
|
||||
}
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
zrtp_status_t zrtp_test_session_get(zrtp_test_id_t id, zrtp_test_session_info_t* info) {
|
||||
zrtp_status_t s;
|
||||
zrtp_test_session_t *session = zrtp_test_session_by_id(id);
|
||||
if (session) {
|
||||
s = zrtp_session_get(session->zrtp, &info->zrtp);
|
||||
if (zrtp_status_ok == s) {
|
||||
unsigned i;
|
||||
for (i=0; i<session->streams_count; i++) {
|
||||
s = zrtp_test_stream_get(session->streams[i].id, &info->streams[i]);
|
||||
if (zrtp_status_ok != s)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
} else {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
}
|
||||
|
||||
zrtp_status_t zrtp_test_channel_create(zrtp_test_id_t left_id, zrtp_test_id_t right_id, zrtp_test_id_t* id) {
|
||||
zrtp_test_channel_t *the_channel;
|
||||
zrtp_test_stream_t *left = zrtp_test_stream_by_id(left_id);
|
||||
zrtp_test_stream_t *right = zrtp_test_stream_by_id(right_id);
|
||||
|
||||
if (!left || !right)
|
||||
return zrtp_status_bad_param;
|
||||
|
||||
if (g_test_channels_count >= K_ZRTP_TEST_MAX_CHANNELS)
|
||||
return zrtp_status_bad_param;
|
||||
|
||||
zrtp_endpoint_t *left_endpoint = zrtp_test_endpoint_by_id(left->endpoint_id);
|
||||
zrtp_endpoint_t *right_endpoint = zrtp_test_endpoint_by_id(right->endpoint_id);
|
||||
|
||||
the_channel = &g_test_channels[g_test_channels_count++];
|
||||
zrtp_memset(the_channel, 0, sizeof(zrtp_test_channel_t));
|
||||
|
||||
the_channel->id = g_channels_counter++;
|
||||
the_channel->left = left;
|
||||
the_channel->right = right;
|
||||
|
||||
left->output = right_endpoint->input_queue;
|
||||
left->input = left_endpoint->input_queue;
|
||||
right->output = left_endpoint->input_queue;
|
||||
right->input = right_endpoint->input_queue;
|
||||
|
||||
right->channel_id = the_channel->id;
|
||||
left->channel_id = the_channel->id;
|
||||
|
||||
the_channel->is_attached = 1;
|
||||
|
||||
*id = the_channel->id;
|
||||
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
zrtp_status_t zrtp_test_channel_create2(zrtp_test_id_t left_session,
|
||||
zrtp_test_id_t right_session,
|
||||
unsigned stream_idx,
|
||||
zrtp_test_id_t *id) {
|
||||
zrtp_test_session_t *left = zrtp_test_session_by_id(left_session);
|
||||
zrtp_test_session_t *right = zrtp_test_session_by_id(right_session);
|
||||
|
||||
if (!left || !right)
|
||||
return zrtp_status_bad_param;
|
||||
|
||||
if (left->streams_count <= stream_idx || right->streams_count <= stream_idx)
|
||||
return zrtp_status_bad_param;
|
||||
|
||||
return zrtp_test_channel_create(left->streams[stream_idx].id, right->streams[stream_idx].id, id);
|
||||
}
|
||||
|
||||
zrtp_status_t zrtp_test_channel_destroy(zrtp_test_id_t id) {
|
||||
zrtp_test_channel_t *channel = zrtp_test_channel_by_id(id);
|
||||
if (!channel)
|
||||
return zrtp_status_bad_param;
|
||||
|
||||
return zrtp_status_ok;
|
||||
}
|
||||
|
||||
zrtp_status_t zrtp_test_channel_start(zrtp_test_id_t id) {
|
||||
zrtp_status_t s1, s2;
|
||||
zrtp_test_channel_t *the_channel = zrtp_test_channel_by_id(id);
|
||||
zrtp_test_session_t *the_session;
|
||||
|
||||
the_session = zrtp_test_session_by_id(the_channel->left->session_id);
|
||||
if (the_session->cfg.is_enrollment)
|
||||
s1 = zrtp_stream_registration_start(the_channel->left->zrtp, the_channel->left->id); /* use stream Id as ssrc */
|
||||
else
|
||||
s1 = zrtp_stream_start(the_channel->left->zrtp, the_channel->left->id); /* use stream Id as ssrc */
|
||||
if (s1 == zrtp_status_ok) {
|
||||
the_session = zrtp_test_session_by_id(the_channel->right->session_id);
|
||||
if (the_session->cfg.is_enrollment)
|
||||
s2 = zrtp_stream_registration_start(the_channel->right->zrtp, the_channel->right->id);
|
||||
else
|
||||
s2 = zrtp_stream_start(the_channel->right->zrtp, the_channel->right->id);
|
||||
} else {
|
||||
return s1;
|
||||
}
|
||||
|
||||
return s2;
|
||||
}
|
||||
|
||||
zrtp_status_t zrtp_test_channel_get(zrtp_test_id_t id,
|
||||
zrtp_test_channel_info_t* info) {
|
||||
|
||||
zrtp_test_channel_t *channel = zrtp_test_channel_by_id(id);
|
||||
if (channel) {
|
||||
zrtp_status_t s;
|
||||
|
||||
zrtp_memset(info, 0, sizeof(zrtp_test_channel_info_t));
|
||||
|
||||
s = zrtp_test_stream_get(channel->left->id, &info->left);
|
||||
if (zrtp_status_ok == s) {
|
||||
s = zrtp_test_stream_get(channel->right->id, &info->right);
|
||||
if (zrtp_status_ok == s) {
|
||||
info->is_secure = channel->is_secure;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
} else {
|
||||
return zrtp_status_bad_param;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Helpers
|
||||
*/
|
||||
|
||||
zrtp_endpoint_t *zrtp_test_endpoint_by_id(zrtp_test_id_t id) {
|
||||
int i;
|
||||
|
||||
if (ZRTP_TEST_UNKNOWN_ID == id) return NULL;
|
||||
|
||||
for (i=0; i<g_test_endpoints_count; i++) {
|
||||
if (g_test_endpoints[i].id == id) {
|
||||
return &g_test_endpoints[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
zrtp_test_session_t *zrtp_test_session_by_id(zrtp_test_id_t id) {
|
||||
int i, j;
|
||||
|
||||
if (ZRTP_TEST_UNKNOWN_ID == id) return NULL;
|
||||
|
||||
for (i=0; i<g_test_endpoints_count; i++) {
|
||||
zrtp_endpoint_t *endpoint = &g_test_endpoints[i];
|
||||
if (endpoint->id == ZRTP_TEST_UNKNOWN_ID)
|
||||
continue;
|
||||
|
||||
for (j=0; j<endpoint->sessions_count; j++) {
|
||||
if (endpoint->sessions[j].id == id) {
|
||||
return &endpoint->sessions[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
zrtp_test_stream_t *zrtp_test_stream_by_id(zrtp_test_id_t id) {
|
||||
int i, j, k;
|
||||
|
||||
if (ZRTP_TEST_UNKNOWN_ID == id) return NULL;
|
||||
|
||||
for (i=0; i<g_test_endpoints_count; i++) {
|
||||
zrtp_endpoint_t *endpoint = &g_test_endpoints[i];
|
||||
if (endpoint->id == ZRTP_TEST_UNKNOWN_ID)
|
||||
continue;
|
||||
|
||||
for (j=0; j<endpoint->sessions_count; j++) {
|
||||
zrtp_test_session_t *session = &endpoint->sessions[j];
|
||||
if (session->id == ZRTP_TEST_UNKNOWN_ID)
|
||||
continue;
|
||||
|
||||
for (k=0; k<session->streams_count; k++) {
|
||||
if (session->streams[k].id == id) {
|
||||
return &session->streams[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
zrtp_test_channel_t *zrtp_test_channel_by_id(zrtp_test_id_t id) {
|
||||
int i;
|
||||
zrtp_test_channel_t *channel = NULL;
|
||||
|
||||
if (ZRTP_TEST_UNKNOWN_ID == id) return NULL;
|
||||
|
||||
for (i=0; i<g_test_channels_count; i++) {
|
||||
if (g_test_channels[i].id != ZRTP_TEST_UNKNOWN_ID && g_test_channels[i].id == id) {
|
||||
channel = &g_test_channels[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
zrtp_test_stream_t *zrtp_test_stream_by_peerid(zrtp_test_id_t id) {
|
||||
int i;
|
||||
if (ZRTP_TEST_UNKNOWN_ID == id) return NULL;
|
||||
|
||||
for (i=0; i<g_test_channels_count; i++) {
|
||||
if (g_test_channels[i].id != ZRTP_TEST_UNKNOWN_ID) {
|
||||
if (g_test_channels[i].left->id == id)
|
||||
return g_test_channels[i].right;
|
||||
else if (g_test_channels[i].right->id == id)
|
||||
return g_test_channels[i].left;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
zrtp_test_id_t zrtp_test_session_get_stream_by_idx(zrtp_test_id_t session_id, unsigned idx) {
|
||||
zrtp_test_session_t *session = zrtp_test_session_by_id(session_id);
|
||||
if (session && session->streams_count > idx) {
|
||||
return session->streams[idx].id;
|
||||
} else {
|
||||
return ZRTP_TEST_UNKNOWN_ID;
|
||||
}
|
||||
}
|
||||
|
||||
zrtp_stream_t *zrtp_stream_for_test_stream(zrtp_test_id_t stream_id) {
|
||||
zrtp_test_stream_t *stream = zrtp_test_stream_by_id(stream_id);
|
||||
if (stream) {
|
||||
return stream->zrtp;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned zrtp_stream_did_event_receive(zrtp_test_id_t stream_id, unsigned event) {
|
||||
unsigned i;
|
||||
zrtp_test_stream_info_t stream_info;
|
||||
|
||||
zrtp_test_stream_get(stream_id, &stream_info);
|
||||
for (i=0; i<stream_info.zrtp_events_count; i++) {
|
||||
if (stream_info.zrtp_events_queueu[i] == event)
|
||||
break;
|
||||
}
|
||||
|
||||
return (i != stream_info.zrtp_events_count);
|
||||
}
|
||||
|
130
libs/libzrtp/test/test_engine.h
Normal file
130
libs/libzrtp/test/test_engine.h
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include "zrtp.h"
|
||||
|
||||
/** libzrtp test elements identifier */
|
||||
typedef uint32_t zrtp_test_id_t;
|
||||
|
||||
/** Defines constant for unknown test element identifier */
|
||||
#define ZRTP_TEST_UNKNOWN_ID 0
|
||||
|
||||
/** Default lengths for libzrtp test string buffers */
|
||||
#define ZRTP_TEST_STR_LEN 128
|
||||
|
||||
/** libzrtp test endpoint configuration */
|
||||
typedef struct {
|
||||
zrtp_config_t zrtp; /** libzrtp global configuration parameters */
|
||||
unsigned generate_traffic; /** switch On to emulate RTP/RTCP traffic generation. Off by default. */
|
||||
} zrtp_test_endpoint_cfg_t;
|
||||
|
||||
/** ZRTP test session parameters*/
|
||||
typedef struct {
|
||||
zrtp_profile_t zrtp; /** libzrtp session parameters */
|
||||
unsigned streams_count; /** number of zrtp streams to be attached to the session */
|
||||
zrtp_signaling_role_t role; /** signaling role, default is ZRTP_SIGNALING_ROLE_UNKNOWN */
|
||||
unsigned is_enrollment; /** true if enrollment session should be created */
|
||||
} zrtp_test_session_cfg_t;
|
||||
|
||||
/** ZRTP test stream info */
|
||||
typedef struct {
|
||||
zrtp_stream_info_t zrtp; /** libzrtp stream info */
|
||||
unsigned zrtp_events_queueu[128]; /** list of received zrtp events*/
|
||||
unsigned zrtp_events_count; /** number of received events */
|
||||
} zrtp_test_stream_info_t;
|
||||
|
||||
/** ZRTP test session state snapshot */
|
||||
typedef struct {
|
||||
zrtp_session_info_t zrtp; /** libzrtp session info*/
|
||||
zrtp_test_stream_info_t streams[ZRTP_MAX_STREAMS_PER_SESSION]; /** array of attached streams info */
|
||||
unsigned streams_count; /** number streams attached to the session */
|
||||
} zrtp_test_session_info_t;
|
||||
|
||||
/** *ZRTP test channel state */
|
||||
typedef struct {
|
||||
zrtp_test_stream_info_t left; /** one-leg zrtp stream */
|
||||
zrtp_test_stream_info_t right; /** second-leg zrtp stream */
|
||||
unsigned char is_secure; /** enabled when both streams in the channel are secure */
|
||||
} zrtp_test_channel_info_t;
|
||||
|
||||
|
||||
/**
|
||||
* Initialize zrtp test endpoint configuration with default values
|
||||
* @param cfg - endpoint config to initialize
|
||||
*/
|
||||
void zrtp_test_endpoint_config_defaults(zrtp_test_endpoint_cfg_t *cfg);
|
||||
|
||||
/**
|
||||
* ZRTP test endpoint constructor
|
||||
* One endpoint is created, it starts processing threads and ready to emulate ZRTP exchange.
|
||||
*
|
||||
* @param cfg - endpoint configuration
|
||||
* @param name - endpoint name for debug purposes and cache naming, e.h "Alice", "Bob".
|
||||
* @param id - just created endpoint identifier will be placed here
|
||||
*
|
||||
* @return zrtp_status_ok on success or some of zrtp_status_t error codes on failure
|
||||
*/
|
||||
zrtp_status_t zrtp_test_endpoint_create(zrtp_test_endpoint_cfg_t *cfg,
|
||||
const char *name,
|
||||
zrtp_test_id_t *id);
|
||||
|
||||
/**
|
||||
* ZRTP test endpoint destructor
|
||||
* zrtp_test_endpoint_destroy() stops processing threads and release all
|
||||
* recurses allocated in zrtp_test_endpoint_create().
|
||||
*
|
||||
* @param id - endpoint identifier
|
||||
* @return zrtp_status_ok on success or some of zrtp_status_t error codes on failure
|
||||
*/
|
||||
zrtp_status_t zrtp_test_endpoint_destroy(zrtp_test_id_t id);
|
||||
|
||||
/**
|
||||
* Enables test session config with default values
|
||||
* @param cfg - session config for initialization
|
||||
*/
|
||||
void zrtp_test_session_config_defaults(zrtp_test_session_cfg_t *cfg);
|
||||
|
||||
/**
|
||||
* Create zrtp test session
|
||||
*
|
||||
* @param endpoint - test endpoint creating endpoint should belong to
|
||||
* @param cfg - session parameters
|
||||
* @param id - created session identifier will be placed here
|
||||
* @return zrtp_status_ok on success or some of zrtp_status_t error codes on failure
|
||||
*/
|
||||
zrtp_status_t zrtp_test_session_create(zrtp_test_id_t endpoint,
|
||||
zrtp_test_session_cfg_t *cfg,
|
||||
zrtp_test_id_t *id);
|
||||
|
||||
zrtp_status_t zrtp_test_session_destroy(zrtp_test_id_t id);
|
||||
|
||||
zrtp_status_t zrtp_test_session_get(zrtp_test_id_t id, zrtp_test_session_info_t *info);
|
||||
|
||||
/**
|
||||
* Get stream Id by it's index in zrtp session
|
||||
*
|
||||
* @param session_id - zrtp test session id where needed stream should be taken
|
||||
* @param idx - stream index
|
||||
* @return found stream id, or ZRTP_TEST_UNKNOWN_ID if idex is out of stream array range
|
||||
*/
|
||||
zrtp_test_id_t zrtp_test_session_get_stream_by_idx(zrtp_test_id_t session_id, unsigned idx);
|
||||
|
||||
zrtp_status_t zrtp_test_stream_get(zrtp_test_id_t id, zrtp_test_stream_info_t *info);
|
||||
|
||||
zrtp_status_t zrtp_test_channel_create(zrtp_test_id_t left_stream, zrtp_test_id_t right_stream, zrtp_test_id_t *id);
|
||||
zrtp_status_t zrtp_test_channel_create2(zrtp_test_id_t left_session, zrtp_test_id_t right_session, unsigned stream_idx, zrtp_test_id_t *id);
|
||||
zrtp_status_t zrtp_test_channel_destroy(zrtp_test_id_t id);
|
||||
zrtp_status_t zrtp_test_channel_start(zrtp_test_id_t id);
|
||||
zrtp_status_t zrtp_test_channel_get(zrtp_test_id_t id, zrtp_test_channel_info_t *info);
|
||||
|
||||
zrtp_stream_t *zrtp_stream_for_test_stream(zrtp_test_id_t stream_id);
|
||||
|
||||
unsigned zrtp_stream_did_event_receive(zrtp_test_id_t stream_id, unsigned event);
|
||||
|
||||
|
@ -1,81 +0,0 @@
|
||||
========================================================================
|
||||
WIN32 APPLICATION : libzrtp_test_GUI Project Overview
|
||||
========================================================================
|
||||
|
||||
AppWizard has created this libzrtp_test_GUI application for you.
|
||||
|
||||
This file contains a summary of what you will find in each of the files that
|
||||
make up your libzrtp_test_GUI application.
|
||||
|
||||
|
||||
libzrtp_test_GUI.vcproj
|
||||
This is the main project file for VC++ projects generated using an Application Wizard.
|
||||
It contains information about the version of Visual C++ that generated the file, and
|
||||
information about the platforms, configurations, and project features selected with the
|
||||
Application Wizard.
|
||||
|
||||
libzrtp_test_GUI.cpp
|
||||
This is the main application source file.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
AppWizard has created the following resources:
|
||||
|
||||
|
||||
libzrtp_test_GUIppc.rc
|
||||
This is a listing of all of the Microsoft Windows resources that the
|
||||
program uses when compiling for the Pocket PC 2003 platform, or a platform
|
||||
that supports the same user interface model. It includes the icons, bitmaps,
|
||||
and cursors that are stored in the RES subdirectory. This file can be
|
||||
directly edited in Microsoft Visual C++. When the .rc file is persisted,
|
||||
the defines in the data section are persisted as the hexadecimal version
|
||||
of the numeric value they are defined to rather than the friendly name of
|
||||
the define.
|
||||
|
||||
libzrtp_test_GUIppc.rc2
|
||||
This file contains resources that are not edited by Microsoft
|
||||
Visual C++. You should place all resources not editable by
|
||||
the resource editor in this file.
|
||||
|
||||
Resourceppc.h
|
||||
This is the standard header file, which defines new resource IDs.
|
||||
Microsoft Visual C++ reads and updates this file.
|
||||
|
||||
libzrtp_test_GUIsp.rc
|
||||
This is a listing of all of the Microsoft Windows resources that the
|
||||
program uses when compiling for the Smartphone 2003 platform, or a
|
||||
platform that supports the same user interface model. It includes the
|
||||
icons, bitmaps, and cursors that are stored in the RES subdirectory.
|
||||
This file can be directly edited in Microsoft Visual C++. When the
|
||||
.rc file is persisted, the defines in the data section are persisted
|
||||
as the hexadecimal version of the numeric value they are defined to
|
||||
rather than the friendly name of the define.
|
||||
|
||||
libzrtp_test_GUIsp.rc2
|
||||
This file contains resources that are not edited by Microsoft
|
||||
Visual C++. You should place all resources not editable by
|
||||
the resource editor in this file.
|
||||
|
||||
Resourcesp.h
|
||||
This is the standard header file, which defines new resource IDs.
|
||||
Microsoft Visual C++ reads and updates this file.
|
||||
|
||||
|
||||
|
||||
libzrtp_test_GUI.ico
|
||||
This is an icon file, which is used as the application's icon (32x32).
|
||||
This icon is included by the main resource file libzrtp_test_GUI.rc.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
Other standard files:
|
||||
|
||||
StdAfx.h, StdAfx.cpp
|
||||
These files are used to build a precompiled header (PCH) file
|
||||
named libzrtp_test_GUI.pch and a precompiled types file named StdAfx.obj.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
Other notes:
|
||||
|
||||
AppWizard uses "TODO:" comments to indicate parts of the source code you
|
||||
should add to or customize.
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////s
|
@ -1,492 +0,0 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Nikolay Popok mailto: <chaser@soft-industry.com>
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "libzrtp_test_GUI.h"
|
||||
#include <windows.h>
|
||||
#include <commctrl.h>
|
||||
|
||||
//#include "resourcesp.h"
|
||||
|
||||
#include <Afx.h>
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "zrtp.h"
|
||||
#include "zrtp_test_core.h"
|
||||
}
|
||||
|
||||
#define MAX_LOADSTRING 100
|
||||
|
||||
// Global Variables:
|
||||
HINSTANCE g_hInst; // current instance
|
||||
HWND g_hWndMenuBar; // menu bar handle
|
||||
HWND hWndList;
|
||||
HWND g_hWnd;
|
||||
|
||||
HFONT font;
|
||||
|
||||
int action_id = 0;
|
||||
|
||||
static void do_action();
|
||||
static void print_log_ce(int level, const char *data, int len, int offset);
|
||||
static DWORD WINAPI destroy_func(void *param);
|
||||
|
||||
static FILE *log_file = NULL;
|
||||
|
||||
typedef struct zrtp_test_command
|
||||
{
|
||||
int32_t code;
|
||||
int first_conn;
|
||||
int last_conn;
|
||||
uint32_t extra, extra2;
|
||||
} zrtp_test_command_t;
|
||||
|
||||
typedef enum zrtp_test_code
|
||||
{
|
||||
ZRTP_TEST_CREATE = 0,
|
||||
ZRTP_TEST_DESTROY,
|
||||
ZRTP_TEST_ZSTART,
|
||||
ZRTP_TEST_ZSECURE,
|
||||
ZRTP_TEST_QUIT,
|
||||
ZRTP_TEST_INC,
|
||||
ZRTP_TEST_DEC,
|
||||
ZRTP_TEST_CLEAR,
|
||||
ZRTP_TEST_SLEEP,
|
||||
ZRTP_TEST_LOGS,
|
||||
ZRTP_TEST_INFO,
|
||||
ZRTP_TEST_HELP,
|
||||
ZRTP_TEST_CMD_SIZE
|
||||
} zrtp_test_code_t;
|
||||
|
||||
extern "C" {
|
||||
void do_quit();
|
||||
int zrtp_test_zrtp_init();
|
||||
void zrtp_test_crypto(zrtp_global_t* zrtp);
|
||||
int zrtp_add_system_state(zrtp_global_t* zrtp, MD_CTX *ctx);
|
||||
}
|
||||
|
||||
// Forward declarations of functions included in this code module:
|
||||
ATOM MyRegisterClass(HINSTANCE, LPTSTR);
|
||||
BOOL InitInstance(HINSTANCE, int);
|
||||
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
#ifndef WIN32_PLATFORM_WFSP
|
||||
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
|
||||
#endif // !WIN32_PLATFORM_WFSP
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPTSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
MSG msg;
|
||||
|
||||
// Perform application initialization:
|
||||
if (!InitInstance(hInstance, nCmdShow))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifndef WIN32_PLATFORM_WFSP
|
||||
HACCEL hAccelTable;
|
||||
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_LIBZRTP_TEST_GUI));
|
||||
#endif // !WIN32_PLATFORM_WFSP
|
||||
|
||||
// Main message loop:
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
{
|
||||
if ( msg.message == WM_KEYDOWN )
|
||||
{
|
||||
switch ( msg.wParam )
|
||||
{
|
||||
case VK_LEFT:
|
||||
{
|
||||
msg.wParam = 0;
|
||||
break;
|
||||
}
|
||||
case VK_RIGHT:
|
||||
{
|
||||
msg.wParam = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef WIN32_PLATFORM_WFSP
|
||||
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
|
||||
#endif // !WIN32_PLATFORM_WFSP
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
return (int) msg.wParam;
|
||||
}
|
||||
|
||||
//
|
||||
// FUNCTION: MyRegisterClass()
|
||||
//
|
||||
// PURPOSE: Registers the window class.
|
||||
//
|
||||
// COMMENTS:
|
||||
//
|
||||
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
|
||||
{
|
||||
WNDCLASS wc;
|
||||
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = hInstance;
|
||||
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_LIBZRTP_TEST_GUI));
|
||||
wc.hCursor = 0;
|
||||
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
|
||||
wc.lpszMenuName = 0;
|
||||
wc.lpszClassName = szWindowClass;
|
||||
|
||||
return RegisterClass(&wc);
|
||||
}
|
||||
|
||||
//
|
||||
// FUNCTION: InitInstance(HINSTANCE, int)
|
||||
//
|
||||
// PURPOSE: Saves instance handle and creates main window
|
||||
//
|
||||
// COMMENTS:
|
||||
//
|
||||
// In this function, we save the instance handle in a global variable and
|
||||
// create and display the main program window.
|
||||
//
|
||||
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
||||
{
|
||||
HWND hWnd;
|
||||
TCHAR szTitle[MAX_LOADSTRING]; // title bar text
|
||||
TCHAR szWindowClass[MAX_LOADSTRING]; // main window class name
|
||||
|
||||
g_hInst = hInstance; // Store instance handle in our global variable
|
||||
|
||||
#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
|
||||
// SHInitExtraControls should be called once during your application's initialization to initialize any
|
||||
// of the device specific controls such as CAPEDIT and SIPPREF.
|
||||
SHInitExtraControls();
|
||||
#endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP
|
||||
|
||||
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
||||
LoadString(hInstance, IDC_LIBZRTP_TEST_GUI, szWindowClass, MAX_LOADSTRING);
|
||||
|
||||
#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
|
||||
//If it is already running, then focus on the window, and exit
|
||||
hWnd = FindWindow(szWindowClass, szTitle);
|
||||
if (hWnd)
|
||||
{
|
||||
// set focus to foremost child window
|
||||
// The "| 0x00000001" is used to bring any owned windows to the foreground and
|
||||
// activate them.
|
||||
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
|
||||
return 0;
|
||||
}
|
||||
#endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP
|
||||
|
||||
if (!MyRegisterClass(hInstance, szWindowClass))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
|
||||
|
||||
if (!hWnd)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_hWnd = hWnd;
|
||||
#ifdef WIN32_PLATFORM_PSPC
|
||||
// When the main window is created using CW_USEDEFAULT the height of the menubar (if one
|
||||
// is created is not taken into account). So we resize the window after creating it
|
||||
// if a menubar is present
|
||||
if (g_hWndMenuBar)
|
||||
{
|
||||
RECT rc;
|
||||
RECT rcMenuBar;
|
||||
|
||||
GetWindowRect(hWnd, &rc);
|
||||
GetWindowRect(g_hWndMenuBar, &rcMenuBar);
|
||||
rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
|
||||
|
||||
MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
|
||||
}
|
||||
#endif // WIN32_PLATFORM_PSPC
|
||||
|
||||
ShowWindow(hWnd, nCmdShow);
|
||||
UpdateWindow(hWnd);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
|
||||
//
|
||||
// PURPOSE: Processes messages for the main window.
|
||||
//
|
||||
// WM_COMMAND - process the application menu
|
||||
// WM_PAINT - Paint the main window
|
||||
// WM_DESTROY - post a quit message and return
|
||||
//
|
||||
//
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
int wmId, wmEvent;
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc;
|
||||
|
||||
#if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP)
|
||||
static SHACTIVATEINFO s_sai;
|
||||
#endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case WM_COMMAND:
|
||||
wmId = LOWORD(wParam);
|
||||
wmEvent = HIWORD(wParam);
|
||||
// Parse the menu selections:
|
||||
switch (wmId)
|
||||
{
|
||||
#ifndef WIN32_PLATFORM_WFSP
|
||||
case IDM_HELP_ABOUT:
|
||||
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
|
||||
break;
|
||||
#endif // !WIN32_PLATFORM_WFSP
|
||||
#ifdef WIN32_PLATFORM_WFSP
|
||||
case IDM_OK:
|
||||
do_action();
|
||||
|
||||
break;
|
||||
#endif // WIN32_PLATFORM_WFSP
|
||||
#ifdef WIN32_PLATFORM_PSPC
|
||||
case IDM_OK:
|
||||
do_action();
|
||||
break;
|
||||
#endif // WIN32_PLATFORM_PSPC
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
break;
|
||||
case WM_CREATE:
|
||||
#ifdef SHELL_AYGSHELL
|
||||
SHMENUBARINFO mbi;
|
||||
|
||||
memset(&mbi, 0, sizeof(SHMENUBARINFO));
|
||||
mbi.cbSize = sizeof(SHMENUBARINFO);
|
||||
mbi.hwndParent = hWnd;
|
||||
mbi.nToolBarId = IDR_MENU;
|
||||
mbi.hInstRes = g_hInst;
|
||||
|
||||
if (!SHCreateMenuBar(&mbi))
|
||||
{
|
||||
g_hWndMenuBar = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_hWndMenuBar = mbi.hwndMB;
|
||||
}
|
||||
|
||||
#ifndef WIN32_PLATFORM_WFSP
|
||||
// Initialize the shell activate info structure
|
||||
memset(&s_sai, 0, sizeof (s_sai));
|
||||
s_sai.cbSize = sizeof (s_sai);
|
||||
#endif // !WIN32_PLATFORM_WFSP
|
||||
#endif // SHELL_AYGSHELL
|
||||
|
||||
#ifdef WIN32_PLATFORM_WFSP
|
||||
hWndList = CreateWindow(TEXT("listbox"),NULL, WS_CHILD|
|
||||
WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|WS_TABSTOP, 0,0, 300, 200, hWnd,
|
||||
(HMENU)"", g_hInst, NULL);
|
||||
#else
|
||||
hWndList = CreateWindow(TEXT("listbox"),NULL, WS_CHILD|
|
||||
WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|WS_TABSTOP, 0,0, 250, 200, hWnd,
|
||||
(HMENU)"", g_hInst, NULL);
|
||||
#endif // !WIN32_PLATFORM_WFSP
|
||||
|
||||
font = CreateFont(10, // height of font
|
||||
0, // average character width
|
||||
0, // angle of escapement
|
||||
0, // base-line orientation angle
|
||||
400, // font weight
|
||||
0, // italic attribute option
|
||||
FALSE, // underline attribute option
|
||||
FALSE, // strikeout attribute option
|
||||
ANSI_CHARSET, // character set identifier
|
||||
OUT_DEFAULT_PRECIS, // output precision
|
||||
CLIP_DEFAULT_PRECIS, // clipping precision
|
||||
ANTIALIASED_QUALITY, // output quality
|
||||
FF_DONTCARE, // pitch and family
|
||||
TEXT("Times New Roman"));
|
||||
|
||||
SendMessage(hWndList, WM_SETFONT, (WPARAM)font, (LPARAM)TRUE);
|
||||
|
||||
SetFocus(hWndList);
|
||||
break;
|
||||
case WM_PAINT:
|
||||
hdc = BeginPaint(hWnd, &ps);
|
||||
|
||||
EndPaint(hWnd, &ps);
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
#ifdef SHELL_AYGSHELL
|
||||
CommandBar_Destroy(g_hWndMenuBar);
|
||||
#endif // SHELL_AYGSHELL
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
#if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP)
|
||||
case WM_ACTIVATE:
|
||||
// Notify shell of our activate message
|
||||
SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
|
||||
break;
|
||||
case WM_SETTINGCHANGE:
|
||||
SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
|
||||
break;
|
||||
#endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP
|
||||
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
HWND hwndAbout = NULL;
|
||||
|
||||
#ifndef WIN32_PLATFORM_WFSP
|
||||
// Message handler for about box.
|
||||
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
#ifdef SHELL_AYGSHELL
|
||||
{
|
||||
// Create a Done button and size it.
|
||||
SHINITDLGINFO shidi;
|
||||
shidi.dwMask = SHIDIM_FLAGS;
|
||||
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
|
||||
shidi.hDlg = hDlg;
|
||||
SHInitDialog(&shidi);
|
||||
}
|
||||
#endif // SHELL_AYGSHELL
|
||||
|
||||
return (INT_PTR)TRUE;
|
||||
|
||||
case WM_COMMAND:
|
||||
#ifdef SHELL_AYGSHELL
|
||||
if (LOWORD(wParam) == IDOK)
|
||||
#endif
|
||||
{
|
||||
return (INT_PTR)TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CLOSE:
|
||||
EndDialog(hDlg, message);
|
||||
return (INT_PTR)TRUE;
|
||||
|
||||
#ifdef _DEVICE_RESOLUTION_AWARE
|
||||
case WM_SIZE:
|
||||
{
|
||||
DRA::RelayoutDialog(
|
||||
g_hInst,
|
||||
hDlg,
|
||||
DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_ABOUTBOX_WIDE) : MAKEINTRESOURCE(IDD_ABOUTBOX));
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
return (INT_PTR)FALSE;
|
||||
}
|
||||
#endif // !WIN32_PLATFORM_WFSP
|
||||
|
||||
static void do_action()
|
||||
{
|
||||
switch (action_id)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
int status;
|
||||
|
||||
zrtp_log_set_log_engine((zrtp_log_engine*)print_log_ce);
|
||||
status = zrtp_test_zrtp_init();
|
||||
if (0 != status) {
|
||||
return;
|
||||
}
|
||||
|
||||
zrtp_test_crypto(zrtp_global);
|
||||
|
||||
{
|
||||
zrtp_test_channel_id_t id;
|
||||
zrtp_test_channel_config_t sconfig;
|
||||
|
||||
sconfig.is_autosecure = 0;
|
||||
sconfig.is_preshared = 0;
|
||||
sconfig.streams_count = 1;
|
||||
|
||||
status = zrtp_test_channel_create(&sconfig, &id);
|
||||
|
||||
if (0 == status) {
|
||||
zrtp_test_channel_start(id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
zrtp_thread_create(destroy_func, NULL);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
DeleteObject(font);
|
||||
if (log_file) fclose(log_file);
|
||||
#ifdef WIN32_PLATFORM_WFSP
|
||||
DestroyWindow(g_hWnd);
|
||||
#endif
|
||||
#ifdef WIN32_PLATFORM_PSPC
|
||||
SendMessage(g_hWnd, WM_CLOSE, 0, 0);
|
||||
#endif // WIN32_PLATFORM_PSPC
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
action_id++;
|
||||
}
|
||||
|
||||
static DWORD WINAPI destroy_func(void *param)
|
||||
{
|
||||
do_quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void print_log_ce(int level, const char *data, int len, int offset)
|
||||
{
|
||||
if ( !log_file )
|
||||
log_file = fopen("zrtp_test.log", "a");
|
||||
|
||||
fprintf(log_file, "%s", data);
|
||||
|
||||
if (level < 3 || 1)
|
||||
{
|
||||
CString strUnicode = data;
|
||||
SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM)strUnicode.GetBuffer(100));
|
||||
SendMessage(hWndList, WM_VSCROLL, SB_BOTTOM, 0L);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Nikolay Popok mailto: <chaser@soft-industry.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifdef POCKETPC2003_UI_MODEL
|
||||
#include "resourceppc.h"
|
||||
#endif
|
||||
#ifdef SMARTPHONE2003_UI_MODEL
|
||||
#include "resourcesp.h"
|
||||
#endif
|
Binary file not shown.
Before Width: | Height: | Size: 23 KiB |
@ -1,183 +0,0 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resourceppc.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#define APSTUDIO_HIDDEN_SYMBOLS
|
||||
#include "resdefce.h"
|
||||
#undef APSTUDIO_HIDDEN_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Russian resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
|
||||
#pragma code_page(1251)
|
||||
#endif //_WIN32
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
IDI_LIBZRTP_TEST_GUI ICON "libzrtp_test_GUI.ico"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Menu
|
||||
//
|
||||
|
||||
IDR_MENU MENU
|
||||
BEGIN
|
||||
POPUP "Help"
|
||||
BEGIN
|
||||
MENUITEM "About", IDM_HELP_ABOUT
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Accelerator
|
||||
//
|
||||
|
||||
IDC_LIBZRTP_TEST_GUI ACCELERATORS
|
||||
BEGIN
|
||||
"A", IDM_HELP_ABOUT, VIRTKEY, CONTROL, NOINVERT
|
||||
"Q", IDM_OK, VIRTKEY, CONTROL, NOINVERT
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog
|
||||
//
|
||||
|
||||
IDD_ABOUTBOX DIALOG 0, 0, 164, 172
|
||||
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION
|
||||
EXSTYLE 0x80000000L
|
||||
CAPTION "About libzrtp_test_GUI"
|
||||
FONT 8, "MS Shell Dlg"
|
||||
BEGIN
|
||||
LISTBOX IDC_LIST1,7,7,150,158,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP
|
||||
END
|
||||
|
||||
IDD_ABOUTBOX_WIDE DIALOG 0, 0, 210, 129
|
||||
STYLE DS_SETFONT | WS_POPUP | WS_CAPTION
|
||||
EXSTYLE 0x80000000L
|
||||
CAPTION "About libzrtp_test_GUI"
|
||||
FONT 8, "MS Shell Dlg"
|
||||
BEGIN
|
||||
ICON IDI_LIBZRTP_TEST_GUI,IDC_STATIC_1,12,12,21,20,SS_REALSIZEIMAGE
|
||||
LTEXT "libzrtp_test_GUI Version 1.0",IDC_STATIC_2,48,12,66,8,SS_NOPREFIX
|
||||
LTEXT "Copyright (C) 2008",IDC_STATIC_3,48,24,66,8
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO
|
||||
BEGIN
|
||||
IDD_ABOUTBOX, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 157
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 165
|
||||
END
|
||||
|
||||
IDD_ABOUTBOX_WIDE, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 203
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 122
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resourceppc.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
|
||||
"#include ""resdefce.h""\r\n"
|
||||
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)\r\n"
|
||||
"LANGUAGE 25, 1\r\n"
|
||||
"#pragma code_page(1251)\r\n"
|
||||
"#include ""libzrtp_test_GUIppc.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
|
||||
"#endif\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// String Table
|
||||
//
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_APP_TITLE "libzrtp_test_GUI"
|
||||
IDC_LIBZRTP_TEST_GUI "LIBZRTP_TEST_GUI"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_OK "OK"
|
||||
IDS_HELP "HELP"
|
||||
END
|
||||
|
||||
#endif // Russian resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
|
||||
LANGUAGE 25, 1
|
||||
#pragma code_page(1251)
|
||||
#include "libzrtp_test_GUIppc.rc2" // non-Microsoft Visual C++ edited resources
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
@ -1,35 +0,0 @@
|
||||
//
|
||||
// libzrtp_test_GUIPPC.RC2 - resources Microsoft Visual C++ does not edit directly
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#error this file is not editable by Microsoft Visual C++
|
||||
#endif //APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Add manually edited resources here...
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
HI_RES_AWARE CEUX {1} // turn off the emulation layer
|
||||
// Remove this resource to enable pixel-
|
||||
// doubling on platforms that support it
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SHMENUBAR
|
||||
//
|
||||
|
||||
IDR_MENU SHMENUBAR DISCARDABLE
|
||||
BEGIN
|
||||
IDR_MENU,
|
||||
2,
|
||||
|
||||
I_IMAGENONE, IDM_OK, TBSTATE_ENABLED, TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE,
|
||||
IDS_OK, 0, NOMENU,
|
||||
|
||||
I_IMAGENONE, IDM_HELP, TBSTATE_ENABLED, TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE,
|
||||
IDS_HELP, 0, 0,
|
||||
END
|
||||
|
@ -1,95 +0,0 @@
|
||||
//Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resourcesp.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#define APSTUDIO_HIDDEN_SYMBOLS
|
||||
#include "resdefce.h"
|
||||
#undef APSTUDIO_HIDDEN_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
|
||||
LANGUAGE 25, 1
|
||||
#pragma code_page(1251)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
|
||||
IDI_LIBZRTP_TEST_GUI ICON "libzrtp_test_GUI.ico"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Menu
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resourcesp.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
|
||||
"#include ""resdefce.h""\r\n"
|
||||
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)\r\n"
|
||||
"LANGUAGE 25, 1\r\n"
|
||||
"#pragma code_page(1251)\r\n"
|
||||
"#include ""libzrtp_test_GUIsp.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
|
||||
"#endif\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// String Table
|
||||
//
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDC_LIBZRTP_TEST_GUI "LIBZRTP_TEST_GUI"
|
||||
IDS_APP_TITLE "libzrtp_test_GUI"
|
||||
IDS_OK "Ok"
|
||||
END
|
||||
|
||||
#endif
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
|
||||
LANGUAGE 25, 1
|
||||
#pragma code_page(1251)
|
||||
#include "libzrtp_test_GUIsp.rc2" // non-Microsoft Visual C++ edited resources
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
@ -1,31 +0,0 @@
|
||||
//
|
||||
// libzrtp_test_GUISP.RC2 - resources Microsoft Visual C++ does not edit directly
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#error this file is not editable by Microsoft Visual C++
|
||||
#endif //APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Add manually edited resources here...
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
HI_RES_AWARE CEUX {1} // turn off the emulation layer
|
||||
// Remove this resource to enable pixel-
|
||||
// doubling on platforms that support it
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Data
|
||||
//
|
||||
|
||||
IDR_MENU SHMENUBAR DISCARDABLE
|
||||
BEGIN
|
||||
IDR_MENU,
|
||||
1,
|
||||
|
||||
I_IMAGENONE, IDM_OK, TBSTATE_ENABLED, TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE,
|
||||
IDS_OK, 0, NOMENU,
|
||||
END
|
@ -1,36 +0,0 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by libzrtp_test_GUIppc.rc
|
||||
//
|
||||
#define IDS_APP_TITLE 1
|
||||
#define IDC_LIBZRTP_TEST_GUI 2
|
||||
#define IDI_LIBZRTP_TEST_GUI 101
|
||||
#define IDR_MENU 102
|
||||
#define IDS_OK 103
|
||||
#define IDS_HELP 104
|
||||
#define IDD_ABOUTBOX 105
|
||||
#define IDD_ABOUTBOX_WIDE 106
|
||||
#define IDC_STATIC_1 201
|
||||
#define IDC_STATIC_2 202
|
||||
#define IDC_STATIC_3 203
|
||||
#define IDC_LIST1 1000
|
||||
#define ID_CMD_INCREASERATE 32771
|
||||
#define ID_CMD_DESCREASERATE 32772
|
||||
#define ID_ACCELERATOR32773 32773
|
||||
#define IDM_ZRTP_LEFT 32773
|
||||
#define IDM_OK 40000
|
||||
#define IDM_HELP 40001
|
||||
#define IDM_HELP_ABOUT 40002
|
||||
#define IDC_STATIC -1
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 129
|
||||
#define _APS_NEXT_COMMAND_VALUE 32775
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 110
|
||||
#endif
|
||||
#endif
|
@ -1,28 +0,0 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by libzrtp_test_GUIsp.rc
|
||||
//
|
||||
|
||||
#define IDS_APP_TITLE 1
|
||||
#define IDC_LIBZRTP_TEST_GUI 2
|
||||
#define IDI_LIBZRTP_TEST_GUI 101
|
||||
#define IDR_MENU 102
|
||||
#define IDS_OK 104
|
||||
#define IDM_OK 40001
|
||||
#ifndef IDC_STATIC
|
||||
#define IDC_STATIC -1
|
||||
#define ID_CMD_INCREASERATE 32771
|
||||
#define ID_CMD_DESCREASERATE 32772
|
||||
#endif
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 130
|
||||
#define _APS_NEXT_RESOURCE_VALUE 129
|
||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 110
|
||||
#endif
|
||||
#endif
|
@ -1,18 +0,0 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Nikolay Popok mailto: <chaser@soft-industry.com>
|
||||
*/
|
||||
|
||||
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// libzrtp_test_GUI.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
@ -1,61 +0,0 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#pragma comment(linker, "/nodefaultlib:libc.lib")
|
||||
#pragma comment(linker, "/nodefaultlib:libcd.lib")
|
||||
|
||||
// NOTE - this value is not strongly correlated to the Windows CE OS version being targeted
|
||||
#define WINVER _WIN32_WCE
|
||||
|
||||
#include <ceconfig.h>
|
||||
#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
|
||||
#define SHELL_AYGSHELL
|
||||
#endif
|
||||
|
||||
#ifdef _CE_DCOM
|
||||
#define _ATL_APARTMENT_THREADED
|
||||
#endif
|
||||
|
||||
#ifdef SHELL_AYGSHELL
|
||||
#include <aygshell.h>
|
||||
#pragma comment(lib, "aygshell.lib")
|
||||
#endif // SHELL_AYGSHELL
|
||||
|
||||
|
||||
// Windows Header Files:
|
||||
#include <windows.h>
|
||||
|
||||
// C RunTime Header Files
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include <memory.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
|
||||
#ifndef _DEVICE_RESOLUTION_AWARE
|
||||
#define _DEVICE_RESOLUTION_AWARE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _DEVICE_RESOLUTION_AWARE
|
||||
#include "DeviceResolutionAware.h"
|
||||
#endif
|
||||
|
||||
#if _WIN32_WCE < 0x500 && ( defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP) )
|
||||
#pragma comment(lib, "ccrtrtti.lib")
|
||||
#ifdef _X86_
|
||||
#if defined(_DEBUG)
|
||||
#pragma comment(lib, "libcmtx86d.lib")
|
||||
#else
|
||||
#pragma comment(lib, "libcmtx86.lib")
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <altcecrt.h>
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
113
libs/libzrtp/test/zrtphash_test.c
Normal file
113
libs/libzrtp/test/zrtphash_test.c
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* libZRTP SDK library, implements the ZRTP secure VoIP protocol.
|
||||
* Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
|
||||
* Contact: http://philzimmermann.com
|
||||
* For licensing and other legal details, see the file zrtp_legal.c.
|
||||
*
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#include "engine_helpers.c"
|
||||
|
||||
static void setup() {
|
||||
zrtp_status_t s;
|
||||
|
||||
zrtp_test_endpoint_cfg_t endpoint_cfg;
|
||||
zrtp_test_endpoint_config_defaults(&endpoint_cfg);
|
||||
|
||||
s = zrtp_test_endpoint_create(&endpoint_cfg, "Alice", &g_alice);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice);
|
||||
|
||||
s = zrtp_test_endpoint_create(&endpoint_cfg, "Bob", &g_bob);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob);
|
||||
}
|
||||
|
||||
static void teardown() {
|
||||
zrtp_test_endpoint_destroy(g_alice);
|
||||
zrtp_test_endpoint_destroy(g_bob);
|
||||
}
|
||||
|
||||
|
||||
static void zrtp_hash_export_import_sunny_test() {
|
||||
zrtp_status_t s;
|
||||
char alice_zrtp_hash[ZRTP_SIGN_ZRTP_HASH_LENGTH];
|
||||
char bob_zrtp_hash[ZRTP_SIGN_ZRTP_HASH_LENGTH];
|
||||
zrtp_stream_t *alice_zrtp_stream, *bob_zrtp_stream;
|
||||
|
||||
/* Create two test sessions, one for Alice and one for Bob and link them into test secure channel */
|
||||
prepare_alice_bob();
|
||||
|
||||
alice_zrtp_stream = zrtp_stream_for_test_stream(zrtp_test_session_get_stream_by_idx(g_alice_sid, 0));
|
||||
bob_zrtp_stream = zrtp_stream_for_test_stream(zrtp_test_session_get_stream_by_idx(g_bob_sid, 0));
|
||||
assert_non_null(alice_zrtp_stream); assert_non_null(bob_zrtp_stream);
|
||||
|
||||
/* Take Alice's hash and give it to Bob */
|
||||
s = zrtp_signaling_hash_get(alice_zrtp_stream, alice_zrtp_hash, sizeof(alice_zrtp_hash));
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
s = zrtp_signaling_hash_set(bob_zrtp_stream, alice_zrtp_hash, ZRTP_SIGN_ZRTP_HASH_LENGTH);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
/* Take Bob's hash and give it to Alice */
|
||||
s = zrtp_signaling_hash_get(bob_zrtp_stream, bob_zrtp_hash, sizeof(bob_zrtp_hash));
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
s = zrtp_signaling_hash_set(alice_zrtp_stream, bob_zrtp_hash, ZRTP_SIGN_ZRTP_HASH_LENGTH);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
/* Start and wait for Secure */
|
||||
start_alice_bob_and_wait4secure();
|
||||
|
||||
/* Check if ZRTP_EVENT_WRONG_SIGNALING_HASH was not triggered for any of test endpoints */
|
||||
assert_false(zrtp_stream_did_event_receive(zrtp_test_session_get_stream_by_idx(g_alice_sid, 0),
|
||||
ZRTP_EVENT_WRONG_SIGNALING_HASH));
|
||||
|
||||
assert_false(zrtp_stream_did_event_receive(zrtp_test_session_get_stream_by_idx(g_bob_sid, 0),
|
||||
ZRTP_EVENT_WRONG_SIGNALING_HASH));
|
||||
|
||||
/* Release test setup */
|
||||
release_alice_bob();
|
||||
}
|
||||
|
||||
static void zrtp_hash_import_wrong_test() {
|
||||
zrtp_status_t s;
|
||||
char wrong_alice_zrtp_hash[ZRTP_SIGN_ZRTP_HASH_LENGTH];
|
||||
zrtp_stream_t *bob_zrtp_stream;
|
||||
|
||||
/* Create two test sessions, one for Alice and one for Bob and link them into test secure channel */
|
||||
prepare_alice_bob();
|
||||
|
||||
bob_zrtp_stream = zrtp_stream_for_test_stream(zrtp_test_session_get_stream_by_idx(g_bob_sid, 0));
|
||||
assert_non_null(bob_zrtp_stream);
|
||||
|
||||
/* Let's provide wrong hash to bob */
|
||||
zrtp_memset(wrong_alice_zrtp_hash, 6, ZRTP_SIGN_ZRTP_HASH_LENGTH);
|
||||
|
||||
s = zrtp_signaling_hash_set(bob_zrtp_stream, wrong_alice_zrtp_hash, ZRTP_SIGN_ZRTP_HASH_LENGTH);
|
||||
assert_int_equal(zrtp_status_ok, s);
|
||||
|
||||
/* Start and wait for Secure */
|
||||
start_alice_bob_and_wait4secure();
|
||||
|
||||
/* Check if Alice don't receive ZRTP_EVENT_WRONG_SIGNALING_HASH, but Bob should get one */
|
||||
assert_false(zrtp_stream_did_event_receive(zrtp_test_session_get_stream_by_idx(g_alice_sid, 0),
|
||||
ZRTP_EVENT_WRONG_SIGNALING_HASH));
|
||||
|
||||
assert_true(zrtp_stream_did_event_receive(zrtp_test_session_get_stream_by_idx(g_bob_sid, 0),
|
||||
ZRTP_EVENT_WRONG_SIGNALING_HASH));
|
||||
|
||||
/* Release test setup */
|
||||
release_alice_bob();
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
const UnitTest tests[] = {
|
||||
unit_test_setup_teardown(zrtp_hash_export_import_sunny_test, setup, teardown),
|
||||
unit_test_setup_teardown(zrtp_hash_import_wrong_test, setup, teardown),
|
||||
};
|
||||
|
||||
return run_tests(tests);
|
||||
}
|
5
libs/libzrtp/third_party/bnlib/.gitignore
vendored
5
libs/libzrtp/third_party/bnlib/.gitignore
vendored
@ -1,3 +1,8 @@
|
||||
# -*- mode:conf -*-
|
||||
/*.a
|
||||
/*.o
|
||||
/Makefile
|
||||
/autom4te.cache/*
|
||||
/bnconfig.h
|
||||
/config.*
|
||||
/configure
|
||||
|
Loading…
x
Reference in New Issue
Block a user