├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── NEWS ├── README ├── acinclude.m4 ├── bootstrap.sh ├── configure.in ├── create_docs.sh ├── create_pack.pl ├── doc ├── Doxyfile.in └── manuals │ ├── changelog.dox │ ├── howto.dox │ ├── main.dox │ └── rng.dox ├── include ├── zrtp.h ├── zrtp_b64_decode.h ├── zrtp_b64_encode.h ├── zrtp_base.h ├── zrtp_cache.h ├── zrtp_cache_db.h ├── zrtp_cache_db_backend.h ├── zrtp_cache_file.h ├── zrtp_config.h ├── zrtp_config_android.h ├── zrtp_config_symbian.h ├── zrtp_config_user.h ├── zrtp_config_win.h ├── zrtp_crypto.h ├── zrtp_ec.h ├── zrtp_engine.h ├── zrtp_error.h ├── zrtp_iface.h ├── zrtp_iface_scheduler.h ├── zrtp_iface_system.h ├── zrtp_legal.h ├── zrtp_list.h ├── zrtp_log.h ├── zrtp_pbx.h ├── zrtp_protocol.h ├── zrtp_sdes.h ├── zrtp_srtp.h ├── zrtp_srtp_builtin.h ├── zrtp_string.h ├── zrtp_types.h └── zrtp_version.h ├── projects ├── android │ └── jni │ │ └── Android.mk ├── symbian │ ├── DelayRuner.cpp │ ├── DelayRuner.h │ ├── bld.bat │ ├── bld.inf │ ├── bldgcce.bat │ ├── libzrtp.mmp │ └── zrtp_iface_symb.cpp ├── win │ ├── libzrtp.2010.vcxproj │ ├── libzrtp.2010.vcxproj.filters │ ├── libzrtp.sln │ ├── libzrtp.vcproj │ ├── libzrtp.x32.vcxproj │ ├── libzrtp.x32.vcxproj.filters │ ├── libzrtp.x32.vcxproj.user │ ├── libzrtp.x64.vcxproj │ ├── libzrtp.x64.vcxproj.filters │ ├── libzrtp.x64.vcxproj.user │ ├── libzrtp_not_ec.vcproj │ └── libzrtp_test.vcproj ├── win_ce │ ├── libzrtp_test_wince.vcproj │ ├── libzrtp_wince.sln │ ├── libzrtp_wince.vcproj │ └── libzrtp_wince_not_ec.vcproj ├── win_kernel │ ├── MAKEFILE.WIN32 │ ├── MAKEFILE.WIN64 │ ├── MAKEFILE_NOT_EC.WIN32 │ └── MAKEFILE_NOT_EC.WIN64 └── xcode │ └── libzrtp.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ └── contents.xcworkspacedata ├── src ├── zrtp.c ├── zrtp_b64_decode.c ├── zrtp_b64_encode.c ├── zrtp_cache.c ├── zrtp_cache_db.c ├── zrtp_cache_file.c ├── zrtp_cache_sqlite_backend.c ├── zrtp_crc.c ├── zrtp_crypto_aes.c ├── zrtp_crypto_atl.c ├── zrtp_crypto_ec.c ├── zrtp_crypto_ecdh.c ├── zrtp_crypto_ecdsa.c ├── zrtp_crypto_hash.c ├── zrtp_crypto_pk.c ├── zrtp_crypto_sas.c ├── zrtp_datatypes.c ├── zrtp_engine.c ├── zrtp_engine_driven.c ├── zrtp_iface_scheduler.c ├── zrtp_iface_sys.c ├── zrtp_initiator.c ├── zrtp_legal.c ├── zrtp_list.c ├── zrtp_log.c ├── zrtp_pbx.c ├── zrtp_protocol.c ├── zrtp_responder.c ├── zrtp_rng.c ├── zrtp_sdes.c ├── zrtp_srtp_builtin.c ├── zrtp_srtp_dm.c ├── zrtp_string.c ├── zrtp_utils.c └── zrtp_utils_proto.c ├── test ├── cache_test.c ├── cipher_test.c ├── cmockery │ ├── cmockery.c │ └── cmockery.h ├── dh_test.c ├── dk_test.c ├── ecdh_test.c ├── engine_helpers.c ├── enroll_test_helpers.c ├── enrollment_test.c ├── go_secure_test.c ├── hash_test.c ├── minor_bugs_test.c ├── queue.c ├── queue.h ├── sasrelay_test.c ├── sdes_test.c ├── srtp_replay_test.c ├── test_engine.c ├── test_engine.h └── zrtphash_test.c └── third_party ├── bgaes ├── aes.h ├── aes_modes.c ├── aescrypt.c ├── aeskey.c ├── aesopt.h ├── aestab.c ├── aestab.h ├── bg2zrtp.h ├── brg_types.h ├── sha1.c ├── sha1.h ├── sha2.c └── sha2.h └── bnlib ├── .gitignore ├── CHANGES ├── Makefile.in ├── README.bn ├── README.bntest ├── bignum-ARM ├── README-small-memory ├── bntest16.c ├── config.h ├── cputime.h ├── kludge.h ├── lbn.h ├── lbn16.c ├── lbn16.h ├── lbnarm.h ├── lbnarm.s ├── lbnmem.c ├── lbnmem.h ├── sha256_arm.c └── sha256_core.s ├── bn.c ├── bn.doc ├── bn.h ├── bn00.c ├── bn16.c ├── bn16.h ├── bn32.c ├── bn32.h ├── bn64.c ├── bn64.h ├── bn68000.c ├── bn8086.c ├── bnconfig.hin ├── bnconfig.win ├── bninit16.c ├── bninit32.c ├── bninit64.c ├── bnintern.doc ├── bnprint.c ├── bnprint.h ├── bnsize00.h ├── bntest00.c ├── bntest16.c ├── bntest32.c ├── bntest64.c ├── bootstrap.sh ├── cfg ├── cfg.debug ├── configure.in ├── cputime.h ├── germain.c ├── germain.h ├── germtest.c ├── jacobi.c ├── jacobi.h ├── kludge.h ├── lbn.h ├── lbn00.c ├── lbn16.c ├── lbn16.h ├── lbn32.c ├── lbn32.h ├── lbn64.c ├── lbn64.h ├── lbn68000.c ├── lbn68000.h ├── lbn68020.c ├── lbn68020.h ├── lbn68360.s ├── lbn80386.asm ├── lbn80386.h ├── lbn80386.s ├── lbn8086.asm ├── lbn8086.h ├── lbn960jx.h ├── lbn960jx.s ├── lbnalpha.h ├── lbnalpha.s ├── lbnmem.c ├── lbnmem.h ├── lbnppc.c ├── lbnppc.h ├── legal.c ├── legal.h ├── ppcasm.h ├── prime.c ├── prime.h ├── sieve.c ├── sieve.h ├── sizetest.c └── test ├── README.dhtest ├── README.dsatest ├── README.rsatest ├── dhtest.c ├── dsatest.c ├── first.h ├── kb.h ├── kbmsdos.c ├── kbunix.c ├── keygen.c ├── keygen.h ├── keys.c ├── keys.h ├── kludge.h ├── md5.c ├── md5.h ├── noise.c ├── noise.h ├── posix.h ├── primes.doc ├── primetest.c ├── pt.c ├── random.c ├── random.h ├── randpool.c ├── randpool.h ├── randtest.c ├── rsaglue.c ├── rsaglue.h ├── rsatest.c ├── sha.c ├── sha.h ├── types.h ├── userio.h └── usuals.h /.gitignore: -------------------------------------------------------------------------------- 1 | # -*- mode:conf -*- 2 | /*~ 3 | /*.a 4 | /*.log 5 | /*.status 6 | /*.dat 7 | /*.o 8 | /.cproject 9 | /.deps 10 | /.project 11 | /.stamp-doc 12 | /Makefile 13 | /Makefile.in 14 | /_configs.sed 15 | /aclocal.m4 16 | /autom4te.cache/* 17 | /cache_test 18 | /config.* 19 | /config/* 20 | /configure 21 | /doc/Doxyfile 22 | /doc/out 23 | /include/zrtp_config_unix.h 24 | !/build/Makefile.am 25 | !/build/test/Makefile.am 26 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 3 | # Contact: http://philzimmermann.com 4 | # For licensing and other legal details, see the file zrtp_legal.c. 5 | # 6 | # Viktor Krikun 7 | 8 | Created by Phil Zimmermann. 9 | 10 | Developers: 11 | Viktor Krikun 12 | Nikolay Popok 13 | Vitaly Rozhkov 14 | Andrey Rozinko 15 | Bryce Wilcox-O'Hearn 16 | 17 | Thanks to: 18 | Alan Johnston 19 | Jon Callas 20 | Hal Finney 21 | Colin Plumb 22 | Sagar Pai 23 | Werner Dittmann 24 | Travis Cross 25 | L. Amber Wilcox-O'Hearn 26 | Ariel Boston 27 | Donovan Preston 28 | 29 | Portions of this software are available under open source licenses from other authors. 30 | Notably, Brian Gladman's AES implementation, and David McGrew's libSRTP package. 31 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | */ 7 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/traviscross/libzrtp/4cb5110147d2bb7e0466eec8ec838d8372ef54c9/NEWS -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | # 2 | # libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | # Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | # Contact: http://philzimmermann.com 5 | # For licensing and other legal details, see the file zrtp_legal.c. 6 | # 7 | 8 | - Check HTML Documentation ./doc 9 | - Visit the Zfone Project Home Page http://zfoneproject.com/ 10 | - Report bugs via the Zfone Bugs Page http://zfoneproject.com/bugs.html 11 | -------------------------------------------------------------------------------- /acinclude.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([AX_PREFIX_CONFIG_H],[dnl 2 | AC_BEFORE([AC_CONFIG_HEADERS],[$0])dnl 3 | AC_CONFIG_COMMANDS([ifelse($1,,$PACKAGE-config.h,$1)],[dnl 4 | AS_VAR_PUSHDEF([_OUT],[ac_prefix_conf_OUT])dnl 5 | AS_VAR_PUSHDEF([_DEF],[ac_prefix_conf_DEF])dnl 6 | AS_VAR_PUSHDEF([_PKG],[ac_prefix_conf_PKG])dnl 7 | AS_VAR_PUSHDEF([_LOW],[ac_prefix_conf_LOW])dnl 8 | AS_VAR_PUSHDEF([_UPP],[ac_prefix_conf_UPP])dnl 9 | AS_VAR_PUSHDEF([_INP],[ac_prefix_conf_INP])dnl 10 | m4_pushdef([_script],[conftest.prefix])dnl 11 | m4_pushdef([_symbol],[m4_cr_Letters[]m4_cr_digits[]_])dnl 12 | _OUT=`echo ifelse($1, , $PACKAGE-config.h, $1)` 13 | _DEF=`echo _$_OUT | sed -e "y:m4_cr_letters:m4_cr_LETTERS[]:" -e "s/@<:@^m4_cr_Letters@:>@/_/g"` 14 | _PKG=`echo ifelse($2, , $PACKAGE, $2)` 15 | _LOW=`echo _$_PKG | sed -e "y:m4_cr_LETTERS-:m4_cr_letters[]_:"` 16 | _UPP=`echo $_PKG | sed -e "y:m4_cr_letters-:m4_cr_LETTERS[]_:" -e "/^@<:@m4_cr_digits@:>@/s/^/_/"` 17 | _INP=`echo "ifelse($3,,,$3)" | sed -e 's/ *//'` 18 | if test ".$_INP" = "."; then 19 | for ac_file in : $CONFIG_HEADERS; do test "_$ac_file" = _: && continue 20 | case "$ac_file" in 21 | *.h) _INP=$ac_file ;; 22 | *) 23 | esac 24 | test ".$_INP" != "." && break 25 | done 26 | fi 27 | if test ".$_INP" = "."; then 28 | case "$_OUT" in 29 | */*) _INP=`basename "$_OUT"` 30 | ;; 31 | *-*) _INP=`echo "$_OUT" | sed -e "s/@<:@_symbol@:>@*-//"` 32 | ;; 33 | *) _INP=config.h 34 | ;; 35 | esac 36 | fi 37 | if test -z "$_PKG" ; then 38 | AC_MSG_ERROR([no prefix for _PREFIX_PKG_CONFIG_H]) 39 | else 40 | if test ! -f "$_INP" ; then if test -f "$srcdir/$_INP" ; then 41 | _INP="$srcdir/$_INP" 42 | fi fi 43 | AC_MSG_NOTICE(creating $_OUT - prefix $_UPP for $_INP defines) 44 | if test -f $_INP ; then 45 | echo "s/^@%:@undef *\\(@<:@m4_cr_LETTERS[]_@:>@\\)/@%:@undef $_UPP""_\\1/" > _script 46 | echo "s/^@%:@undef *\\(@<:@m4_cr_letters@:>@\\)/@%:@undef $_LOW""_\\1/" >> _script 47 | echo "s/^@%:@def[]ine *\\(@<:@m4_cr_LETTERS[]_@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_UPP""_\\1 \\" >> _script 48 | echo "@%:@def[]ine $_UPP""_\\1 \\2 \\" >> _script 49 | echo "@%:@endif/" >>_script 50 | echo "s/^@%:@def[]ine *\\(@<:@m4_cr_letters@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_LOW""_\\1 \\" >> _script 51 | echo "@%:@define $_LOW""_\\1 \\2 \\" >> _script 52 | echo "@%:@endif/" >> _script 53 | # now executing _script on _DEF input to create _OUT output file 54 | echo "@%:@ifndef $_DEF" >$tmp/pconfig.h 55 | echo "@%:@def[]ine $_DEF 1" >>$tmp/pconfig.h 56 | echo ' ' >>$tmp/pconfig.h 57 | echo /'*' $_OUT. Generated automatically at end of configure. '*'/ >>$tmp/pconfig.h 58 | 59 | sed -f _script $_INP >>$tmp/pconfig.h 60 | echo ' ' >>$tmp/pconfig.h 61 | echo '/* once:' $_DEF '*/' >>$tmp/pconfig.h 62 | echo "@%:@endif" >>$tmp/pconfig.h 63 | if cmp -s $_OUT $tmp/pconfig.h 2>/dev/null; then 64 | AC_MSG_NOTICE([$_OUT is unchanged]) 65 | else 66 | ac_dir=`AS_DIRNAME(["$_OUT"])` 67 | AS_MKDIR_P(["$ac_dir"]) 68 | rm -f "$_OUT" 69 | mv $tmp/pconfig.h "$_OUT" 70 | fi 71 | cp _script _configs.sed 72 | else 73 | AC_MSG_ERROR([input file $_INP does not exist - skip generating $_OUT]) 74 | fi 75 | rm -f conftest.* 76 | fi 77 | m4_popdef([_symbol])dnl 78 | m4_popdef([_script])dnl 79 | AS_VAR_POPDEF([_INP])dnl 80 | AS_VAR_POPDEF([_UPP])dnl 81 | AS_VAR_POPDEF([_LOW])dnl 82 | AS_VAR_POPDEF([_PKG])dnl 83 | AS_VAR_POPDEF([_DEF])dnl 84 | AS_VAR_POPDEF([_OUT])dnl 85 | ],[PACKAGE="$PACKAGE"])]) 86 | 87 | dnl implementation note: a bug report (31.5.2005) from Marten Svantesson points 88 | dnl out a problem where `echo "\1"` results in a Control-A. The unix standard 89 | dnl http://www.opengroup.org/onlinepubs/000095399/utilities/echo.html 90 | dnl defines all backslash-sequences to be inherently non-portable asking 91 | dnl for replacement mit printf. Some old systems had problems with that 92 | dnl one either. However, the latest libtool (!) release does export an $ECHO 93 | dnl (and $echo) that does the right thing - just one question is left: what 94 | dnl was the first version to have it? Is it greater 2.58 ? 95 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | reconf () { 4 | aclocal 5 | mkdir -p config 6 | libtoolize --copy --automake 7 | autoconf 8 | autoheader 9 | automake --no-force --add-missing --copy 10 | } 11 | 12 | (cd third_party/bnlib && ./bootstrap.sh) 13 | reconf 14 | 15 | -------------------------------------------------------------------------------- /configure.in: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2011 Philip R. Zimmermann. All rights reserved. 3 | # Contact: http://philzimmermann.com 4 | # For licensing and other legal details, see the file zrtp_legal.c. 5 | # 6 | # Viktor Krikun 7 | # 8 | 9 | AC_INIT([libzrtp], [1.2.0]) 10 | 11 | AC_CONFIG_AUX_DIR(config) 12 | AC_CONFIG_HEADER(config/config.h) 13 | 14 | # Checks for target OS 15 | AC_CANONICAL_TARGET 16 | 17 | case $target_os in 18 | aix*) ;; 19 | *mingw* | *cygw* | *win32* | *w32* ) 20 | echo "------- START libzrtp configuration for Windows platform ------------" 21 | ;; 22 | *darwin*) 23 | echo "------- START libzrtp configuration for Darwin platform ------------" 24 | ;; 25 | *freebsd2* | *freebsd* | *netbsd* | *openbsd* | *osf[12]*) 26 | echo "------- START libzrtp configuration for BSD platform ------------" 27 | ;; 28 | hpux* | irix* | linuxaout* | linux* | osf* | solaris2* | sunos4*) 29 | echo "------- START libzrtp configuration for Linux platform ------------" 30 | ;; 31 | esac 32 | 33 | 34 | AM_INIT_AUTOMAKE 35 | AX_PREFIX_CONFIG_H(include/zrtp_config_unix.h,ZRTP,config/config.h) 36 | 37 | CFLAGS="$CFLAGS -std=c99 -O2 -g3 -Wall -Wextra -Wno-unused-parameter -fno-strict-aliasing -fPIC -DZRTP_AUTOMAKE=1" 38 | 39 | # Configuring external libraries 40 | echo "========================= configuring bnlib ==============================" 41 | cd third_party/bnlib 42 | ./configure CFLAGS="$CFLAGS" 43 | cd ../.. 44 | echo "================================ done ===================================" 45 | 46 | # Checks for programs. 47 | AC_PROG_CC 48 | AC_PROG_CXX 49 | AC_PROG_RANLIB 50 | 51 | # Checks for header files. 52 | AC_HEADER_STDC 53 | AC_CHECK_HEADERS([linux/version.h endian.h]) 54 | AC_CHECK_HEADERS([errno.h]) 55 | AC_CHECK_HEADERS([asm/types.h]) 56 | AC_CHECK_HEADERS([stdlib.h stdint.h stdarg.h]) 57 | AC_CHECK_HEADERS([string.h strings.h]) 58 | AC_CHECK_HEADERS([stdio.h unistd.h]) 59 | AC_CHECK_HEADERS([inttypes.h sys/inttypes.h sys/types.h machine/types.h]) 60 | AC_CHECK_HEADERS([pthread.h semaphore.h sys/time.h fcntl.h]) 61 | 62 | AC_CHECK_TYPES([int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,uint64_t,int64_t]) 63 | 64 | # Checks for typedefs, structures, and compiler characteristics. 65 | AC_C_CONST 66 | 67 | # Checks for library functions. 68 | AC_FUNC_MALLOC 69 | AC_CHECK_FUNCS([memset memcpy malloc free]) 70 | AC_CHECK_FUNCS([usleep]) 71 | AC_CHECK_FUNCS([fopen fread]) 72 | AC_CHECK_FUNCS([pthread_mutex_lock pthread_mutex_unlock pthread_mutex_init pthread_mutex_destroy]) 73 | AC_CHECK_FUNCS([pthread_attr_init pthread_attr_setdetachstate pthread_create]) 74 | AC_CHECK_FUNCS([sem_wait sem_trywait sem_post sem_unlink sem_destroy sem_open sem_init]) 75 | 76 | AC_CHECK_LIB([pthread], [main], [LIBS="-lpthread $LIBS"], [echo " Couldn't find library pthread";]) 77 | 78 | # Other 79 | AC_DEFINE(PRAGMA_PACK_PUSH,[#pragma pack(push, 1)],[Define pragma pack(push) for your platform]) 80 | AC_DEFINE(PRAGMA_PACK_POP,[#pragma pack(pop)],[Define pragma pack(pop) for your platform]) 81 | AC_DEFINE(INLINE,[static inline],[Define inline construction for your platform]) 82 | 83 | # Check if SQLite database cache shall be used. 84 | AC_ARG_WITH([sqlite], 85 | [AS_HELP_STRING([--with-sqlite], [enable support for SQLite based cache])], 86 | [], 87 | [with_sqlite=no]) 88 | AS_IF([test "x$with_sqlite" != xno], 89 | [AC_CHECK_LIB([sqlite3], [sqlite3_open_v2], 90 | [AC_DEFINE([HAVE_SQLITE], [1], [Define if you have libsqlite3]) 91 | AC_CHECK_HEADERS([sqlite3.h], [], AC_MSG_ERROR([sqlite3 headers not found.])) 92 | LIBS="-lsqlite3 $LIBS" 93 | ], 94 | [AC_MSG_FAILURE([--with-sqlite was given, but tests for SQLite failed])]) 95 | ]) 96 | AM_CONDITIONAL(ZRTP_WITH_SQLITE, [test "x$with_sqlite" = "xyes"]) 97 | 98 | # 99 | # Documentation 100 | # 101 | AM_CONDITIONAL([HAVE_DOXYGEN], [false]) 102 | AC_CHECK_PROGS([DOXYGEN], [doxygen]) 103 | if test -z "$DOXYGEN"; then 104 | AC_MSG_WARN([Doxygen not found - continuing without Doxygen support]) 105 | else 106 | AM_CONDITIONAL([HAVE_DOXYGEN], [true]) 107 | AC_CONFIG_FILES([doc/Doxyfile]) 108 | fi 109 | 110 | # 111 | # Generate Makefiles 112 | AC_OUTPUT([Makefile]) 113 | -------------------------------------------------------------------------------- /create_docs.sh: -------------------------------------------------------------------------------- 1 | cd ../../doc 2 | rm -f docs.tar.gz 3 | rm -rf libzrtp-doc 4 | echo "=================> start doxygen." 5 | doxygen > /dev/null 2>&1 6 | mkdir libzrtp-doc 7 | cp -Rf ./out/html/* ./libzrtp-doc 8 | tar -zcvf ./libzrtp-doc.tar.gz ./libzrtp-doc >> /dev/null 9 | rm -rf libzrtp-doc 10 | -------------------------------------------------------------------------------- /doc/manuals/main.dox: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 3 | # Contact: http://philzimmermann.com 4 | # For licensing and other legal details, see the file zrtp_legal.c. 5 | # 6 | # Viktor Krykun 7 | 8 | /** 9 | \mainpage ZRTP VoIP security 10 | 11 | **************************************************************************************************** 12 | \section intro Intro 13 | **************************************************************************************************** 14 | 15 | ZRTP Protocol finally goes RFC and we going to stabilize SDK as well. Libzrtp series 0.9X builds 16 | will contain bug-fixes, performance and stability improvements only. 17 | 18 | So, please, be a patient with new API changes. We hope you will find them useful. 19 | 20 | **************************************************************************************************** 21 | \section aboutdoc About this Documentation 22 | **************************************************************************************************** 23 | 24 | Libzrtp, since v0.80 includes new, documentation. We have updated "How to Get Up and Running Quickly with libZRTP" and Public API documentation. 25 | 26 | We working on new "Libzrtp Developers Guide" which will give more detail information about ZRTP protocol and libzrtp architecture. This document will be available in next versions of libzrtp. But even now, libzrtp contains enough documentation to start using it comfortable. 27 | 28 | \note 29 | libzrtp private API may have outdated information from previous version (links like this: \ref XXX). We working hard on that part of the documentation and it will be published in next versions of libzrtp. 30 | 31 | **************************************************************************************************** 32 | \section zrtp Libzrtp Documents 33 | **************************************************************************************************** 34 | -# \ref changelog 35 | -# \ref howto 36 | -# \ref rng 37 | 38 | */ 39 | -------------------------------------------------------------------------------- /include/zrtp_b64_decode.h: -------------------------------------------------------------------------------- 1 | /* 2 | cdecode.h - c header for a base64 decoding algorithm 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifndef BASE64_CDECODE_H 9 | #define BASE64_CDECODE_H 10 | 11 | #include 12 | 13 | typedef enum 14 | { 15 | step_a, step_b, step_c, step_d 16 | } base64_decodestep; 17 | 18 | typedef struct 19 | { 20 | base64_decodestep step; 21 | char plainchar; 22 | } base64_decodestate; 23 | 24 | void base64_init_decodestate(base64_decodestate* state_in); 25 | 26 | int base64_decode_value(char value_in); 27 | 28 | int base64_decode_block(const char* code_in, const int length_in, uint8_t *plaintext_out, base64_decodestate* state_in); 29 | 30 | #endif /* BASE64_CDECODE_H */ 31 | -------------------------------------------------------------------------------- /include/zrtp_b64_encode.h: -------------------------------------------------------------------------------- 1 | /* 2 | cencode.h - c header for a base64 encoding algorithm 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifndef BASE64_CENCODE_H 9 | #define BASE64_CENCODE_H 10 | 11 | #include 12 | 13 | typedef enum 14 | { 15 | step_A, step_B, step_C 16 | } base64_encodestep; 17 | 18 | typedef struct 19 | { 20 | base64_encodestep step; 21 | char result; 22 | int stepcount; 23 | int lineLength; 24 | } base64_encodestate; 25 | 26 | void base64_init_encodestate(base64_encodestate* state_in, int lineLength); 27 | 28 | char base64_encode_value(const int8_t value_in); 29 | 30 | int base64_encode_block(const uint8_t *plaintext_in, int length_in, char* code_out, base64_encodestate* state_in); 31 | 32 | int base64_encode_blockend(char *code_out, base64_encodestate* state_in); 33 | 34 | #endif /* BASE64_CENCODE_H */ 35 | -------------------------------------------------------------------------------- /include/zrtp_cache_db.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | */ 4 | 5 | #ifndef _ZRTP_CACHE_DB_H_ 6 | #define _ZRTP_CACHE_DB_H_ 7 | 8 | #if defined(__cplusplus) 9 | extern "C" 10 | { 11 | #endif 12 | 13 | /** 14 | * Definitions and structures for ZRTP database cache implementations. 15 | * 16 | * The figure below depicts the overall structure of the ZRTP DB cache implmentation. 17 | * 18 | * 19 | *@verbatim 20 | * +--------------------------------+ 21 | * | zrtp_cache.h (zrtp_cache_op_t) | 22 | * | zrtp_cache.c | 23 | * +-+------------------------------+ 24 | * | 25 | * | 26 | * | 27 | * |Include 28 | * | 29 | * | Defines config for Defines interface to access 30 | * | DB caches DB caches (dbCacheOps_t) 31 | * | +-----------------+ +-------------------------+ 32 | * | | zrtp_cache_db.h | | zrtp_cache_db_backend.h | 33 | * | +------+----------+ +-----+---+----+----------+ 34 | * | | | | | 35 | * | | | | | 36 | * | |Include and use | | | 37 | * | | +----------------+ | | 38 | * | | | | | 39 | * | +------+------+---+ | | Include and 40 | * +---+ zrtp_cache_db.c | | | implement 41 | * +-----+-----+-----+ | | 42 | * | | +---------+-------------------+ 43 | * | +------------+ zrtp_cache_sqlite_backend.c | 44 | * | Call +-----------------------------+ 45 | * | | 46 | * | | 47 | * | +--------------+--------------+ 48 | * +------------------+ zrtp_cache_others_backend.c | 49 | * Call +-----------------------------+ 50 | * DB specific backends implement 51 | * the acccess interface 52 | *@endverbatim 53 | * 54 | * The @c zrtp_cache_db module implments the standard @c libzrtp cache plugin 55 | * interface which is defined in @c zrtp_cache.h. The @c zrtp_cache_db.c file 56 | * includes the @c zrtp_cache_backend.h that defines a record structure to 57 | * manage cache data for the remote ZRTP identifiers (ZID). 58 | * 59 | * The database specific backend implementations take this ZID record to store 60 | * or retrieve data to/from the database. The database backend implementation 61 | * is independent of the @c zrtp_cache_db module. 62 | * 63 | */ 64 | 65 | 66 | /* The following lines are a slightly modified copy of @c zrtp_cache_file.h and 67 | * define the structure, public functions, and names for ZRTP database cache 68 | * implementations. 69 | * 70 | */ 71 | #undef ZRTP_DEF_CACHE_VERSION_STR 72 | #define ZRTP_DEF_CACHE_VERSION_STR "libZRTP db cache version=" 73 | 74 | #undef ZRTP_DEF_CACHE_VERSION_VAL 75 | #define ZRTP_DEF_CACHE_VERSION_VAL "1.0" 76 | 77 | #define ZRTP_CACHE_DB_DEF_PATH "./zrtp_def_cache_db.dat" 78 | 79 | #define ZRTP_CACHE_STRLEN 256 80 | 81 | /* Forward declaration - the structure is local to zrtp_cache_db.c */ 82 | typedef struct zrtp_cache_db_t zrtp_cache_db_t; 83 | 84 | typedef struct { 85 | /** 86 | * Path to ZRTP cache file. If file doesn't exist it will be created. 87 | * Default is ZRTP_CACHE_FILE_DEF_PATH. 88 | */ 89 | char cache_path[ZRTP_CACHE_STRLEN]; 90 | 91 | /** 92 | * @brief Flush the cache automatically 93 | * Set to 1 if you want libzrtp to flush the cache to the persistent storage 94 | * right after it was modified. If cache_auto_store is 0, libzrtp will flush 95 | * the cache on going down only and the app is responsible for storing the 96 | * cache in unexpected situations. Enabled by default. 97 | * 98 | * @sa zrtp_def_cache_store() 99 | */ 100 | unsigned cache_auto_store; 101 | } zrtp_cache_db_config_t; 102 | 103 | zrtp_status_t zrtp_cache_db_create(zrtp_stringn_t *local_zid, 104 | zrtp_cache_db_config_t *config, 105 | zrtp_cache_db_t **cache); 106 | 107 | zrtp_status_t zrtp_cache_db_destroy(zrtp_cache_t *cache); 108 | 109 | 110 | #if defined(__cplusplus) 111 | } 112 | #endif 113 | #endif /* _ZRTP_CACHE_DB_H_ */ 114 | -------------------------------------------------------------------------------- /include/zrtp_cache_file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | /** 11 | * \file zrtp_cache_file.h 12 | * \brief file-based zrtp cache implementation 13 | */ 14 | 15 | #ifndef __ZRTP_CACHE_FILE_H__ 16 | #define __ZRTP_CACHE_FILE_H__ 17 | 18 | #include "zrtp_config.h" 19 | #include "zrtp_base.h" 20 | #include "zrtp_string.h" 21 | #include "zrtp_error.h" 22 | 23 | #include "zrtp_cache.h" 24 | 25 | #if defined(__cplusplus) 26 | extern "C" 27 | { 28 | #endif 29 | 30 | #define ZRTP_DEF_CACHE_VERSION_STR "libZRTP cache version=" 31 | #define ZRTP_DEF_CACHE_VERSION_VAL "1.0" 32 | 33 | #define ZRTP_CACHE_FILE_DEF_PATH "./zrtp_def_cache_path.dat" 34 | 35 | #define ZRTP_CACHE_STRLEN 256 36 | 37 | typedef struct zrtp_cache_file_t zrtp_cache_file_t; 38 | 39 | typedef struct { 40 | /** 41 | * Path to ZRTP cache file. If file doesn't exist it will be created. 42 | * Default is ZRTP_CACHE_FILE_DEF_PATH. 43 | */ 44 | char cache_path[256]; 45 | 46 | /** 47 | * @brief Flush the cache automatically 48 | * Set to 1 if you want libzrtp to flush the cache to the persistent storage 49 | * right after it was modified. If cache_autho_store is 0, libzrtp will flush 50 | * the cache on going down only and the app is responsible for storing the 51 | * cache in unexpected situations. Enabled by default. 52 | * 53 | * @sa zrtp_def_cache_store() 54 | */ 55 | unsigned cache_auto_store; 56 | } zrtp_cache_file_config_t; 57 | 58 | zrtp_status_t zrtp_cache_file_create(zrtp_stringn_t *local_zid, 59 | zrtp_cache_file_config_t *config, 60 | zrtp_cache_file_t **cache); 61 | 62 | zrtp_status_t zrtp_cache_file_destroy(zrtp_cache_file_t *cache); 63 | 64 | #if defined(__cplusplus) 65 | } 66 | #endif 67 | 68 | #endif /*__ZRTP_CACHE_FILE_H__*/ 69 | -------------------------------------------------------------------------------- /include/zrtp_config_android.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #ifndef ZRTP_SYMB_CONFIG_H__ 11 | #define ZRTP_SYMB_CONFIG_H__ 12 | 13 | #ifndef ZRTP_HAVE_STDIO_H 14 | # define ZRTP_HAVE_STDIO_H 1 15 | #endif 16 | 17 | #ifndef ZRTP_HAVE_STDARG_H 18 | # define ZRTP_HAVE_STDARG_H 1 19 | #endif 20 | 21 | 22 | #ifndef NO_ASSERT_H 23 | # define NO_ASSERT_H 1 24 | #endif 25 | 26 | #ifndef NO_STDLIB_H 27 | # define NO_STDLIB_H 0 28 | #endif 29 | //#define ZRTP_HAVE_INTTYPES_H 1 30 | #ifndef ZRTP_HAVE_UNISTD_H 31 | # define ZRTP_HAVE_UNISTD_H 1 32 | #endif 33 | 34 | #ifndef ZRTP_HAVE_PTHREAD_H 35 | # define ZRTP_HAVE_PTHREAD_H 1 36 | #endif 37 | 38 | #ifndef ZRTP_HAVE_SEMAPHORE_H 39 | #define ZRTP_HAVE_SEMAPHORE_H 1 40 | #endif 41 | 42 | #ifndef ZRTP_HAVE_ERRNO_H 43 | #define ZRTP_HAVE_ERRNO_H 1 44 | #endif 45 | 46 | #ifndef ZRTP_HAVE_FCNTL_H 47 | #define ZRTP_HAVE_FCNTL_H 1 48 | #endif 49 | 50 | #ifndef ZRTP_HAVE_SYS_TIME_H 51 | # define ZRTP_HAVE_SYS_TIME_H 1 52 | #endif 53 | 54 | 55 | #ifndef ZRTP_HAVE_SYS_TYPES_H 56 | # define ZRTP_HAVE_SYS_TYPES_H 1 57 | #endif 58 | 59 | 60 | #ifndef ZRTP_HAVE_INTTYPES_H 61 | # define ZRTP_HAVE_INTTYPES_H 1 62 | #endif 63 | 64 | #ifndef ZRTP_HAVE_STDINT_H 65 | # define ZRTP_HAVE_STDINT_H 1 66 | #endif 67 | 68 | #ifndef ZRTP_HAVE_LINUX_VERSION_H 69 | # define ZRTP_HAVE_LINUX_VERSION_H 0 70 | #endif 71 | 72 | 73 | // (ZRTP_PLATFORM == ZP_ANDROID) 74 | 75 | 76 | #define ZRTP_HAVE_INT64_T 1 77 | #define ZRTP_HAVE_INT32_T 1 78 | #define ZRTP_HAVE_INT16_T 1 79 | #define ZRTP_HAVE_INT8_T 1 80 | 81 | #define ZRTP_HAVE_UINT64_T 1 82 | #define ZRTP_HAVE_UINT32_T 1 83 | #define ZRTP_HAVE_UINT16_T 1 84 | #define ZRTP_HAVE_UINT8_T 1 85 | 86 | #define ZRTP_BYTE_ORDER ZBO_LITTLE_ENDIAN 87 | 88 | #define SIZEOF_UNSIGNED_LONG 4 89 | #define SIZEOF_UNSIGNED_LONG_LONG 8 90 | 91 | #define ZRTP_INLINE inline 92 | 93 | #define ZRTP_USE_BUILTIN_CACHE 1 94 | #define ZRTP_USE_BUILTIN_SCEHDULER 1 95 | #undef ZRTP_USE_STACK_MINIM 96 | #define ZRTP_USE_STACK_MINIM 1 97 | #define ALIGNMENT_32BIT_REQUIRED 98 | 99 | #endif /* ZRTP_WIN_CONFIG_H__ */ 100 | -------------------------------------------------------------------------------- /include/zrtp_config_symbian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #ifndef ZRTP_SYMB_CONFIG_H__ 11 | #define ZRTP_SYMB_CONFIG_H__ 12 | 13 | 14 | /* 15 | * Used to map system integer types to zrtp integer definitions. 16 | * Define to 1 if you have the header file. 17 | */ 18 | #undef ZRTP_HAVE_INTTYPES_H 19 | 20 | /* 21 | * This header is needed for operations with binary file in deefault realization 22 | * of the secrets' cache. Can be eliminated if default cache isn't used. 23 | * Define to 1 if you have the header file. 24 | */ 25 | #ifndef ZRTP_HAVE_STDIO_H 26 | # define ZRTP_HAVE_STDIO_H 1 27 | #endif 28 | 29 | #ifndef ZRTP_HAVE_STDARG_H 30 | # define ZRTP_HAVE_STDARG_H 1 31 | #endif 32 | 33 | /* 34 | * Used by bnlib, but we don't need this on Symbian platform. 35 | */ 36 | #ifndef NO_ASSERT_H 37 | # define NO_ASSERT_H 1 38 | #endif 39 | 40 | /* 41 | * Used by bnlib. We have stdlib in Symbian platform - set it to 1. 42 | */ 43 | #ifndef NO_STDLIB_H 44 | # define NO_STDLIB_H 0 45 | #endif 46 | 47 | #ifndef ZRTP_HAVE_SYS_TIME_H 48 | # define ZRTP_HAVE_SYS_TIME_H 1 49 | #endif 50 | 51 | 52 | #define ZRTP_HAVE_INT64_T 0 53 | #define ZRTP_HAVE_INT32_T 0 54 | #define ZRTP_HAVE_INT16_T 0 55 | #define ZRTP_HAVE_INT8_T 0 56 | 57 | #define ZRTP_HAVE_UINT64_T 0 58 | #define ZRTP_HAVE_UINT32_T 0 59 | #define ZRTP_HAVE_UINT16_T 0 60 | #define ZRTP_HAVE_UINT8_T 0 61 | 62 | #define ZRTP_BYTE_ORDER ZBO_BIG_ENDIAN 63 | 64 | #define SIZEOF_UNSIGNED_LONG 4 65 | #define SIZEOF_UNSIGNED_LONG_LONG 8 66 | 67 | #define ZRTP_INLINE static __inline 68 | 69 | #endif /* ZRTP_WIN_CONFIG_H__ */ 70 | -------------------------------------------------------------------------------- /include/zrtp_config_win.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #ifndef ZRTP_WIN_CONFIG_H__ 11 | #define ZRTP_WIN_CONFIG_H__ 12 | 13 | #define _CRT_SECURE_NO_WARNINGS 1 14 | #pragma warning(disable: 4068) 15 | 16 | #if !(defined(__BUILDMACHINE__) && __BUILDMACHINE__ == WinDDK) 17 | #include 18 | #endif 19 | 20 | /* 21 | * Used to map system integer types to zrtp integer definitions. 22 | * Define to 1 if you have the header file. 23 | */ 24 | #undef ZRTP_HAVE_INTTYPES_H 25 | 26 | #define ZRTP_HAVE_STRING_H 1 27 | 28 | /* 29 | * This header is needed for operations with binary file in deefault realization 30 | * of the secrets' cache. Can be eliminated if default cache isn't used. 31 | * Define to 1 if you have the header file. 32 | */ 33 | #ifndef ZRTP_HAVE_STDIO_H 34 | # define ZRTP_HAVE_STDIO_H 1 35 | #endif 36 | 37 | #ifndef ZRTP_HAVE_STDARG_H 38 | # define ZRTP_HAVE_STDARG_H 1 39 | #endif 40 | 41 | /* 42 | * Used by bnlib, but we don't need this on Windows platform. 43 | */ 44 | #ifndef NO_ASSERT_H 45 | #define NO_ASSERT_H 1 46 | #endif 47 | 48 | /* 49 | * Used by bnlib. We have stdlib in any Windows platform - set it to 1. 50 | */ 51 | #ifndef NO_STDLIB_H 52 | #define NO_STDLIB_H 0 53 | #endif 54 | 55 | 56 | #define ZRTP_HAVE_INT64_T 0 57 | #define ZRTP_HAVE_INT32_T 0 58 | #define ZRTP_HAVE_INT16_T 0 59 | #define ZRTP_HAVE_INT8_T 0 60 | 61 | #define ZRTP_HAVE_UINT64_T 0 62 | #define ZRTP_HAVE_UINT32_T 0 63 | #define ZRTP_HAVE_UINT16_T 0 64 | #define ZRTP_HAVE_UINT8_T 0 65 | 66 | #define SIZEOF_UNSIGNED_LONG 4 67 | #define SIZEOF_UNSIGNED_LONG_LONG 8 68 | 69 | #define ZRTP_INLINE static __inline 70 | 71 | #define ZRTP_VERSION "0.90" 72 | 73 | 74 | #endif /* ZRTP_WIN_CONFIG_H__ */ 75 | -------------------------------------------------------------------------------- /include/zrtp_ec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | */ 7 | 8 | #ifndef __ZRTP_CRYPTO_EC_H__ 9 | #define __ZRTP_CRYPTO_EC_H__ 10 | 11 | #include "bn.h" 12 | 13 | #include "zrtp_config.h" 14 | #include "zrtp_types.h" 15 | #include "zrtp_error.h" 16 | 17 | #define ZRTP_MAXECBITS 521 18 | #define ZRTP_MAXECWORDS ((ZRTP_MAXECBITS+7)/8) 19 | 20 | typedef struct zrtp_ec_params 21 | { 22 | unsigned ec_bits; /* # EC bits: 256, 384, 521 */ 23 | uint8_t P_data[ZRTP_MAXECWORDS]; /* curve field prime */ 24 | uint8_t n_data[ZRTP_MAXECWORDS]; /* curve order (# points) */ 25 | uint8_t b_data[ZRTP_MAXECWORDS]; /* curve param, y^3 = x^2 -3x + b */ 26 | uint8_t Gx_data[ZRTP_MAXECWORDS]; /* curve point, x coordinate */ 27 | uint8_t Gy_data[ZRTP_MAXECWORDS]; /* curve point, y coordinate */ 28 | } zrtp_ec_params_t; 29 | 30 | #if defined(__cplusplus) 31 | extern "C" 32 | { 33 | #endif 34 | 35 | /*============================================================================*/ 36 | /* Elliptic Curve library */ 37 | /*============================================================================*/ 38 | 39 | int zrtp_ecAdd ( struct BigNum *rsltx, 40 | struct BigNum *rslty, 41 | struct BigNum *p1x, 42 | struct BigNum *p1y, 43 | struct BigNum *p2x, 44 | struct BigNum *p2y, 45 | struct BigNum *mod); 46 | 47 | int zrtp_ecMul ( struct BigNum *rsltx, 48 | struct BigNum *rslty, 49 | struct BigNum *mult, 50 | struct BigNum *basex, 51 | struct BigNum *basey, 52 | struct BigNum *mod); 53 | 54 | zrtp_status_t zrtp_ec_random_point( zrtp_global_t *zrtp, 55 | struct BigNum *P, 56 | struct BigNum *n, 57 | struct BigNum *Gx, 58 | struct BigNum *Gy, 59 | struct BigNum *pkx, 60 | struct BigNum *pky, 61 | struct BigNum *sv, 62 | uint8_t *test_sv_data, 63 | size_t test_sv_data_len); 64 | 65 | extern zrtp_status_t zrtp_ec_init_params(struct zrtp_ec_params *params, uint32_t bits ); 66 | 67 | 68 | /* Useful bignum utility functions not defined in bignum library */ 69 | int bnAddMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *mod); 70 | int bnAddQMod_ (struct BigNum *rslt, unsigned n1, struct BigNum *mod); 71 | int bnSubMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *mod); 72 | int bnSubQMod_ (struct BigNum *rslt, unsigned n1, struct BigNum *mod); 73 | int bnMulMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *n2, struct BigNum *mod); 74 | int bnMulQMod_ (struct BigNum *rslt, struct BigNum *n1, unsigned n2, struct BigNum *mod); 75 | int bnSquareMod_ (struct BigNum *rslt, struct BigNum *n1, struct BigNum *mod); 76 | 77 | #if defined(__cplusplus) 78 | } 79 | #endif 80 | 81 | #endif /* __ZRTP_CRYPTO_EC_H__ */ 82 | -------------------------------------------------------------------------------- /include/zrtp_iface_scheduler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | 11 | #ifndef __ZRTP_IFACE_SCHEDULER_H__ 12 | #define __ZRTP_IFACE_SCHEDULER_H__ 13 | 14 | #include "zrtp_config.h" 15 | #include "zrtp_base.h" 16 | #include "zrtp_string.h" 17 | #include "zrtp_error.h" 18 | #include "zrtp_iface.h" 19 | 20 | #if defined(ZRTP_USE_BUILTIN_SCEHDULER) && (ZRTP_USE_BUILTIN_SCEHDULER == 1) 21 | 22 | #if defined(__cplusplus) 23 | extern "C" 24 | { 25 | #endif 26 | 27 | 28 | /** 29 | * In order to use default secheduler libzrtp one should define tow extra interfaces: 30 | * sleep and threads riutine. 31 | */ 32 | 33 | /** 34 | * \brief Suspend thread execution for an interval measured in miliseconds 35 | * \param msec - number of miliseconds 36 | * \return: 0 if successful and -1 in case of errors. 37 | */ 38 | 39 | #if ZRTP_PLATFORM != ZP_WIN32_KERNEL 40 | 41 | #if (ZRTP_PLATFORM == ZP_WIN32) || (ZRTP_PLATFORM == ZP_WINCE) 42 | #include 43 | typedef LPTHREAD_START_ROUTINE zrtp_thread_routine_t; 44 | #elif (ZRTP_PLATFORM == ZP_LINUX) || (ZRTP_PLATFORM == ZP_DARWIN) || (ZRTP_PLATFORM == ZP_BSD) || (ZRTP_PLATFORM == ZP_ANDROID) 45 | typedef void *(*zrtp_thread_routine_t)(void*); 46 | #elif (ZRTP_PLATFORM == ZP_SYMBIAN) 47 | typedef int(*zrtp_thread_routine_t)(void*); 48 | #endif 49 | 50 | /** 51 | * \brief Function is used to create a new thread, within a process. 52 | * 53 | * Thread should be created with default attributes. Upon its creation, the thread executes 54 | * \c start_routine, with \c arg as its sole argument. 55 | * \param start_routine - thread start routine. 56 | * \param arg - start routine arguments. 57 | * \return 0 if successful and -1 in case of errors. 58 | */ 59 | 60 | 61 | extern int zrtp_thread_create(zrtp_thread_routine_t start_routine, void *arg); 62 | extern int zrtp_sleep(unsigned int msec); 63 | 64 | #endif 65 | 66 | void zrtp_def_scheduler_down(); 67 | 68 | zrtp_status_t zrtp_def_scheduler_init(zrtp_global_t* zrtp); 69 | 70 | void zrtp_def_scheduler_call_later(zrtp_stream_t *ctx, zrtp_retry_task_t* ztask); 71 | 72 | void zrtp_def_scheduler_cancel_call_later(zrtp_stream_t* ctx, zrtp_retry_task_t* ztask); 73 | 74 | void zrtp_def_scheduler_wait_call_later(zrtp_stream_t* ctx); 75 | 76 | 77 | zrtp_status_t zrtp_sem_init(zrtp_sem_t** sem, uint32_t value, uint32_t limit); 78 | zrtp_status_t zrtp_sem_destroy(zrtp_sem_t* sem); 79 | zrtp_status_t zrtp_sem_wait(zrtp_sem_t* sem); 80 | zrtp_status_t zrtp_sem_trtwait(zrtp_sem_t* sem); 81 | zrtp_status_t zrtp_sem_post(zrtp_sem_t* sem); 82 | 83 | #if defined(__cplusplus) 84 | } 85 | #endif 86 | 87 | #endif /* ZRTP_USE_BUILTIN_SCEHDULER */ 88 | 89 | #endif /*__ZRTP_IFACE_SCHEDULER_H__*/ 90 | -------------------------------------------------------------------------------- /include/zrtp_legal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #ifndef __ZRTP_LEGAL_H__ 11 | #define __ZRTP_LEGAL_H__ 12 | 13 | 14 | /* 15 | * We want the copyright string accessable to the unix strings command in 16 | * the linked binary, and don't want the linker to remove it if it's not 17 | * referenced, thus the volatile qualifier. 18 | * 19 | * ANSI C standard, section 3.5.3: "An object that has volatile-qualified 20 | * type may be modified in ways unknown to the implementation or have 21 | * other unknown side effects." 22 | */ 23 | extern volatile const char zrtpCopyright[]; 24 | 25 | #endif /*__ZRTP_LEGAL_H__ */ 26 | -------------------------------------------------------------------------------- /include/zrtp_list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | 11 | #ifndef __ZRTP_LIST_H__ 12 | #define __ZRTP_LIST_H__ 13 | 14 | #include "zrtp_config.h" 15 | 16 | typedef struct mlist mlist_t; 17 | struct mlist 18 | { 19 | mlist_t *next; 20 | mlist_t *prev; 21 | }; 22 | 23 | #if defined(__cplusplus) 24 | extern "C" 25 | { 26 | #endif 27 | 28 | /* 29 | * \warning 30 | * We cast pointer to integer. There is bad thing for 64 bit platforms but 31 | * calculated offset couldn't be bigger then 2x32 and it will be casted 32 | * to integer correctly. 33 | */ 34 | #define mlist_list_offset(type, list_name) ((size_t)&(((type*)0)->list_name)) 35 | 36 | #define mlist_get_struct(type, list_name, list_ptr) \ 37 | ((type*)(((char*)(list_ptr)) - mlist_list_offset(type,list_name))) 38 | 39 | #define mlist_for_each(pos, head) \ 40 | for (pos = (head)->next; pos != (head); pos = pos->next) 41 | 42 | #define mlist_for_each_safe(pos, n, head) \ 43 | for (pos = (head)->next, n = pos->next; pos != (head); \ 44 | pos = n, n = pos->next) 45 | 46 | void init_mlist(mlist_t* head); 47 | 48 | void mlist_add(mlist_t* head, mlist_t* node); 49 | void mlist_add_tail(mlist_t *head, mlist_t *node); 50 | 51 | void mlist_insert(mlist_t *prev, mlist_t *node); 52 | 53 | void mlist_del(mlist_t *node); 54 | void mlist_del_tail(mlist_t *node); 55 | 56 | mlist_t* mlist_get(mlist_t *head); 57 | mlist_t* mlist_get_tail(mlist_t *head); 58 | 59 | int mlist_isempty(mlist_t *head); 60 | 61 | #if defined(__cplusplus) 62 | } 63 | #endif 64 | 65 | 66 | #endif /*__ZRTP_LIST_H__ */ 67 | -------------------------------------------------------------------------------- /include/zrtp_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #ifndef __ZRTP_VERSION_H__ 11 | #define __ZRTP_VERSION_H__ 12 | 13 | #define LIBZRTP_VERSION_MAJOR 1 14 | 15 | #define LIBZRTP_VERSION_MINOR 20 16 | #define LIBZRTP_VERSION_BUILD 616 17 | #define LIBZRTP_VERSION_STR "v1.20 616" 18 | 19 | #endif /*__ZRTP_VERSION_H__*/ 20 | -------------------------------------------------------------------------------- /projects/android/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir)/../../.. 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := libzrtp 6 | MY_SRC_PATH := src 7 | 8 | MY_SRC_FILES := $(MY_SRC_PATH)/zrtp.c \ 9 | $(MY_SRC_PATH)/zrtp_crc.c \ 10 | $(MY_SRC_PATH)/zrtp_crypto_aes.c \ 11 | $(MY_SRC_PATH)/zrtp_crypto_atl.c \ 12 | $(MY_SRC_PATH)/zrtp_crypto_hash.c \ 13 | $(MY_SRC_PATH)/zrtp_crypto_pk.c \ 14 | $(MY_SRC_PATH)/zrtp_crypto_sas.c \ 15 | $(MY_SRC_PATH)/zrtp_datatypes.c \ 16 | $(MY_SRC_PATH)/zrtp_engine.c \ 17 | $(MY_SRC_PATH)/zrtp_engine_driven.c \ 18 | $(MY_SRC_PATH)/zrtp_iface_cache.c \ 19 | $(MY_SRC_PATH)/zrtp_iface_scheduler.c \ 20 | $(MY_SRC_PATH)/zrtp_iface_sys.c \ 21 | $(MY_SRC_PATH)/zrtp_initiator.c \ 22 | $(MY_SRC_PATH)/zrtp_legal.c \ 23 | $(MY_SRC_PATH)/zrtp_list.c \ 24 | $(MY_SRC_PATH)/zrtp_log.c \ 25 | $(MY_SRC_PATH)/zrtp_pbx.c \ 26 | $(MY_SRC_PATH)/zrtp_protocol.c \ 27 | $(MY_SRC_PATH)/zrtp_responder.c \ 28 | $(MY_SRC_PATH)/zrtp_rng.c \ 29 | $(MY_SRC_PATH)/zrtp_srtp_builtin.c \ 30 | $(MY_SRC_PATH)/zrtp_srtp_dm.c \ 31 | $(MY_SRC_PATH)/zrtp_string.c \ 32 | $(MY_SRC_PATH)/zrtp_utils.c \ 33 | $(MY_SRC_PATH)/zrtp_utils_proto.c 34 | 35 | MY_SRC_FILES += third_party/bgaes/aes_modes.c \ 36 | third_party/bgaes/sha2.c \ 37 | third_party/bgaes/sha1.c \ 38 | third_party/bgaes/aestab.c \ 39 | third_party/bgaes/aeskey.c \ 40 | third_party/bgaes/aescrypt.c 41 | 42 | MY_SRC_FILES += third_party/bnlib/bn.c \ 43 | third_party/bnlib/bn32.c \ 44 | third_party/bnlib/bninit32.c \ 45 | third_party/bnlib/lbn32.c \ 46 | third_party/bnlib/lbnmem.c \ 47 | third_party/bnlib/legal.c 48 | 49 | LOCAL_SRC_FILES := $(MY_SRC_FILES) 50 | 51 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include 52 | 53 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include 54 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/third_party/bnlib 55 | LOCAL_C_INCLUDES += $(LOCAL_PATH)/third_party/bgaes 56 | 57 | LOCAL_ARM_MODE := arm 58 | LOCAL_CFLAGS := -DANDROID_NDK=5 59 | 60 | #include $(BUILD_STATIC_LIBRARY) 61 | include $(BUILD_SHARED_LIBRARY) 62 | 63 | # 64 | # Dummy shared library to build libzrtp.a 65 | # 66 | 67 | # include $(CLEAR_VARS) 68 | # 69 | # LOCAL_MODULE := libzrtp-dummy 70 | # LOCAL_STATIC_LIBRARIES := libzrtp 71 | # 72 | # include $(BUILD_SHARED_LIBRARY) 73 | -------------------------------------------------------------------------------- /projects/symbian/DelayRuner.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================ 3 | Name : CDelayRuner.cpp 4 | Author : R. Drutsky 5 | Version : 1.0 6 | Copyright : Copyright (c) 2010 Soft Industry 7 | Description : CCDelayRuner implementation 8 | ============================================================================ 9 | */ 10 | 11 | #include "DelayRuner.h" 12 | #include "zrtp_iface_system.h" 13 | 14 | void zrtp_internal_delete_task_from_list(zrtp_stream_t* ctx, zrtp_retry_task_t* ztask); 15 | 16 | CDelayRuner::CDelayRuner() : 17 | CActive(EPriorityLow) // Standard priority 18 | { 19 | } 20 | 21 | CDelayRuner* CDelayRuner::NewLC() 22 | { 23 | CDelayRuner* self = new (ELeave) CDelayRuner(); 24 | CleanupStack::PushL(self); 25 | self->ConstructL(); 26 | return self; 27 | } 28 | 29 | CDelayRuner* CDelayRuner::NewL() 30 | { 31 | CDelayRuner* self = CDelayRuner::NewLC(); 32 | CleanupStack::Pop(); // self; 33 | return self; 34 | } 35 | 36 | void CDelayRuner::ConstructL() 37 | { 38 | User::LeaveIfError(iTimer.CreateLocal()); // Initialize timer 39 | CActiveScheduler::Add(this); // Add to scheduler 40 | } 41 | 42 | CDelayRuner::~CDelayRuner() 43 | { 44 | Cancel(); // Cancel any request, if outstanding 45 | iTimer.Close(); // Destroy the RTimer object 46 | // Delete instance variables if any 47 | } 48 | 49 | void CDelayRuner::DoCancel() 50 | { 51 | iTimer.Cancel(); 52 | } 53 | 54 | void CDelayRuner::StartL(zrtp_stream_t *ctx, zrtp_retry_task_t* ztask) 55 | { 56 | Cancel(); // Cancel any request, just to be sure 57 | //iState = EUninitialized; 58 | iCtx = ctx; 59 | iZTask = ztask; 60 | iTimer.After(iStatus, ztask->timeout * 1000); // Set for later 61 | SetActive(); // Tell scheduler a request is active 62 | } 63 | 64 | void CDelayRuner::RunL() 65 | { 66 | if (iStatus == KErrNone) 67 | { 68 | // Do something useful 69 | iZTask->_is_busy = 1 ; // may be we don't need this 70 | (iZTask->callback)(iCtx,iZTask); 71 | iZTask->_is_busy = 0 ; // may be we don't need this 72 | } 73 | zrtp_internal_delete_task_from_list(iCtx,iZTask); 74 | } 75 | 76 | TInt CDelayRuner::RunError(TInt aError) 77 | { 78 | return aError; 79 | } 80 | -------------------------------------------------------------------------------- /projects/symbian/DelayRuner.h: -------------------------------------------------------------------------------- 1 | /* 2 | ============================================================================ 3 | Name : CDelayRuner.h 4 | Author : R. Drutsky 5 | Version : 1.0 6 | Copyright : Copyright (c) 2010 Soft Industry 7 | Description : CDelayRuner declaration 8 | ============================================================================ 9 | */ 10 | 11 | #ifndef DELAYRUNER_H 12 | #define DELAYRUNER_H 13 | 14 | #include // For CActive, link against: euser.lib 15 | #include // For RTimer, link against: euser.lib 16 | 17 | #include 18 | class CDelayRuner : public CActive 19 | { 20 | public: 21 | // Cancel and destroy 22 | ~CDelayRuner(); 23 | 24 | // Two-phased constructor. 25 | static CDelayRuner* NewL(); 26 | 27 | // Two-phased constructor. 28 | static CDelayRuner* NewLC(); 29 | 30 | public: 31 | // New functions 32 | // Function for making the initial request 33 | void StartL(zrtp_stream_t *ctx, zrtp_retry_task_t* ztask); 34 | 35 | private: 36 | // C++ constructor 37 | CDelayRuner(); 38 | 39 | // Second-phase constructor 40 | void ConstructL(); 41 | 42 | private: 43 | // From CActive 44 | // Handle completion 45 | void RunL(); 46 | 47 | // How to cancel me 48 | void DoCancel(); 49 | 50 | // Override to handle leaves from RunL(). Default implementation causes 51 | // the active scheduler to panic. 52 | TInt RunError(TInt aError); 53 | 54 | private: 55 | enum TCDelayRunerState 56 | { 57 | EUninitialized, // Uninitialized 58 | EInitialized, // Initalized 59 | EError 60 | // Error condition 61 | }; 62 | 63 | private: 64 | TInt iState; // State of the active object 65 | RTimer iTimer; // Provides async timing service 66 | 67 | zrtp_stream_t *iCtx; 68 | zrtp_retry_task_t * iZTask; 69 | 70 | }; 71 | 72 | #endif // CDELAYRUNER_H 73 | -------------------------------------------------------------------------------- /projects/symbian/bld.bat: -------------------------------------------------------------------------------- 1 | bldmake bldfiles -------------------------------------------------------------------------------- /projects/symbian/bld.inf: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Philip R. Zimmermann. All rights reserved. 3 | * Contact: http://philzimmermann.com 4 | * 5 | * Nikolay Popok mailto: 6 | * 7 | */ 8 | 9 | PRJ_MMPFILES 10 | libzrtp.mmp 11 | 12 | PRJ_PLATFORMS 13 | WINSCW GCCE WINC 14 | -------------------------------------------------------------------------------- /projects/symbian/bldgcce.bat: -------------------------------------------------------------------------------- 1 | abld build gcce urel 2 | pause -------------------------------------------------------------------------------- /projects/symbian/libzrtp.mmp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 3 | * Contact: http://philzimmermann.com 4 | * For licensing and other legal details, see the file zrtp_legal.c. 5 | */ 6 | 7 | TARGET libzrtp.lib 8 | TARGETTYPE lib 9 | UID 0x0FFFFFF0 10 | 11 | VENDORID 0 12 | 13 | //OPTION GCC +Wno-ctor-dtor-privacy 14 | MACRO ZRTP_USE_STACK_MINIM 15 | 16 | USERINCLUDE . 17 | 18 | SOURCEPATH . 19 | SOURCE DelayRuner.cpp 20 | SOURCE zrtp_iface_symb.cpp 21 | 22 | SOURCEPATH ..\..\third_party\bnlib 23 | SOURCE bn.c 24 | SOURCE bn32.c 25 | SOURCE bninit32.c 26 | SOURCE lbn32.c 27 | SOURCE lbnmem.c 28 | SOURCE legal.c 29 | 30 | SOURCEPATH ..\..\src 31 | SOURCE zrtp_crc.c 32 | SOURCE zrtp_crypto_aes.c 33 | SOURCE zrtp_crypto_atl.c 34 | SOURCE zrtp_crypto_hash.c 35 | SOURCE zrtp_crypto_pk.c 36 | SOURCE zrtp_crypto_sas.c 37 | SOURCE zrtp_datatypes.c 38 | SOURCE zrtp_engine.c 39 | SOURCE zrtp_iface_cache.c 40 | SOURCE zrtp_iface_scheduler.c 41 | SOURCE zrtp_iface_sys.c 42 | SOURCE zrtp_initiator.c 43 | SOURCE zrtp_list.c 44 | SOURCE zrtp_log.c 45 | SOURCE zrtp_pbx.c 46 | SOURCE zrtp_protocol.c 47 | SOURCE zrtp_responder.c 48 | SOURCE zrtp_rng.c 49 | SOURCE zrtp_srtp_builtin.c 50 | SOURCE zrtp_string.c 51 | SOURCE zrtp_utils.c 52 | SOURCE zrtp_utils_proto.c 53 | SOURCE zrtp.c 54 | 55 | SOURCEPATH ..\..\third_party\bgaes 56 | SOURCE aes_modes.c 57 | SOURCE aescrypt.c 58 | SOURCE aeskey.c 59 | SOURCE aestab.c 60 | SOURCE sha1.c 61 | SOURCE sha2.c 62 | 63 | SYSTEMINCLUDE ..\..\. 64 | SYSTEMINCLUDE ..\..\include 65 | SYSTEMINCLUDE ..\..\third_party\bnlib 66 | SYSTEMINCLUDE ..\..\third_party\bgaes 67 | 68 | SYSTEMINCLUDE \epoc32\include 69 | SYSTEMINCLUDE \epoc32\include\libc 70 | 71 | LIBRARY euser.lib 72 | 73 | SOURCEPATH ..\..\src 74 | SOURCE zrtp_crypto_ec.c zrtp_crypto_ecdh.c zrtp_crypto_ecdsa.c zrtp_engine_driven.c zrtp_legal.c zrtp_srtp_dm.c 75 | -------------------------------------------------------------------------------- /projects/win/libzrtp.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 10.00 2 | # Visual Studio 2008 3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libzrtp_test", "libzrtp_test.vcproj", "{BA35741B-8C8E-4A39-9CA1-0CE032D6E4ED}" 4 | ProjectSection(ProjectDependencies) = postProject 5 | {C13CC324-E0CA-4492-9A30-310A6BD64FF5} = {C13CC324-E0CA-4492-9A30-310A6BD64FF5} 6 | EndProjectSection 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libzrtp", "libzrtp.vcproj", "{C13CC324-E0CA-4492-9A30-310A6BD64FF5}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Win32 = Debug|Win32 13 | Release|Win32 = Release|Win32 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {BA35741B-8C8E-4A39-9CA1-0CE032D6E4ED}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {BA35741B-8C8E-4A39-9CA1-0CE032D6E4ED}.Debug|Win32.Build.0 = Debug|Win32 18 | {BA35741B-8C8E-4A39-9CA1-0CE032D6E4ED}.Release|Win32.ActiveCfg = Release|Win32 19 | {BA35741B-8C8E-4A39-9CA1-0CE032D6E4ED}.Release|Win32.Build.0 = Release|Win32 20 | {C13CC324-E0CA-4492-9A30-310A6BD64FF5}.Debug|Win32.ActiveCfg = Debug|Win32 21 | {C13CC324-E0CA-4492-9A30-310A6BD64FF5}.Debug|Win32.Build.0 = Debug|Win32 22 | {C13CC324-E0CA-4492-9A30-310A6BD64FF5}.Release|Win32.ActiveCfg = Release|Win32 23 | {C13CC324-E0CA-4492-9A30-310A6BD64FF5}.Release|Win32.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /projects/win/libzrtp.x32.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /projects/win/libzrtp.x64.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /projects/win_ce/libzrtp_wince.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libzrtp", "libzrtp_wince.vcproj", "{53F84E3B-9903-4046-897B-33FEFFED527A}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libzrtp_test", "libzrtp_test_wince.vcproj", "{5C082222-FD44-4295-8055-915936F086BE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Pocket PC 2003 (ARMV4) = Debug|Pocket PC 2003 (ARMV4) 11 | Debug|Smartphone 2003 (ARMV4) = Debug|Smartphone 2003 (ARMV4) 12 | Release|Pocket PC 2003 (ARMV4) = Release|Pocket PC 2003 (ARMV4) 13 | Release|Smartphone 2003 (ARMV4) = Release|Smartphone 2003 (ARMV4) 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {53F84E3B-9903-4046-897B-33FEFFED527A}.Debug|Pocket PC 2003 (ARMV4).ActiveCfg = Debug|Pocket PC 2003 (ARMV4) 17 | {53F84E3B-9903-4046-897B-33FEFFED527A}.Debug|Smartphone 2003 (ARMV4).ActiveCfg = Debug|Smartphone 2003 (ARMV4) 18 | {53F84E3B-9903-4046-897B-33FEFFED527A}.Release|Pocket PC 2003 (ARMV4).ActiveCfg = Release|Pocket PC 2003 (ARMV4) 19 | {53F84E3B-9903-4046-897B-33FEFFED527A}.Release|Pocket PC 2003 (ARMV4).Build.0 = Release|Pocket PC 2003 (ARMV4) 20 | {53F84E3B-9903-4046-897B-33FEFFED527A}.Release|Pocket PC 2003 (ARMV4).Deploy.0 = Release|Pocket PC 2003 (ARMV4) 21 | {53F84E3B-9903-4046-897B-33FEFFED527A}.Release|Smartphone 2003 (ARMV4).ActiveCfg = Release|Smartphone 2003 (ARMV4) 22 | {53F84E3B-9903-4046-897B-33FEFFED527A}.Release|Smartphone 2003 (ARMV4).Build.0 = Release|Smartphone 2003 (ARMV4) 23 | {53F84E3B-9903-4046-897B-33FEFFED527A}.Release|Smartphone 2003 (ARMV4).Deploy.0 = Release|Smartphone 2003 (ARMV4) 24 | {5C082222-FD44-4295-8055-915936F086BE}.Debug|Pocket PC 2003 (ARMV4).ActiveCfg = Debug|Pocket PC 2003 (ARMV4) 25 | {5C082222-FD44-4295-8055-915936F086BE}.Debug|Pocket PC 2003 (ARMV4).Build.0 = Debug|Pocket PC 2003 (ARMV4) 26 | {5C082222-FD44-4295-8055-915936F086BE}.Debug|Pocket PC 2003 (ARMV4).Deploy.0 = Debug|Pocket PC 2003 (ARMV4) 27 | {5C082222-FD44-4295-8055-915936F086BE}.Debug|Smartphone 2003 (ARMV4).ActiveCfg = Debug|Smartphone 2003 (ARMV4) 28 | {5C082222-FD44-4295-8055-915936F086BE}.Debug|Smartphone 2003 (ARMV4).Build.0 = Debug|Smartphone 2003 (ARMV4) 29 | {5C082222-FD44-4295-8055-915936F086BE}.Debug|Smartphone 2003 (ARMV4).Deploy.0 = Debug|Smartphone 2003 (ARMV4) 30 | {5C082222-FD44-4295-8055-915936F086BE}.Release|Pocket PC 2003 (ARMV4).ActiveCfg = Release|Pocket PC 2003 (ARMV4) 31 | {5C082222-FD44-4295-8055-915936F086BE}.Release|Pocket PC 2003 (ARMV4).Build.0 = Release|Pocket PC 2003 (ARMV4) 32 | {5C082222-FD44-4295-8055-915936F086BE}.Release|Pocket PC 2003 (ARMV4).Deploy.0 = Release|Pocket PC 2003 (ARMV4) 33 | {5C082222-FD44-4295-8055-915936F086BE}.Release|Smartphone 2003 (ARMV4).ActiveCfg = Release|Smartphone 2003 (ARMV4) 34 | {5C082222-FD44-4295-8055-915936F086BE}.Release|Smartphone 2003 (ARMV4).Build.0 = Release|Smartphone 2003 (ARMV4) 35 | {5C082222-FD44-4295-8055-915936F086BE}.Release|Smartphone 2003 (ARMV4).Deploy.0 = Release|Smartphone 2003 (ARMV4) 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | EndGlobal 41 | -------------------------------------------------------------------------------- /projects/win_kernel/MAKEFILE.WIN32: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006 Philip R. Zimmermann. All rights reserved. 3 | # Contact: http://philzimmermann.com 4 | # For licensing and other legal details, see the file zrtp_legal.c. 5 | # 6 | # Andrew Rozinko 7 | 8 | # 9 | # THIS MAKEFILE WORKS WITH MICROSOFT NMAKE ONLY 10 | # 11 | 12 | # change this to point to your DDK 13 | 14 | DDK = ..\..\..\..\winddk\3790 15 | OS = wxp 16 | BASENAME = libzrtp 17 | 18 | #RELEASE = 1 19 | 20 | CC = cl 21 | ASM = ml 22 | LIB = lib 23 | 24 | all: $(BASENAME).lib 25 | 26 | # bnlib (the BigNumber engine) 27 | 28 | bnlib = \ 29 | ../../third_party/bnlib/bn.obj \ 30 | ../../third_party/bnlib/bn32.obj \ 31 | ../../third_party/bnlib/bninit32.obj \ 32 | ../../third_party/bnlib/lbn32.obj \ 33 | ../../third_party/bnlib/lbnmem.obj \ 34 | ../../third_party/bnlib/legal.obj 35 | 36 | protocol = \ 37 | ../../src/zrtp.obj \ 38 | ../../src/zrtp_crc.obj \ 39 | ../../src/zrtp_crypto_aes.obj \ 40 | ../../src/zrtp_crypto_atl.obj \ 41 | ../../src/zrtp_crypto_hash.obj \ 42 | ../../src/zrtp_crypto_pk.obj \ 43 | ../../src/zrtp_crypto_sas.obj \ 44 | ../../src/zrtp_datatypes.obj \ 45 | ../../src/zrtp_engine.obj \ 46 | ../../src/enterprise/zrtp_engine_driven.obj \ 47 | ../../src/enterprise/zrtp_crypto_ec.obj \ 48 | ../../src/enterprise/zrtp_crypto_ecdh.obj \ 49 | ../../src/zrtp_iface_sys.obj \ 50 | ../../src/zrtp_initiator.obj \ 51 | ../../src/zrtp_legal.obj \ 52 | ../../src/zrtp_list.obj \ 53 | ../../src/zrtp_log.obj \ 54 | ../../src/zrtp_pbx.obj \ 55 | ../../src/zrtp_protocol.obj \ 56 | ../../src/zrtp_responder.obj \ 57 | ../../src/zrtp_rng.obj \ 58 | ../../src/zrtp_srtp_builtin.obj \ 59 | ../../src/zrtp_string.obj \ 60 | ../../src/zrtp_utils.obj \ 61 | ../../src/zrtp_utils_proto.obj 62 | 63 | bgaes = \ 64 | ../../third_party/bgaes/aes_modes.obj \ 65 | ../../third_party/bgaes/aescrypt.obj \ 66 | ../../third_party/bgaes/aeskey.obj \ 67 | ../../third_party/bgaes/aestab.obj \ 68 | ../../third_party/bgaes/sha1.obj \ 69 | ../../third_party/bgaes/sha2.obj 70 | 71 | OBJECTS = $(bnlib) $(protocol) $(bgaes) 72 | 73 | !IFNDEF RELEASE 74 | 75 | # Debug 76 | 77 | OUT_DIR = debug_ec.km 78 | 79 | DEFINES_D = -D_X86_=1 -Di386=1 -DSTD_CALL -DCONDITION_HANDLING=1 \ 80 | -DNT_UP=1 -DNT_INST=0 -DWIN32=100 -D_NT1X_=100 \ 81 | -DWINNT=1 -D_WIN32_WINNT=0x0500 -DWIN32_LEAN_AND_MEAN=1 -DDBG=1 -D_DEBUG -DDEBUG -DDEVL=1 \ 82 | -DFPO=0 -D_DLL=1 -D_IDWBUILD -DRDRDBG -DSRVDBG -DDBG_MESSAGES=1 \ 83 | -D_UNICODE -DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=1 84 | 85 | CFLAGS_D = $(DEFINES_D) -Zel -Zp8 -Gy -cbstring -Gz -QIfdiv- -QIf -Gi- -Gm- -GX- \ 86 | -GR- -GF -FI$(DDK)\inc\$(OS)\warning.h -Z7 -Od -Oi -Oy- -W3 87 | 88 | !ELSE 89 | 90 | # Release 91 | 92 | OUT_DIR = release_ec.km 93 | 94 | DEFINES_D = -D_X86_=1 -Di386=1 -DSTD_CALL -DCONDITION_HANDLING=1 \ 95 | -DNT_UP=1 -DNO_DISK_ACCESS -DNT_INST=0 -DWIN32=100 -D_NT1X_=100 \ 96 | -DWINNT=1 -D_WIN32_WINNT=0x0500 -DWIN32_LEAN_AND_MEAN=1 -DDEVL=1 \ 97 | -DFPO=1 -DNDEBUG -D_DLL=1 -D_IDWBUILD -D_UNICODE \ 98 | -DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=1 99 | 100 | CFLAGS_D = $(DEFINES_D) -Zel -Zp8 -Gy -cbstring -Gz -QIfdiv- -QIf -Gi- -Gm- -GX- \ 101 | -GR- -GF -Oxs -Oy -FI$(DDK)\inc\$(OS)\warning.h -W3 -FAcs -Z7 102 | 103 | !ENDIF 104 | 105 | ASM = ml 106 | AFLAGS = /c /Cx /coff /Zi 107 | AINCLUDE = -I. -I$(DDK)\inc 108 | 109 | CFLAGS = $(CFLAGS_D) -nologo -DHAVE_CONFIG_H=1 -DNT_DRIVER -D__BUILDMACHINE__=WinDDK \ 110 | -I$(DDK)\inc\$(OS) -I$(DDK)\inc\ddk\$(OS) -I$(DDK)\inc\ddk\wdm\$(OS) \ 111 | -I. -Ibnlib -Iinclude \ 112 | -I$(DDK)\inc\crt -I..\..\third_party\bnlib\config -I..\..\third_party\bnlib \ 113 | -I..\..\third_party\bgaes -I..\..\test\include -I..\..\include -I..\..\include\enterprise 114 | 115 | .c.obj : 116 | @$(CC) -c $(CFLAGS) $< /Fo$(OUT_DIR)/$( 7 | 8 | # 9 | # THIS MAKEFILE WORKS WITH MICROSOFT NMAKE ONLY 10 | # 11 | 12 | # change this to point to your DDK 13 | 14 | DDK = ..\..\..\..\winddk2003 15 | OS = wnet 16 | BASENAME = libzrtp 17 | BINPATH = $(DDK)\bin\win64\x86\amd64 18 | 19 | #RELEASE = 1 20 | 21 | CC = $(BINPATH)\cl 22 | ASM = $(BINPATH)\ml 23 | LIB = $(BINPATH)\lib 24 | 25 | all: $(BASENAME).lib 26 | 27 | # bnlib (the BigNumber engine) 28 | 29 | bnlib = \ 30 | ../../third_party/bnlib/bn.obj \ 31 | ../../third_party/bnlib/bn32.obj \ 32 | ../../third_party/bnlib/bninit32.obj \ 33 | ../../third_party/bnlib/lbn32.obj \ 34 | ../../third_party/bnlib/lbnmem.obj \ 35 | ../../third_party/bnlib/legal.obj 36 | 37 | protocol = \ 38 | ../../src/zrtp.obj \ 39 | ../../src/zrtp_crc.obj \ 40 | ../../src/zrtp_crypto_aes.obj \ 41 | ../../src/zrtp_crypto_atl.obj \ 42 | ../../src/zrtp_crypto_hash.obj \ 43 | ../../src/zrtp_crypto_pk.obj \ 44 | ../../src/zrtp_crypto_sas.obj \ 45 | ../../src/zrtp_datatypes.obj \ 46 | ../../src/zrtp_engine.obj \ 47 | ../../src/enterprise/zrtp_engine_driven.obj \ 48 | ../../src/enterprise/zrtp_crypto_ec.obj \ 49 | ../../src/enterprise/zrtp_crypto_ecdh.obj \ 50 | ../../src/zrtp_iface_sys.obj \ 51 | ../../src/zrtp_initiator.obj \ 52 | ../../src/zrtp_legal.obj \ 53 | ../../src/zrtp_list.obj \ 54 | ../../src/zrtp_log.obj \ 55 | ../../src/zrtp_pbx.obj \ 56 | ../../src/zrtp_protocol.obj \ 57 | ../../src/zrtp_responder.obj \ 58 | ../../src/zrtp_rng.obj \ 59 | ../../src/zrtp_srtp_builtin.obj \ 60 | ../../src/zrtp_string.obj \ 61 | ../../src/zrtp_utils.obj \ 62 | ../../src/zrtp_utils_proto.obj 63 | 64 | bgaes = \ 65 | ../../third_party/bgaes/aes_modes.obj \ 66 | ../../third_party/bgaes/aescrypt.obj \ 67 | ../../third_party/bgaes/aeskey.obj \ 68 | ../../third_party/bgaes/aestab.obj \ 69 | ../../third_party/bgaes/sha1.obj \ 70 | ../../third_party/bgaes/sha2.obj 71 | 72 | OBJECTS = $(bnlib) $(protocol) $(bgaes) 73 | 74 | !IFNDEF RELEASE 75 | 76 | # Debug 77 | 78 | OUT_DIR = debug64_ec.km 79 | 80 | DEFINES_D = -DWIN64=1 -D_WIN64=1 -D_AMD64_=1 -D_M_AMD64 -D_WINDOWS \ 81 | -DSTD_CALL -DCONDITION_HANDLING=1 \ 82 | -DNT_UP=1 -DNT_INST=0 -D_NT1X_=100 \ 83 | -DWINNT=1 -D_WIN32_WINNT=0x0500 -DWIN32_LEAN_AND_MEAN=1 -DDBG=1 -D_DEBUG -DDEBUG -DDEVL=1 \ 84 | -DFPO=0 -D_DLL=1 -D_IDWBUILD -DRDRDBG -DSRVDBG -DDBG_MESSAGES=1 \ 85 | -D_UNICODE -DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=1 86 | 87 | CFLAGS_D = $(DEFINES_D) -Zp8 -Gy -cbstring -Gz -Gm- -EHs-c- \ 88 | -GR- -GF -FI$(DDK)\inc\$(OS)\warning.h -Z7 -Od -Oi -Oy- -W3 89 | 90 | !ELSE 91 | 92 | # Release 93 | 94 | OUT_DIR = release64_ec.km 95 | 96 | DEFINES_D = -DWIN64=1 -D_WIN64=1 -D_AMD64_=1 -D_M_AMD64 -D_WINDOWS \ 97 | -DSTD_CALL -DCONDITION_HANDLING=1 \ 98 | -DNT_UP=1 -DNO_DISK_ACCESS -DNT_INST=0 -DWIN32=100 -D_NT1X_=100 \ 99 | -DWINNT=1 -D_WIN32_WINNT=0x0500 -DWIN32_LEAN_AND_MEAN=1 -DDEVL=1 \ 100 | -DFPO=1 -DNDEBUG -D_DLL=1 -D_IDWBUILD -D_UNICODE \ 101 | -DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=1 102 | 103 | CFLAGS_D = $(DEFINES_D) -Zel -Zp8 -Gy -cbstring -Gz -QIfdiv- -QIf -Gi- -Gm- -GX- \ 104 | -GR- -GF -Oxs -Oy -FI$(DDK)\inc\$(OS)\warning.h -W3 -FAcs -Z7 105 | 106 | !ENDIF 107 | 108 | ASM = ml 109 | AFLAGS = /c /Cx /coff /Zi 110 | AINCLUDE = -I. -I$(DDK)\inc 111 | 112 | CFLAGS = $(CFLAGS_D) -nologo -DHAVE_CONFIG_H=1 -DNT_DRIVER -D__BUILDMACHINE__=WinDDK \ 113 | -I$(DDK)\inc\$(OS) -I$(DDK)\inc\ddk\$(OS) -I$(DDK)\inc\ddk\wdm\$(OS) \ 114 | -I$(DDK)\inc\crt -I..\..\third_party\bnlib\config -I..\..\third_party\bnlib \ 115 | -I..\..\third_party\bgaes -I..\..\test\include -I..\..\include -I..\..\include\enterprise 116 | 117 | .c.obj : 118 | @$(CC) -c $(CFLAGS) $< /Fo$(OUT_DIR)/$( 7 | 8 | # 9 | # THIS MAKEFILE WORKS WITH MICROSOFT NMAKE ONLY 10 | # 11 | 12 | # change this to point to your DDK 13 | 14 | DDK = ..\..\..\..\winddk\3790 15 | OS = wxp 16 | BASENAME = libzrtp 17 | 18 | #RELEASE = 1 19 | 20 | CC = cl 21 | ASM = ml 22 | LIB = lib 23 | 24 | all: $(BASENAME).lib 25 | 26 | # bnlib (the BigNumber engine) 27 | 28 | bnlib = \ 29 | ../../third_party/bnlib/bn.obj \ 30 | ../../third_party/bnlib/bn32.obj \ 31 | ../../third_party/bnlib/bninit32.obj \ 32 | ../../third_party/bnlib/lbn32.obj \ 33 | ../../third_party/bnlib/lbnmem.obj \ 34 | ../../third_party/bnlib/legal.obj 35 | 36 | protocol = \ 37 | ../../src/zrtp.obj \ 38 | ../../src/zrtp_crc.obj \ 39 | ../../src/zrtp_crypto_aes.obj \ 40 | ../../src/zrtp_crypto_atl.obj \ 41 | ../../src/zrtp_crypto_hash.obj \ 42 | ../../src/zrtp_crypto_pk.obj \ 43 | ../../src/zrtp_crypto_sas.obj \ 44 | ../../src/zrtp_datatypes.obj \ 45 | ../../src/zrtp_engine.obj \ 46 | ../../src/zrtp_iface_sys.obj \ 47 | ../../src/zrtp_initiator.obj \ 48 | ../../src/zrtp_legal.obj \ 49 | ../../src/zrtp_list.obj \ 50 | ../../src/zrtp_log.obj \ 51 | ../../src/zrtp_pbx.obj \ 52 | ../../src/zrtp_protocol.obj \ 53 | ../../src/zrtp_responder.obj \ 54 | ../../src/zrtp_rng.obj \ 55 | ../../src/zrtp_srtp_builtin.obj \ 56 | ../../src/zrtp_string.obj \ 57 | ../../src/zrtp_utils.obj \ 58 | ../../src/zrtp_utils_proto.obj 59 | 60 | bgaes = \ 61 | ../../third_party/bgaes/aes_modes.obj \ 62 | ../../third_party/bgaes/aescrypt.obj \ 63 | ../../third_party/bgaes/aeskey.obj \ 64 | ../../third_party/bgaes/aestab.obj \ 65 | ../../third_party/bgaes/sha1.obj \ 66 | ../../third_party/bgaes/sha2.obj 67 | 68 | OBJECTS = $(bnlib) $(protocol) $(bgaes) 69 | 70 | !IFNDEF RELEASE 71 | 72 | # Debug 73 | 74 | OUT_DIR = debug.km 75 | 76 | DEFINES_D = -D_X86_=1 -Di386=1 -DSTD_CALL -DCONDITION_HANDLING=1 \ 77 | -DNT_UP=1 -DNT_INST=0 -DWIN32=100 -D_NT1X_=100 \ 78 | -DWINNT=1 -D_WIN32_WINNT=0x0500 -DWIN32_LEAN_AND_MEAN=1 -DDBG=1 -D_DEBUG -DDEBUG -DDEVL=1 \ 79 | -DFPO=0 -D_DLL=1 -D_IDWBUILD -DRDRDBG -DSRVDBG -DDBG_MESSAGES=1 \ 80 | -D_UNICODE -DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=0 81 | 82 | CFLAGS_D = $(DEFINES_D) -Zel -Zp8 -Gy -cbstring -Gz -QIfdiv- -QIf -Gi- -Gm- -GX- \ 83 | -GR- -GF -FI$(DDK)\inc\$(OS)\warning.h -Z7 -Od -Oi -Oy- -W3 84 | 85 | !ELSE 86 | 87 | # Release 88 | 89 | OUT_DIR = release.km 90 | 91 | DEFINES_D = -D_X86_=1 -Di386=1 -DSTD_CALL -DCONDITION_HANDLING=1 \ 92 | -DNT_UP=1 -DNO_DISK_ACCESS -DNT_INST=0 -DWIN32=100 -D_NT1X_=100 \ 93 | -DWINNT=1 -D_WIN32_WINNT=0x0500 -DWIN32_LEAN_AND_MEAN=1 -DDEVL=1 \ 94 | -DFPO=1 -DNDEBUG -D_DLL=1 -D_IDWBUILD -D_UNICODE \ 95 | -DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=0 96 | 97 | CFLAGS_D = $(DEFINES_D) -Zel -Zp8 -Gy -cbstring -Gz -QIfdiv- -QIf -Gi- -Gm- -GX- \ 98 | -GR- -GF -Oxs -Oy -FI$(DDK)\inc\$(OS)\warning.h -W3 -FAcs -Z7 99 | 100 | !ENDIF 101 | 102 | ASM = ml 103 | AFLAGS = /c /Cx /coff /Zi 104 | AINCLUDE = -I. -I$(DDK)\inc 105 | 106 | CFLAGS = $(CFLAGS_D) -nologo -DHAVE_CONFIG_H=1 -DNT_DRIVER -D__BUILDMACHINE__=WinDDK \ 107 | -I$(DDK)\inc\$(OS) -I$(DDK)\inc\ddk\$(OS) -I$(DDK)\inc\ddk\wdm\$(OS) \ 108 | -I. -Ibnlib -Iinclude \ 109 | -I$(DDK)\inc\crt -I..\..\third_party\bnlib\config -I..\..\third_party\bnlib \ 110 | -I..\..\third_party\bgaes -I..\..\test\include -I..\..\include -I..\..\include\enterprise 111 | 112 | .c.obj : 113 | @$(CC) -c $(CFLAGS) $< /Fo$(OUT_DIR)/$( 7 | 8 | # 9 | # THIS MAKEFILE WORKS WITH MICROSOFT NMAKE ONLY 10 | # 11 | 12 | # change this to point to your DDK 13 | 14 | DDK = ..\..\..\..\winddk2003 15 | OS = wnet 16 | BASENAME = libzrtp 17 | BINPATH = $(DDK)\bin\win64\x86\amd64 18 | 19 | #RELEASE = 1 20 | 21 | CC = $(BINPATH)\cl 22 | ASM = $(BINPATH)\ml 23 | LIB = $(BINPATH)\lib 24 | 25 | all: $(BASENAME).lib 26 | 27 | # bnlib (the BigNumber engine) 28 | 29 | bnlib = \ 30 | ../../third_party/bnlib/bn.obj \ 31 | ../../third_party/bnlib/bn32.obj \ 32 | ../../third_party/bnlib/bninit32.obj \ 33 | ../../third_party/bnlib/lbn32.obj \ 34 | ../../third_party/bnlib/lbnmem.obj \ 35 | ../../third_party/bnlib/legal.obj 36 | 37 | protocol = \ 38 | ../../src/zrtp.obj \ 39 | ../../src/zrtp_crc.obj \ 40 | ../../src/zrtp_crypto_aes.obj \ 41 | ../../src/zrtp_crypto_atl.obj \ 42 | ../../src/zrtp_crypto_hash.obj \ 43 | ../../src/zrtp_crypto_pk.obj \ 44 | ../../src/zrtp_crypto_sas.obj \ 45 | ../../src/zrtp_datatypes.obj \ 46 | ../../src/zrtp_engine.obj \ 47 | ../../src/zrtp_iface_sys.obj \ 48 | ../../src/zrtp_initiator.obj \ 49 | ../../src/zrtp_legal.obj \ 50 | ../../src/zrtp_list.obj \ 51 | ../../src/zrtp_log.obj \ 52 | ../../src/zrtp_pbx.obj \ 53 | ../../src/zrtp_protocol.obj \ 54 | ../../src/zrtp_responder.obj \ 55 | ../../src/zrtp_rng.obj \ 56 | ../../src/zrtp_srtp_builtin.obj \ 57 | ../../src/zrtp_string.obj \ 58 | ../../src/zrtp_utils.obj \ 59 | ../../src/zrtp_utils_proto.obj 60 | 61 | bgaes = \ 62 | ../../third_party/bgaes/aes_modes.obj \ 63 | ../../third_party/bgaes/aescrypt.obj \ 64 | ../../third_party/bgaes/aeskey.obj \ 65 | ../../third_party/bgaes/aestab.obj \ 66 | ../../third_party/bgaes/sha1.obj \ 67 | ../../third_party/bgaes/sha2.obj 68 | 69 | OBJECTS = $(bnlib) $(protocol) $(bgaes) 70 | 71 | !IFNDEF RELEASE 72 | 73 | # Debug 74 | 75 | OUT_DIR = debug64.km 76 | 77 | DEFINES_D = -DWIN64=1 -D_WIN64=1 -D_AMD64_=1 -D_M_AMD64 -D_WINDOWS \ 78 | -DSTD_CALL -DCONDITION_HANDLING=1 \ 79 | -DNT_UP=1 -DNT_INST=0 -D_NT1X_=100 \ 80 | -DWINNT=1 -D_WIN32_WINNT=0x0500 -DWIN32_LEAN_AND_MEAN=1 -DDBG=1 -D_DEBUG -DDEBUG -DDEVL=1 \ 81 | -DFPO=0 -D_DLL=1 -D_IDWBUILD -DRDRDBG -DSRVDBG -DDBG_MESSAGES=1 \ 82 | -D_UNICODE -DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=0 83 | 84 | CFLAGS_D = $(DEFINES_D) -Zp8 -Gy -cbstring -Gz -Gm- -EHs-c- \ 85 | -GR- -GF -FI$(DDK)\inc\$(OS)\warning.h -Z7 -Od -Oi -Oy- -W3 86 | 87 | !ELSE 88 | 89 | # Release 90 | 91 | OUT_DIR = release64.km 92 | 93 | DEFINES_D = -DWIN64=1 -D_WIN64=1 -D_AMD64_=1 -D_M_AMD64 -D_WINDOWS \ 94 | -DSTD_CALL -DCONDITION_HANDLING=1 \ 95 | -DNT_UP=1 -DNO_DISK_ACCESS -DNT_INST=0 -DWIN32=100 -D_NT1X_=100 \ 96 | -DWINNT=1 -D_WIN32_WINNT=0x0500 -DWIN32_LEAN_AND_MEAN=1 -DDEVL=1 \ 97 | -DFPO=1 -DNDEBUG -D_DLL=1 -D_IDWBUILD -D_UNICODE \ 98 | -DLITTLE_ENDIAN -DZRTP_USE_ENTERPRISE=0 99 | 100 | CFLAGS_D = $(DEFINES_D) -Zel -Zp8 -Gy -cbstring -Gz -QIfdiv- -QIf -Gi- -Gm- -GX- \ 101 | -GR- -GF -Oxs -Oy -FI$(DDK)\inc\$(OS)\warning.h -W3 -FAcs -Z7 102 | 103 | !ENDIF 104 | 105 | ASM = ml 106 | AFLAGS = /c /Cx /coff /Zi 107 | AINCLUDE = -I. -I$(DDK)\inc 108 | 109 | CFLAGS = $(CFLAGS_D) -nologo -DHAVE_CONFIG_H=1 -DNT_DRIVER -D__BUILDMACHINE__=WinDDK \ 110 | -I$(DDK)\inc\$(OS) -I$(DDK)\inc\ddk\$(OS) -I$(DDK)\inc\ddk\wdm\$(OS) \ 111 | -I$(DDK)\inc\crt -I..\..\third_party\bnlib\config -I..\..\third_party\bnlib \ 112 | -I..\..\third_party\bgaes -I..\..\test\include -I..\..\include -I..\..\include\enterprise 113 | 114 | .c.obj : 115 | @$(CC) -c $(CFLAGS) $< /Fo$(OUT_DIR)/$( 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/zrtp_b64_decode.c: -------------------------------------------------------------------------------- 1 | /* 2 | cdecoder.c - c source to a base64 decoding algorithm implementation 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #include 9 | 10 | int base64_decode_value(char value_in) 11 | { 12 | static const char decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51}; 13 | static const char decoding_size = sizeof(decoding); 14 | value_in -= 43; 15 | if (value_in < 0 || value_in > decoding_size) return -1; 16 | return decoding[(int)value_in]; 17 | } 18 | 19 | void base64_init_decodestate(base64_decodestate* state_in) 20 | { 21 | state_in->step = step_a; 22 | state_in->plainchar = 0; 23 | } 24 | 25 | int base64_decode_block(const char* code_in, const int length_in, uint8_t *plaintext_out, base64_decodestate* state_in) 26 | { 27 | const char* codechar = code_in; 28 | uint8_t *plainchar = plaintext_out; 29 | char fragment; 30 | 31 | *plainchar = state_in->plainchar; 32 | 33 | switch (state_in->step) 34 | { 35 | while (1) 36 | { 37 | case step_a: 38 | do { 39 | if (codechar == code_in+length_in) 40 | { 41 | state_in->step = step_a; 42 | state_in->plainchar = *plainchar; 43 | return plainchar - plaintext_out; 44 | } 45 | fragment = (char)base64_decode_value(*codechar++); 46 | } while (fragment < 0); 47 | *plainchar = (fragment & 0x03f) << 2; 48 | case step_b: 49 | do { 50 | if (codechar == code_in+length_in) 51 | { 52 | state_in->step = step_b; 53 | state_in->plainchar = *plainchar; 54 | return plainchar - plaintext_out; 55 | } 56 | fragment = (char)base64_decode_value(*codechar++); 57 | } while (fragment < 0); 58 | *plainchar++ |= (fragment & 0x030) >> 4; 59 | *plainchar = (fragment & 0x00f) << 4; 60 | case step_c: 61 | do { 62 | if (codechar == code_in+length_in) 63 | { 64 | state_in->step = step_c; 65 | state_in->plainchar = *plainchar; 66 | return plainchar - plaintext_out; 67 | } 68 | fragment = (char)base64_decode_value(*codechar++); 69 | } while (fragment < 0); 70 | *plainchar++ |= (fragment & 0x03c) >> 2; 71 | *plainchar = (fragment & 0x003) << 6; 72 | case step_d: 73 | do { 74 | if (codechar == code_in+length_in) 75 | { 76 | state_in->step = step_d; 77 | state_in->plainchar = *plainchar; 78 | return plainchar - plaintext_out; 79 | } 80 | fragment = (char)base64_decode_value(*codechar++); 81 | } while (fragment < 0); 82 | *plainchar++ |= (fragment & 0x03f); 83 | } 84 | } 85 | /* control should not reach here */ 86 | return plainchar - plaintext_out; 87 | } 88 | 89 | -------------------------------------------------------------------------------- /src/zrtp_b64_encode.c: -------------------------------------------------------------------------------- 1 | /* 2 | cencoder.c - c source to a base64 encoding algorithm implementation 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #include 9 | 10 | const int CHARS_PER_LINE = 72; 11 | 12 | void base64_init_encodestate(base64_encodestate* state_in, int lineLength) 13 | { 14 | state_in->step = step_A; 15 | state_in->result = 0; 16 | state_in->stepcount = 0; 17 | if (lineLength < 0) 18 | state_in->lineLength = CHARS_PER_LINE / 4; 19 | else 20 | state_in->lineLength = (lineLength+3) / 4; 21 | } 22 | 23 | char base64_encode_value(const int8_t value_in) 24 | { 25 | static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 26 | if (value_in > 63) return '='; 27 | return encoding[(int)value_in]; 28 | } 29 | 30 | int base64_encode_block(const uint8_t *plaintext_in, int length_in, char* code_out, base64_encodestate* state_in) 31 | { 32 | const uint8_t *plainchar = plaintext_in; 33 | const uint8_t *const plaintextend = plaintext_in + length_in; 34 | char* codechar = code_out; 35 | char result; 36 | char fragment; 37 | 38 | result = state_in->result; 39 | 40 | switch (state_in->step) 41 | { 42 | while (1) 43 | { 44 | case step_A: 45 | if (plainchar == plaintextend) 46 | { 47 | state_in->result = result; 48 | state_in->step = step_A; 49 | return codechar - code_out; 50 | } 51 | fragment = *plainchar++; 52 | result = (fragment & 0x0fc) >> 2; 53 | *codechar++ = base64_encode_value(result); 54 | result = (fragment & 0x003) << 4; 55 | case step_B: 56 | if (plainchar == plaintextend) 57 | { 58 | state_in->result = result; 59 | state_in->step = step_B; 60 | return codechar - code_out; 61 | } 62 | fragment = *plainchar++; 63 | result |= (fragment & 0x0f0) >> 4; 64 | *codechar++ = base64_encode_value(result); 65 | result = (fragment & 0x00f) << 2; 66 | case step_C: 67 | if (plainchar == plaintextend) 68 | { 69 | state_in->result = result; 70 | state_in->step = step_C; 71 | return codechar - code_out; 72 | } 73 | fragment = *plainchar++; 74 | result |= (fragment & 0x0c0) >> 6; 75 | *codechar++ = base64_encode_value(result); 76 | result = (fragment & 0x03f) >> 0; 77 | *codechar++ = base64_encode_value(result); 78 | 79 | if (state_in->lineLength > 0) { 80 | state_in->stepcount++; 81 | if (state_in->stepcount == state_in->lineLength) 82 | { 83 | *codechar++ = '\n'; 84 | state_in->stepcount = 0; 85 | } 86 | } 87 | } 88 | } 89 | /* control should not reach here */ 90 | return codechar - code_out; 91 | } 92 | 93 | int base64_encode_blockend(char* code_out, base64_encodestate* state_in) 94 | { 95 | char* codechar = code_out; 96 | 97 | switch (state_in->step) 98 | { 99 | case step_B: 100 | *codechar++ = base64_encode_value(state_in->result); 101 | *codechar++ = '='; 102 | *codechar++ = '='; 103 | break; 104 | case step_C: 105 | *codechar++ = base64_encode_value(state_in->result); 106 | *codechar++ = '='; 107 | break; 108 | case step_A: 109 | break; 110 | } 111 | if (state_in->lineLength > 0) 112 | *codechar++ = '\n'; 113 | 114 | return codechar - code_out; 115 | } 116 | 117 | -------------------------------------------------------------------------------- /src/zrtp_crypto_atl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #include "zrtp.h" 11 | 12 | 13 | /*============================================================================*/ 14 | /* SRTP Auth Tag Length support */ 15 | /*============================================================================*/ 16 | 17 | zrtp_status_t zrtp_defaults_atl(zrtp_global_t* global_ctx) 18 | { 19 | zrtp_auth_tag_length_t* atl32 = zrtp_sys_alloc(sizeof(zrtp_auth_tag_length_t)); 20 | zrtp_auth_tag_length_t* atl80 = zrtp_sys_alloc(sizeof(zrtp_auth_tag_length_t)); 21 | 22 | if (!atl32 || !atl80) { 23 | if(atl32) zrtp_sys_free(atl32); 24 | if(atl80) zrtp_sys_free(atl80); 25 | return zrtp_status_alloc_fail; 26 | } 27 | 28 | zrtp_memset(atl32, 0, sizeof(zrtp_auth_tag_length_t)); 29 | zrtp_memcpy(atl32->base.type, ZRTP_HS32, ZRTP_COMP_TYPE_SIZE); 30 | atl32->base.id = ZRTP_ATL_HS32; 31 | atl32->base.zrtp = global_ctx; 32 | atl32->tag_length = 4; 33 | 34 | zrtp_memset(atl80, 0, sizeof(zrtp_auth_tag_length_t)); 35 | zrtp_memcpy(atl80->base.type, ZRTP_HS80, ZRTP_COMP_TYPE_SIZE); 36 | atl80->base.id = ZRTP_ATL_HS80; 37 | atl80->base.zrtp = global_ctx; 38 | atl80->tag_length = 10; 39 | 40 | zrtp_comp_register(ZRTP_CC_ATL, atl32, global_ctx); 41 | zrtp_comp_register(ZRTP_CC_ATL, atl80, global_ctx); 42 | 43 | return zrtp_status_ok; 44 | } 45 | -------------------------------------------------------------------------------- /src/zrtp_datatypes.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #include "zrtp.h" 11 | 12 | /*---------------------------------------------------------------------------*/ 13 | void zrtp_bitmap_right_shift(uint8_t *x, int width_bytes, int index) 14 | { 15 | const int base_index = index >> 3; 16 | const int bit_index = index & 7; 17 | int i, from; 18 | uint8_t b; 19 | 20 | if (index > width_bytes*8) { 21 | for(i=0; i < width_bytes; i++) { 22 | x[i] = 0; 23 | } 24 | return; 25 | } 26 | 27 | if (bit_index == 0) { 28 | /* copy each word from left side to right side */ 29 | x[width_bytes-1] = x[width_bytes-1-base_index]; 30 | for (i=width_bytes-1; i > base_index; i--) { 31 | x[i-1] = x[i-1-base_index]; 32 | } 33 | } else { 34 | /* set each word to the OR of the two bit-shifted words */ 35 | for (i = width_bytes; i > base_index; i--) { 36 | from = i-1 - base_index; 37 | b = x[from] << bit_index; 38 | if (from > 0) { 39 | b |= x[from-1] >> (8-bit_index); 40 | } 41 | x[i-1] = b; 42 | } 43 | } 44 | 45 | /* now wrap up the final portion */ 46 | for (i=0; i < base_index; i++) { 47 | x[i] = 0; 48 | } 49 | } 50 | 51 | /*---------------------------------------------------------------------------*/ 52 | void zrtp_bitmap_left_shift(uint8_t *x, int width_bytes, int index) 53 | { 54 | int i; 55 | const int base_index = index >> 3; 56 | const int bit_index = index & 7; 57 | 58 | if (index > width_bytes*8) { 59 | for(i=0; i < width_bytes; i++) { 60 | x[i] = 0; 61 | } 62 | return; 63 | } 64 | 65 | if (0 == bit_index) { 66 | for (i=0; i < width_bytes - base_index; i++) { 67 | x[i] = x[i+base_index]; 68 | } 69 | } else { 70 | for (i=0; i < width_bytes - base_index - 1; i++) { 71 | x[i] = (x[i+base_index] >> bit_index) ^ (x[i+base_index+1] << (8 - bit_index)); 72 | } 73 | 74 | x[width_bytes - base_index-1] = x[width_bytes-1] >> bit_index; 75 | } 76 | 77 | /* now wrap up the final portion */ 78 | for (i = width_bytes - base_index; i < width_bytes; i++) { 79 | x[i] = 0; 80 | } 81 | } 82 | 83 | void zrtp_v128_xor(zrtp_v128_t *z, zrtp_v128_t *x, zrtp_v128_t *y) 84 | { 85 | _zrtp_v128_xor(z, x, y); 86 | } 87 | 88 | /*---------------------------------------------------------------------------*/ 89 | uint16_t zrtp_swap16(uint16_t x) { 90 | return (x >> 8 | x << 8); 91 | } 92 | 93 | uint32_t zrtp_swap32(uint32_t x) 94 | { 95 | uint32_t res = (x >> 8 & 0x0000ff00) | (x << 8 & 0x00ff0000); 96 | res |= (x >> 24 ) | (x << 24); 97 | return res; 98 | } 99 | 100 | #ifdef ZRTP_NO_64BIT_MATH 101 | uint64_t zrtp_swap64(uint64_t x) 102 | { 103 | uint8_t *p = &x; 104 | uint8_t tmp; 105 | int i; 106 | 107 | for(i=0; i<4; i++) { 108 | tmp = p[i]; 109 | p[i] = p[7-i]; 110 | p[7-i] = tmp; 111 | } 112 | return x; 113 | } 114 | #else 115 | uint64_t zrtp_swap64(uint64_t x) 116 | { 117 | uint64_t res; 118 | res = (x >> 8 & 0x00000000ff000000ll) | (x << 8 & 0x000000ff00000000ll); 119 | res |= (x >> 24 & 0x0000000000ff0000ll) | (x << 24 & 0x0000ff0000000000ll); 120 | res |= (x >> 40 & 0x000000000000ff00ll) | (x << 40 & 0x00ff000000000000ll); 121 | res |= (x >> 56 & 0x00000000000000ffll) | (x << 56 & 0xff00000000000000ll); 122 | return res; 123 | } 124 | #endif /* ZRTP_NO_64BIT_MATH */ 125 | -------------------------------------------------------------------------------- /src/zrtp_list.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #include "zrtp.h" 11 | 12 | /*----------------------------------------------------------------------------*/ 13 | void init_mlist(mlist_t* head) { 14 | head->next = head; 15 | head->prev = head; 16 | } 17 | 18 | /*----------------------------------------------------------------------------*/ 19 | static void mlist_insert_node(mlist_t* node, mlist_t* prev, mlist_t* next) { 20 | next->prev = node; 21 | node->next = next; 22 | node->prev = prev; 23 | prev->next = node; 24 | } 25 | 26 | void mlist_insert(mlist_t *prev, mlist_t *node) { 27 | mlist_insert_node(node, prev->prev, prev); 28 | } 29 | 30 | void mlist_add(mlist_t* head, mlist_t* node) { 31 | mlist_insert_node(node, head, head->next); 32 | } 33 | 34 | void mlist_add_tail(mlist_t *head, mlist_t *node) { 35 | mlist_insert_node(node, head->prev, head); 36 | } 37 | 38 | /*----------------------------------------------------------------------------*/ 39 | static void mlist_remove(mlist_t* prev, mlist_t* next) { 40 | next->prev = prev; 41 | prev->next = next; 42 | } 43 | 44 | void mlist_del(mlist_t *node) { 45 | mlist_remove(node->prev, node->next); 46 | node->next = node->prev = 0; 47 | } 48 | 49 | void mlist_del_tail(mlist_t *node) { 50 | mlist_remove(node->prev, node->next); 51 | node->next = node->prev = 0; 52 | } 53 | 54 | /*----------------------------------------------------------------------------*/ 55 | mlist_t* mlist_get(mlist_t *head) { 56 | return (head->next != head) ? head->next : 0; 57 | } 58 | 59 | mlist_t* mlist_get_tail(mlist_t *head) { 60 | return (head->prev != head) ? head->prev : 0; 61 | } 62 | 63 | /*----------------------------------------------------------------------------*/ 64 | int mlist_isempty(mlist_t *head) { 65 | return (head->next == head); 66 | } 67 | -------------------------------------------------------------------------------- /test/cipher_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #include "zrtp.h" 14 | #include "cmockery/cmockery.h" 15 | 16 | zrtp_global_t *zrtp; 17 | 18 | void setup() { 19 | zrtp_status_t s; 20 | zrtp_config_t zrtp_config; 21 | 22 | zrtp_config_defaults(&zrtp_config); 23 | 24 | s = zrtp_init(&zrtp_config, &zrtp); 25 | assert_int_equal(s, zrtp_status_ok); 26 | } 27 | 28 | void teardown() { 29 | zrtp_down(zrtp); 30 | } 31 | 32 | static void aes128_ctr_test() { 33 | zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES128, zrtp); 34 | assert_non_null(cipher); 35 | cipher->self_test(cipher, ZRTP_CIPHER_MODE_CTR); 36 | } 37 | 38 | static void aes128_cfb_test() { 39 | zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES128, zrtp); 40 | assert_non_null(cipher); 41 | cipher->self_test(cipher, ZRTP_CIPHER_MODE_CFB); 42 | } 43 | 44 | static void aes256_ctr_test() { 45 | zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES256, zrtp); 46 | assert_non_null(cipher); 47 | cipher->self_test(cipher, ZRTP_CIPHER_MODE_CTR); 48 | } 49 | 50 | static void aes256_cfb_test() { 51 | zrtp_cipher_t *cipher = zrtp_comp_find(ZRTP_CC_CIPHER, ZRTP_CIPHER_AES256, zrtp); 52 | assert_non_null(cipher); 53 | cipher->self_test(cipher, ZRTP_CIPHER_MODE_CFB); 54 | } 55 | 56 | int main(void) { 57 | const UnitTest tests[] = { 58 | unit_test_setup_teardown(aes128_ctr_test, setup, teardown), 59 | unit_test_setup_teardown(aes128_cfb_test, setup, teardown), 60 | unit_test_setup_teardown(aes256_ctr_test, setup, teardown), 61 | unit_test_setup_teardown(aes256_cfb_test, setup, teardown), 62 | }; 63 | 64 | return run_tests(tests); 65 | } 66 | -------------------------------------------------------------------------------- /test/dh_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #include "zrtp.h" 14 | #include "cmockery/cmockery.h" 15 | 16 | zrtp_global_t *zrtp; 17 | 18 | void setup() { 19 | zrtp_status_t s; 20 | zrtp_config_t zrtp_config; 21 | 22 | zrtp_config_defaults(&zrtp_config); 23 | 24 | s = zrtp_init(&zrtp_config, &zrtp); 25 | assert_int_equal(s, zrtp_status_ok); 26 | } 27 | 28 | void teardown() { 29 | zrtp_down(zrtp); 30 | } 31 | 32 | static void dh2k_test() { 33 | zrtp_pk_scheme_t *pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_DH2048, zrtp); 34 | assert_non_null(pks); 35 | pks->self_test(pks); 36 | } 37 | 38 | static void dh3k_test() { 39 | zrtp_pk_scheme_t *pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_DH3072, zrtp); 40 | assert_non_null(pks); 41 | pks->self_test(pks); 42 | } 43 | 44 | 45 | int main(void) { 46 | const UnitTest tests[] = { 47 | unit_test_setup_teardown(dh2k_test, setup, teardown), 48 | unit_test_setup_teardown(dh3k_test, setup, teardown), 49 | }; 50 | 51 | return run_tests(tests); 52 | } 53 | -------------------------------------------------------------------------------- /test/dk_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #include "zrtp.h" 14 | #include "cmockery/cmockery.h" 15 | 16 | zrtp_global_t *zrtp; 17 | 18 | extern zrtp_dk_ctx *zrtp_dk_init(zrtp_cipher_t *cipher, zrtp_stringn_t *key, zrtp_stringn_t *salt); 19 | extern zrtp_status_t zrtp_derive_key(zrtp_dk_ctx *ctx, zrtp_srtp_prf_label label, zrtp_stringn_t *result_key); 20 | extern void zrtp_dk_deinit(zrtp_dk_ctx *ctx); 21 | 22 | static uint8_t dk_master_key[16] = { 23 | 0xE1, 0xF9, 0x7A, 0x0D, 0x3E, 0x01, 0x8B, 0xE0, 24 | 0xD6, 0x4F, 0xA3, 0x2C, 0x06, 0xDE, 0x41, 0x39 25 | }; 26 | 27 | static uint8_t dk_master_salt[14] = { 28 | 0x0E, 0xC6, 0x75, 0xAD, 0x49, 0x8A, 0xFE, 0xEB, 29 | 0xB6, 0x96, 0x0B, 0x3A, 0xAB, 0xE6 30 | }; 31 | 32 | 33 | static uint8_t dk_cipher_key[16] = { 34 | 0xC6, 0x1E, 0x7A, 0x93, 0x74, 0x4F, 0x39, 0xEE, 35 | 0x10, 0x73, 0x4A, 0xFE, 0x3F, 0xF7, 0xA0, 0x87 36 | }; 37 | 38 | static uint8_t dk_cipher_salt[14] = { 39 | 0x30, 0xCB, 0xBC, 0x08, 0x86, 0x3D, 0x8C, 0x85, 40 | 0xD4, 0x9D, 0xB3, 0x4A, 0x9A, 0xE1 41 | }; 42 | 43 | static uint8_t dk_auth_key[94] = { 44 | 0xCE, 0xBE, 0x32, 0x1F, 0x6F, 0xF7, 0x71, 0x6B, 45 | 0x6F, 0xD4, 0xAB, 0x49, 0xAF, 0x25, 0x6A, 0x15, 46 | 0x6D, 0x38, 0xBA, 0xA4, 0x8F, 0x0A, 0x0A, 0xCF, 47 | 0x3C, 0x34, 0xE2, 0x35, 0x9E, 0x6C, 0xDB, 0xCE, 48 | 0xE0, 0x49, 0x64, 0x6C, 0x43, 0xD9, 0x32, 0x7A, 49 | 0xD1, 0x75, 0x57, 0x8E, 0xF7, 0x22, 0x70, 0x98, 50 | 0x63, 0x71, 0xC1, 0x0C, 0x9A, 0x36, 0x9A, 0xC2, 51 | 0xF9, 0x4A, 0x8C, 0x5F, 0xBC, 0xDD, 0xDC, 0x25, 52 | 0x6D, 0x6E, 0x91, 0x9A, 0x48, 0xB6, 0x10, 0xEF, 53 | 0x17, 0xC2, 0x04, 0x1E, 0x47, 0x40, 0x35, 0x76, 54 | 0x6B, 0x68, 0x64, 0x2C, 0x59, 0xBB, 0xFC, 0x2F, 55 | 0x34, 0xDB, 0x60, 0xDB, 0xDF, 0xB2 56 | }; 57 | 58 | 59 | void setup() { 60 | zrtp_status_t s; 61 | zrtp_config_t zrtp_config; 62 | 63 | zrtp_config_defaults(&zrtp_config); 64 | 65 | s = zrtp_init(&zrtp_config, &zrtp); 66 | assert_int_equal(s, zrtp_status_ok); 67 | } 68 | 69 | void teardown() { 70 | zrtp_down(zrtp); 71 | } 72 | 73 | zrtp_status_t hex_cmp(uint8_t *a, uint8_t *b, uint32_t len) 74 | { 75 | uint32_t i; 76 | zrtp_status_t res = zrtp_status_ok; 77 | for (i = 0; i 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #include "zrtp.h" 14 | #include "cmockery/cmockery.h" 15 | 16 | zrtp_global_t *zrtp; 17 | 18 | void setup() { 19 | zrtp_status_t s; 20 | zrtp_config_t zrtp_config; 21 | 22 | zrtp_config_defaults(&zrtp_config); 23 | 24 | s = zrtp_init(&zrtp_config, &zrtp); 25 | assert_int_equal(s, zrtp_status_ok); 26 | } 27 | 28 | void teardown() { 29 | zrtp_down(zrtp); 30 | } 31 | 32 | 33 | static void ecdh256_test() { 34 | zrtp_pk_scheme_t *pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_EC256P, zrtp); 35 | assert_non_null(pks); 36 | pks->self_test(pks); 37 | } 38 | 39 | static void ecdh384_test() { 40 | zrtp_pk_scheme_t *pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_EC384P, zrtp); 41 | assert_non_null(pks); 42 | pks->self_test(pks); 43 | } 44 | 45 | static void ecdh512_test() { 46 | zrtp_pk_scheme_t *pks = zrtp_comp_find(ZRTP_CC_PKT, ZRTP_PKTYPE_EC521P, zrtp); 47 | assert_non_null(pks); 48 | pks->self_test(pks); 49 | } 50 | 51 | 52 | int main(void) { 53 | const UnitTest tests[] = { 54 | unit_test_setup_teardown(ecdh256_test, setup, teardown), 55 | unit_test_setup_teardown(ecdh384_test, setup, teardown), 56 | unit_test_setup_teardown(ecdh512_test, setup, teardown), 57 | }; 58 | 59 | return run_tests(tests); 60 | } 61 | -------------------------------------------------------------------------------- /test/engine_helpers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #include /*chmockery dependency*/ 11 | #include /*chmockery dependency*/ 12 | #include /*for usleep*/ 13 | 14 | #include "cmockery/cmockery.h" 15 | #include "test_engine.h" 16 | 17 | static zrtp_test_id_t g_alice, g_bob; 18 | static zrtp_test_id_t g_alice_sid, g_bob_sid; 19 | static zrtp_test_id_t g_secure_audio_channel; 20 | 21 | 22 | static void prepare_alice_bob() { 23 | zrtp_status_t s; 24 | 25 | zrtp_test_session_cfg_t session_config; 26 | zrtp_test_session_config_defaults(&session_config); 27 | 28 | /* 29 | * Create two test sessions, one for Alice and one for Bob and link them 30 | * into test secure channel 31 | */ 32 | s = zrtp_test_session_create(g_alice, &session_config, &g_alice_sid); 33 | assert_int_equal(zrtp_status_ok, s); 34 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice_sid); 35 | 36 | s = zrtp_test_session_create(g_bob, &session_config, &g_bob_sid); 37 | assert_int_equal(zrtp_status_ok, s); 38 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob_sid); 39 | 40 | s = zrtp_test_channel_create2(g_alice_sid, g_bob_sid, 0, &g_secure_audio_channel); 41 | assert_int_equal(zrtp_status_ok, s); 42 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_secure_audio_channel); 43 | } 44 | 45 | static void release_alice_bob() { 46 | zrtp_test_session_destroy(g_alice_sid); 47 | zrtp_test_session_destroy(g_bob_sid); 48 | 49 | zrtp_test_channel_destroy(g_secure_audio_channel); 50 | } 51 | 52 | static void start_alice_bob_and_wait4secure() { 53 | zrtp_status_t s; 54 | zrtp_test_channel_info_t channel_info; 55 | 56 | /* Everything is ready. Let's start the stream and give it few seconds to switch secure. */ 57 | s = zrtp_test_channel_start(g_secure_audio_channel); 58 | assert_int_equal(zrtp_status_ok, s); 59 | 60 | unsigned i = 30; 61 | for (; i>0; i--) { 62 | usleep(100*1000); 63 | } 64 | 65 | s = zrtp_test_channel_get(g_secure_audio_channel, &channel_info); 66 | assert_int_equal(zrtp_status_ok, s); 67 | 68 | assert_true(channel_info.is_secure); 69 | } 70 | -------------------------------------------------------------------------------- /test/enroll_test_helpers.c: -------------------------------------------------------------------------------- 1 | 2 | static zrtp_test_id_t g_alice, g_bob, g_pbx; 3 | static zrtp_test_id_t g_alice_sid, g_bob_sid, g_pbxa_sid, g_pbxb_sid; 4 | static zrtp_test_id_t g_alice2pbx_channel, g_bob2pbx_channel; 5 | 6 | static void pbx_setup() { 7 | zrtp_status_t s; 8 | 9 | zrtp_test_endpoint_cfg_t endpoint_cfg; 10 | zrtp_test_endpoint_config_defaults(&endpoint_cfg); 11 | 12 | s = zrtp_test_endpoint_create(&endpoint_cfg, "Alice", &g_alice); 13 | assert_int_equal(zrtp_status_ok, s); 14 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice); 15 | 16 | s = zrtp_test_endpoint_create(&endpoint_cfg, "Bob", &g_bob); 17 | assert_int_equal(zrtp_status_ok, s); 18 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob); 19 | 20 | endpoint_cfg.zrtp.is_mitm = 1; 21 | s = zrtp_test_endpoint_create(&endpoint_cfg, "PBX", &g_pbx); 22 | assert_int_equal(zrtp_status_ok, s); 23 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_pbx); 24 | } 25 | 26 | static void pbx_teardown() { 27 | zrtp_test_endpoint_destroy(g_alice); 28 | zrtp_test_endpoint_destroy(g_bob); 29 | zrtp_test_endpoint_destroy(g_pbx); 30 | } 31 | 32 | 33 | static void prepare_alice_pbx_bob_setup(zrtp_test_session_cfg_t *alice_sconfig, 34 | zrtp_test_session_cfg_t *bob_sconfig, 35 | zrtp_test_session_cfg_t *pbxa_sconfig, 36 | zrtp_test_session_cfg_t *pbxb_sconfig) { 37 | zrtp_status_t s; 38 | 39 | if (alice_sconfig) { 40 | assert_non_null(pbxa_sconfig); 41 | 42 | s = zrtp_test_session_create(g_alice, alice_sconfig, &g_alice_sid); 43 | assert_int_equal(zrtp_status_ok, s); 44 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice_sid); 45 | 46 | s = zrtp_test_session_create(g_pbx, pbxa_sconfig, &g_pbxa_sid); 47 | assert_int_equal(zrtp_status_ok, s); 48 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_pbxa_sid); 49 | 50 | s = zrtp_test_channel_create2(g_alice_sid, g_pbxa_sid, 0, &g_alice2pbx_channel); 51 | assert_int_equal(zrtp_status_ok, s); 52 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice2pbx_channel); 53 | } 54 | 55 | if (bob_sconfig) { 56 | assert_non_null(pbxb_sconfig); 57 | 58 | s = zrtp_test_session_create(g_bob, bob_sconfig, &g_bob_sid); 59 | assert_int_equal(zrtp_status_ok, s); 60 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob_sid); 61 | 62 | s = zrtp_test_session_create(g_pbx, pbxb_sconfig, &g_pbxb_sid); 63 | assert_int_equal(zrtp_status_ok, s); 64 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_pbxb_sid); 65 | 66 | s = zrtp_test_channel_create2(g_bob_sid, g_pbxb_sid, 0, &g_bob2pbx_channel); 67 | assert_int_equal(zrtp_status_ok, s); 68 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob2pbx_channel); 69 | } 70 | } 71 | 72 | static void cleanup_alice_pbx_bob_setup() { 73 | zrtp_test_session_destroy(g_alice_sid); 74 | zrtp_test_session_destroy(g_bob_sid); 75 | zrtp_test_session_destroy(g_pbxa_sid); 76 | zrtp_test_session_destroy(g_pbxb_sid); 77 | 78 | zrtp_test_channel_destroy(g_alice2pbx_channel); 79 | zrtp_test_channel_destroy(g_bob2pbx_channel); 80 | } 81 | 82 | -------------------------------------------------------------------------------- /test/enrollment_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #include /*chmockery dependency*/ 11 | #include /*chmockery dependency*/ 12 | #include /*for usleep*/ 13 | 14 | #include "cmockery/cmockery.h" 15 | #include "test_engine.h" 16 | 17 | #include "enroll_test_helpers.c" 18 | 19 | static void enrollment_test() { 20 | zrtp_status_t s; 21 | 22 | zrtp_test_channel_info_t a2pbx_channel_info; 23 | zrtp_test_session_cfg_t session_config, session_config_enroll; 24 | zrtp_test_session_config_defaults(&session_config); 25 | zrtp_test_session_config_defaults(&session_config_enroll); 26 | 27 | session_config_enroll.is_enrollment = 1; 28 | 29 | /************************************************************************** 30 | * Enroll Alice to PBX and check triggered events. 31 | */ 32 | prepare_alice_pbx_bob_setup(&session_config, NULL, &session_config_enroll, NULL); 33 | 34 | /* Everything is ready. Let's start the stream and give it few seconds to switch secure. */ 35 | s = zrtp_test_channel_start(g_alice2pbx_channel); 36 | assert_int_equal(zrtp_status_ok, s); 37 | 38 | int i = 30; 39 | for (; i>0; i--) { 40 | usleep(100*1000); 41 | } 42 | 43 | s = zrtp_test_channel_get(g_alice2pbx_channel, &a2pbx_channel_info); 44 | assert_int_equal(zrtp_status_ok, s); 45 | 46 | /* Both, Alice and PBX should switch secure */ 47 | assert_true(a2pbx_channel_info.is_secure); 48 | 49 | /* Alice should receive Enrollment notification */ 50 | zrtp_test_id_t alice2pbx_stream = zrtp_test_session_get_stream_by_idx(g_alice_sid, 0); 51 | assert_true(zrtp_stream_did_event_receive(alice2pbx_stream, ZRTP_EVENT_IS_CLIENT_ENROLLMENT)); 52 | 53 | /* PBX streams should receive incoming enrollment notification */ 54 | zrtp_test_id_t pbx2alice_stream = zrtp_test_session_get_stream_by_idx(g_pbxa_sid, 0); 55 | assert_true(zrtp_stream_did_event_receive(pbx2alice_stream, ZRTP_EVENT_NEW_USER_ENROLLED)); 56 | 57 | /* Confirm enrollment at the PBX side */ 58 | s = zrtp_register_with_trusted_mitm(zrtp_stream_for_test_stream(alice2pbx_stream)); 59 | assert_int_equal(zrtp_status_ok, s); 60 | 61 | /* Clean-up */ 62 | cleanup_alice_pbx_bob_setup(); 63 | 64 | /************************************************************************** 65 | * Try to make one more enrollment call. This time it should say "Already enrolled" 66 | */ 67 | prepare_alice_pbx_bob_setup(&session_config, NULL, &session_config_enroll, NULL); 68 | 69 | /* Everything is ready. Let's start the stream and give it few seconds to switch secure. */ 70 | s = zrtp_test_channel_start(g_alice2pbx_channel); 71 | assert_int_equal(zrtp_status_ok, s); 72 | 73 | i = 30; 74 | for (; i>0; i--) { 75 | usleep(100*1000); 76 | } 77 | 78 | s = zrtp_test_channel_get(g_alice2pbx_channel, &a2pbx_channel_info); 79 | assert_int_equal(zrtp_status_ok, s); 80 | 81 | assert_true(a2pbx_channel_info.is_secure); 82 | 83 | /* Alice should receive Enrollment notification */ 84 | alice2pbx_stream = zrtp_test_session_get_stream_by_idx(g_alice_sid, 0); 85 | assert_true(zrtp_stream_did_event_receive(alice2pbx_stream, ZRTP_EVENT_IS_CLIENT_ENROLLMENT)); 86 | 87 | /* PBX streams should receive incoming enrollment notification */ 88 | pbx2alice_stream = zrtp_test_session_get_stream_by_idx(g_pbxa_sid, 0); 89 | assert_true(zrtp_stream_did_event_receive(pbx2alice_stream, ZRTP_EVENT_USER_ALREADY_ENROLLED)); 90 | 91 | // TODO: check if we have PBX secret cached 92 | // TODO: test zrtp_is_user_enrolled() 93 | } 94 | 95 | int main(void) { 96 | const UnitTest tests[] = { 97 | unit_test_setup_teardown(enrollment_test, pbx_setup, pbx_teardown), 98 | }; 99 | 100 | return run_tests(tests); 101 | } 102 | -------------------------------------------------------------------------------- /test/go_secure_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #include "engine_helpers.c" 11 | 12 | static void setup() { 13 | zrtp_status_t s; 14 | 15 | zrtp_test_endpoint_cfg_t endpoint_cfg; 16 | zrtp_test_endpoint_config_defaults(&endpoint_cfg); 17 | 18 | s = zrtp_test_endpoint_create(&endpoint_cfg, "Alice", &g_alice); 19 | assert_int_equal(zrtp_status_ok, s); 20 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice); 21 | 22 | s = zrtp_test_endpoint_create(&endpoint_cfg, "Bob", &g_bob); 23 | assert_int_equal(zrtp_status_ok, s); 24 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob); 25 | } 26 | 27 | static void teardown() { 28 | zrtp_test_endpoint_destroy(g_alice); 29 | zrtp_test_endpoint_destroy(g_bob); 30 | } 31 | 32 | 33 | static void go_secure_test() { 34 | /* 35 | * Create two test sessions, one for Alice and one for Bob and link them 36 | * into test secure channel 37 | */ 38 | prepare_alice_bob(); 39 | start_alice_bob_and_wait4secure(); 40 | release_alice_bob(); 41 | } 42 | 43 | static void go_secure_flags_test() { 44 | zrtp_status_t s; 45 | zrtp_test_session_info_t alice_ses_info; 46 | 47 | prepare_alice_bob(); 48 | 49 | start_alice_bob_and_wait4secure(); 50 | 51 | /* All flags should be clear */ 52 | s = zrtp_test_session_get(g_alice_sid, &alice_ses_info); 53 | assert_int_equal(zrtp_status_ok, s); 54 | 55 | assert_int_equal(0, alice_ses_info.zrtp.matches_flags); 56 | assert_int_equal(0, alice_ses_info.zrtp.cached_flags); 57 | assert_int_equal(0, alice_ses_info.zrtp.wrongs_flags); 58 | 59 | /* 60 | * Now let's make one more call, RS1 should match and cached 61 | */ 62 | release_alice_bob(); 63 | 64 | prepare_alice_bob(); 65 | 66 | start_alice_bob_and_wait4secure(); 67 | 68 | s = zrtp_test_session_get(g_alice_sid, &alice_ses_info); 69 | assert_int_equal(zrtp_status_ok, s); 70 | 71 | assert_int_equal((int)ZRTP_BIT_RS1, alice_ses_info.zrtp.matches_flags); 72 | assert_int_equal((int)ZRTP_BIT_RS1, alice_ses_info.zrtp.cached_flags); 73 | assert_int_equal(0, alice_ses_info.zrtp.wrongs_flags); 74 | 75 | /* 76 | * And one more time.. both RS1 and RS2 should be cached and should match. 77 | */ 78 | release_alice_bob(); 79 | 80 | prepare_alice_bob(); 81 | 82 | start_alice_bob_and_wait4secure(); 83 | 84 | s = zrtp_test_session_get(g_alice_sid, &alice_ses_info); 85 | assert_int_equal(zrtp_status_ok, s); 86 | 87 | assert_int_equal((int)(ZRTP_BIT_RS1 | ZRTP_BIT_RS2) , alice_ses_info.zrtp.matches_flags); 88 | assert_int_equal((int)(ZRTP_BIT_RS1 | ZRTP_BIT_RS2), alice_ses_info.zrtp.cached_flags); 89 | assert_int_equal(0, alice_ses_info.zrtp.wrongs_flags); 90 | } 91 | 92 | int main(void) { 93 | const UnitTest tests[] = { 94 | unit_test_setup_teardown(go_secure_test, setup, teardown), 95 | unit_test_setup_teardown(go_secure_flags_test, setup, teardown), 96 | }; 97 | 98 | return run_tests(tests); 99 | } 100 | -------------------------------------------------------------------------------- /test/hash_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #include "zrtp.h" 14 | #include "cmockery/cmockery.h" 15 | 16 | zrtp_global_t *zrtp; 17 | 18 | void setup() { 19 | zrtp_status_t s; 20 | zrtp_config_t zrtp_config; 21 | 22 | zrtp_config_defaults(&zrtp_config); 23 | 24 | s = zrtp_init(&zrtp_config, &zrtp); 25 | assert_int_equal(s, zrtp_status_ok); 26 | } 27 | 28 | void teardown() { 29 | zrtp_down(zrtp); 30 | } 31 | 32 | static void sha1_hash_test() { 33 | zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_SRTP_HASH_HMAC_SHA1, zrtp); 34 | assert_non_null(hash); 35 | hash->hash_self_test(hash); 36 | } 37 | 38 | static void sha1_hmac_test() { 39 | zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_SRTP_HASH_HMAC_SHA1, zrtp); 40 | assert_non_null(hash); 41 | hash->hmac_self_test(hash); 42 | } 43 | 44 | static void sha256_hash_test() { 45 | zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA256, zrtp); 46 | assert_non_null(hash); 47 | hash->hash_self_test(hash); 48 | } 49 | 50 | static void sha256_hmac_test() { 51 | zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA256, zrtp); 52 | assert_non_null(hash); 53 | hash->hmac_self_test(hash); 54 | } 55 | 56 | static void sha384_hash_test() { 57 | zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA384, zrtp); 58 | assert_non_null(hash); 59 | hash->hash_self_test(hash); 60 | } 61 | 62 | static void sha384_hmac_test() { 63 | zrtp_hash_t *hash = zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA384, zrtp); 64 | assert_non_null(hash); 65 | hash->hmac_self_test(hash); 66 | } 67 | 68 | 69 | int main(void) { 70 | const UnitTest tests[] = { 71 | unit_test_setup_teardown(sha1_hash_test, setup, teardown), 72 | unit_test_setup_teardown(sha1_hmac_test, setup, teardown), 73 | unit_test_setup_teardown(sha256_hash_test, setup, teardown), 74 | unit_test_setup_teardown(sha256_hmac_test, setup, teardown), 75 | unit_test_setup_teardown(sha384_hash_test, setup, teardown), 76 | unit_test_setup_teardown(sha384_hmac_test, setup, teardown), 77 | }; 78 | 79 | return run_tests(tests); 80 | } 81 | -------------------------------------------------------------------------------- /test/minor_bugs_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #include "zrtp.h" 14 | #include "cmockery/cmockery.h" 15 | 16 | zrtp_global_t *zrtp; 17 | 18 | void setup() { 19 | zrtp_status_t s; 20 | zrtp_config_t zrtp_config; 21 | 22 | zrtp_config_defaults(&zrtp_config); 23 | 24 | s = zrtp_init(&zrtp_config, &zrtp); 25 | assert_int_equal(s, zrtp_status_ok); 26 | } 27 | 28 | void teardown() { 29 | zrtp_down(zrtp); 30 | } 31 | 32 | 33 | static void session_init_fails_with_no_dh2k() { 34 | zrtp_profile_t profile; 35 | zrtp_status_t s; 36 | 37 | zrtp_session_t *new_session; 38 | 39 | /* Let's initialize ZRTP session with default profile first */ 40 | zrtp_profile_defaults(&profile, zrtp); 41 | 42 | new_session = NULL; 43 | s = zrtp_session_init(zrtp, 44 | &profile, 45 | ZRTP_SIGNALING_ROLE_INITIATOR, 46 | &new_session); 47 | 48 | assert_int_equal(zrtp_status_ok, s); 49 | assert_non_null(new_session); 50 | 51 | /* Then disable DH2K and leave just mandatory parameters */ 52 | profile.pk_schemes[0] = ZRTP_PKTYPE_DH3072; 53 | profile.pk_schemes[1] = ZRTP_PKTYPE_MULT; 54 | profile.pk_schemes[2] = 0; 55 | 56 | new_session = NULL; 57 | s = zrtp_session_init(zrtp, 58 | &profile, 59 | ZRTP_SIGNALING_ROLE_INITIATOR, 60 | &new_session); 61 | 62 | assert_int_equal(zrtp_status_ok, s); 63 | assert_non_null(new_session); 64 | 65 | /* Let's try to disable Multi key exchange, it should produce an error. */ 66 | profile.pk_schemes[0] = ZRTP_PKTYPE_DH3072; 67 | profile.pk_schemes[1] = 0; 68 | 69 | new_session = NULL; 70 | s = zrtp_session_init(zrtp, 71 | &profile, 72 | ZRTP_SIGNALING_ROLE_INITIATOR, 73 | &new_session); 74 | 75 | assert_int_not_equal(zrtp_status_ok, s); 76 | assert_null(new_session); 77 | 78 | /* Profile checking with one of mandatory components missing should return error too. */ 79 | s = zrtp_profile_check(&profile, zrtp); 80 | assert_int_not_equal(zrtp_status_ok, s); 81 | 82 | /* NOTE: we ignore memory leaks and don't destroy ZRTP sessions to make test sources cleaner */ 83 | } 84 | 85 | 86 | int main(void) { 87 | const UnitTest tests[] = { 88 | unit_test_setup_teardown(session_init_fails_with_no_dh2k, setup, teardown), 89 | }; 90 | 91 | return run_tests(tests); 92 | } 93 | -------------------------------------------------------------------------------- /test/queue.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #include "zrtp.h" 11 | #include "queue.h" 12 | 13 | struct zrtp_queue { 14 | zrtp_sem_t* size_sem; 15 | zrtp_sem_t* main_sem; 16 | zrtp_mutex_t* mutex; 17 | mlist_t head; 18 | uint32_t size; 19 | }; 20 | 21 | 22 | zrtp_status_t zrtp_test_queue_create(zrtp_queue_t** queue) { 23 | 24 | zrtp_status_t s = zrtp_status_fail; 25 | zrtp_queue_t* new_queue = (zrtp_queue_t*) zrtp_sys_alloc(sizeof(zrtp_queue_t)); 26 | if (! new_queue) { 27 | return zrtp_status_fail; 28 | } 29 | zrtp_memset(new_queue, 0, sizeof(zrtp_queue_t)); 30 | 31 | do { 32 | s = zrtp_sem_init(&new_queue->size_sem, ZRTP_QUEUE_SIZE, ZRTP_QUEUE_SIZE); 33 | if (zrtp_status_ok != s) { 34 | break; 35 | } 36 | s = zrtp_sem_init(&new_queue->main_sem, 0, ZRTP_QUEUE_SIZE); 37 | if (zrtp_status_ok != s) { 38 | break; 39 | } 40 | 41 | s = zrtp_mutex_init(&new_queue->mutex); 42 | if (zrtp_status_ok != s) { 43 | break; 44 | } 45 | 46 | init_mlist(&new_queue->head); 47 | new_queue->size = 0; 48 | 49 | s = zrtp_status_ok; 50 | } while (0); 51 | 52 | if (zrtp_status_ok != s) { 53 | if (new_queue->size_sem) { 54 | zrtp_sem_destroy(new_queue->size_sem); 55 | } 56 | if (new_queue->main_sem) { 57 | zrtp_sem_destroy(new_queue->main_sem); 58 | } 59 | if (new_queue->mutex) { 60 | zrtp_mutex_destroy(new_queue->mutex); 61 | } 62 | } 63 | 64 | *queue = new_queue; 65 | 66 | return s; 67 | } 68 | 69 | void zrtp_test_queue_destroy(zrtp_queue_t* queue) { 70 | if (queue->size_sem) { 71 | zrtp_sem_destroy(queue->size_sem); 72 | } 73 | if (queue->main_sem) { 74 | zrtp_sem_destroy(queue->main_sem); 75 | } 76 | if (queue->mutex) { 77 | zrtp_mutex_destroy(queue->mutex); 78 | } 79 | } 80 | 81 | 82 | void zrtp_test_queue_push(zrtp_queue_t* queue, zrtp_queue_elem_t* elem) { 83 | zrtp_sem_wait(queue->size_sem); 84 | 85 | zrtp_mutex_lock(queue->mutex); 86 | mlist_add_tail(&queue->head, &elem->_mlist); 87 | queue->size++; 88 | zrtp_mutex_unlock(queue->mutex); 89 | 90 | zrtp_sem_post(queue->main_sem); 91 | } 92 | 93 | zrtp_queue_elem_t* zrtp_test_queue_pop(zrtp_queue_t* queue) { 94 | zrtp_queue_elem_t* res = NULL; 95 | zrtp_sem_wait(queue->main_sem); 96 | 97 | zrtp_mutex_lock(queue->mutex); 98 | if (queue->size) { 99 | zrtp_queue_elem_t* elem_cover = mlist_get_struct(zrtp_queue_elem_t, _mlist, queue->head.next); 100 | res = elem_cover; 101 | mlist_del(queue->head.next); 102 | 103 | queue->size--; 104 | zrtp_sem_post(queue->size_sem); 105 | } else { 106 | zrtp_sem_post(queue->main_sem); 107 | } 108 | zrtp_mutex_unlock(queue->mutex); 109 | 110 | return res; 111 | } 112 | -------------------------------------------------------------------------------- /test/queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #ifndef __ZRTP_TEST_QUEUE_H__ 11 | #define __ZRTP_TEST_QUEUE_H__ 12 | 13 | #include "zrtp.h" 14 | 15 | #define ZRTP_QUEUE_SIZE 2000 16 | 17 | typedef struct zrtp_queue_elem { 18 | char data[1500]; 19 | uint32_t size; 20 | mlist_t _mlist; 21 | } zrtp_queue_elem_t; 22 | typedef struct zrtp_queue zrtp_queue_t; 23 | 24 | zrtp_status_t zrtp_test_queue_create(zrtp_queue_t** queue); 25 | void zrtp_test_queue_destroy(zrtp_queue_t* queue); 26 | void zrtp_test_queue_push(zrtp_queue_t* queue, zrtp_queue_elem_t* elem); 27 | zrtp_queue_elem_t* zrtp_test_queue_pop(zrtp_queue_t* queue); 28 | 29 | #endif /* __ZRTP_TEST_QUEUE_H__ */ 30 | -------------------------------------------------------------------------------- /test/sdes_test.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "zrtp.h" 8 | #include "zrtp_sdes.h" 9 | 10 | /* 11 | * Test Data and tests 12 | */ 13 | 14 | /* parsing the following string shall return a parse error */ 15 | static char *minimumLong = 16 | "1 AES_CM_128_HMAC_SHA1_8045AES_CM_128_HMAC_SHA1_8045AES_CM_128_HMAC_SHA1_8045" 17 | "AES_CM_128_HMAC_SHA1_8045AES_CM_128_HMAC_SHA1_8045 inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz"; 18 | 19 | static char *minimum = "1 AES_CM_128_HMAC_SHA1_80 inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz"; 20 | static char *withLifetime = "1 AES_CM_128_HMAC_SHA1_32 inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz|2^20"; 21 | static char *withLifetimeMki = "1 AES_CM_128_HMAC_SHA1_80 inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz|2^20|1:4"; 22 | 23 | static char *minimumSp = 24 | "1 AES_CM_128_HMAC_SHA1_80 inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz " 25 | "FEC_ORDER=FEC_SRTP KDR=20"; 26 | 27 | static char *withLifetimeSp = 28 | "1 AES_CM_128_HMAC_SHA1_80 inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz|2^20 " 29 | "FEC_ORDER=FEC_SRTP KDR=20"; 30 | 31 | static char *withLifetimeMkiSp = 32 | "1 AES_CM_128_HMAC_SHA1_32 inline:WVNfX19zZW1jdGwgKCkgewkyMjA7fQp9CnVubGVz|2^20|1:4 " 33 | "FEC_ORDER=FEC_SRTP KDR=20"; 34 | 35 | 36 | static zrtp_global_t *zrtp; 37 | 38 | static void setup() { 39 | zrtp_status_t s; 40 | zrtp_config_t zrtp_config; 41 | 42 | zrtp_config_defaults(&zrtp_config); 43 | 44 | s = zrtp_init(&zrtp_config, &zrtp); 45 | } 46 | 47 | int 48 | main (int argc, char **argv) 49 | { 50 | int64_t tag = 0; 51 | sdesSuites suite; 52 | int i; 53 | char cryptoString[200]; 54 | size_t length = 200; 55 | 56 | zrtp_srtp_profile_t profile; 57 | 58 | setup(); 59 | 60 | createSdesProfile(zrtp, AES_CM_128_HMAC_SHA1_80, cryptoString, &length, 2, &profile); 61 | printf("crypto string: %s, len: %ld, %ld\n", cryptoString, length, strlen(cryptoString)); 62 | 63 | length = 200; 64 | createSdesProfile(zrtp, AES_CM_128_HMAC_SHA1_32, cryptoString, &length, 1, &profile); 65 | printf("crypto string: %s, len: %ld, %ld\n", cryptoString, length, strlen(cryptoString)); 66 | 67 | i = parseCreateSdesProfile(zrtp, minimum, strlen(minimum), &profile, &suite, &tag); 68 | printf("parse return: %d, suite: %d, tag: %ld\n", i, suite, tag); 69 | if (i == zrtp_status_ok) { 70 | printf("cipher name, srtp: %.4s, srtcp: %.4s\n", profile.rtp_policy.cipher->base.type, profile.rtcp_policy.cipher->base.type); 71 | printf("cipher keylength, srtp: %d, srtcp: %d\n", profile.rtp_policy.cipher_key_len, profile.rtcp_policy.cipher_key_len); 72 | printf("authentication, srtp: %.4s, srtcp: %.4s\n", profile.rtp_policy.auth_tag_len->base.type, profile.rtcp_policy.auth_tag_len->base.type); 73 | printf("authentication keylength, srtp: %d, srtcp: %d\n", profile.rtp_policy.auth_key_len, profile.rtcp_policy.auth_key_len); 74 | printf("cipher name key derivation: %.4s\n", profile.dk_cipher->base.type); 75 | printf("hmac name, srtp: %.4s, srtcp: %.4s\n", profile.rtp_policy.hash->base.type, profile.rtcp_policy.hash->base.type); 76 | } 77 | 78 | /* i shall be zrtp_status_fail */ 79 | i = parseCreateSdesProfile(zrtp, minimumLong, strlen(minimumLong), &profile, &suite, &tag); 80 | printf("parse return: %d, suite: %d, tag: %ld\n", i, suite, tag); 81 | 82 | i = parseCreateSdesProfile(zrtp, withLifetime, strlen(withLifetime), &profile, &suite, &tag); 83 | printf("parse return: %d, suite: %d, tag: %ld\n", i, suite, tag); 84 | 85 | i = parseCreateSdesProfile(zrtp, withLifetimeMkiSp, strlen(withLifetimeMkiSp), &profile, &suite, &tag); 86 | printf("parse return: %d, suite: %d, tag: %ld\n", i, suite, tag); 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /test/zrtphash_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libZRTP SDK library, implements the ZRTP secure VoIP protocol. 3 | * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved. 4 | * Contact: http://philzimmermann.com 5 | * For licensing and other legal details, see the file zrtp_legal.c. 6 | * 7 | * Viktor Krykun 8 | */ 9 | 10 | #include "engine_helpers.c" 11 | 12 | static void setup() { 13 | zrtp_status_t s; 14 | 15 | zrtp_test_endpoint_cfg_t endpoint_cfg; 16 | zrtp_test_endpoint_config_defaults(&endpoint_cfg); 17 | 18 | s = zrtp_test_endpoint_create(&endpoint_cfg, "Alice", &g_alice); 19 | assert_int_equal(zrtp_status_ok, s); 20 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice); 21 | 22 | s = zrtp_test_endpoint_create(&endpoint_cfg, "Bob", &g_bob); 23 | assert_int_equal(zrtp_status_ok, s); 24 | assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob); 25 | } 26 | 27 | static void teardown() { 28 | zrtp_test_endpoint_destroy(g_alice); 29 | zrtp_test_endpoint_destroy(g_bob); 30 | } 31 | 32 | 33 | static void zrtp_hash_export_import_sunny_test() { 34 | zrtp_status_t s; 35 | char alice_zrtp_hash[ZRTP_SIGN_ZRTP_HASH_LENGTH]; 36 | char bob_zrtp_hash[ZRTP_SIGN_ZRTP_HASH_LENGTH]; 37 | zrtp_stream_t *alice_zrtp_stream, *bob_zrtp_stream; 38 | 39 | /* Create two test sessions, one for Alice and one for Bob and link them into test secure channel */ 40 | prepare_alice_bob(); 41 | 42 | alice_zrtp_stream = zrtp_stream_for_test_stream(zrtp_test_session_get_stream_by_idx(g_alice_sid, 0)); 43 | bob_zrtp_stream = zrtp_stream_for_test_stream(zrtp_test_session_get_stream_by_idx(g_bob_sid, 0)); 44 | assert_non_null(alice_zrtp_stream); assert_non_null(bob_zrtp_stream); 45 | 46 | /* Take Alice's hash and give it to Bob */ 47 | s = zrtp_signaling_hash_get(alice_zrtp_stream, alice_zrtp_hash, sizeof(alice_zrtp_hash)); 48 | assert_int_equal(zrtp_status_ok, s); 49 | 50 | s = zrtp_signaling_hash_set(bob_zrtp_stream, alice_zrtp_hash, ZRTP_SIGN_ZRTP_HASH_LENGTH); 51 | assert_int_equal(zrtp_status_ok, s); 52 | 53 | /* Take Bob's hash and give it to Alice */ 54 | s = zrtp_signaling_hash_get(bob_zrtp_stream, bob_zrtp_hash, sizeof(bob_zrtp_hash)); 55 | assert_int_equal(zrtp_status_ok, s); 56 | 57 | s = zrtp_signaling_hash_set(alice_zrtp_stream, bob_zrtp_hash, ZRTP_SIGN_ZRTP_HASH_LENGTH); 58 | assert_int_equal(zrtp_status_ok, s); 59 | 60 | /* Start and wait for Secure */ 61 | start_alice_bob_and_wait4secure(); 62 | 63 | /* Check if ZRTP_EVENT_WRONG_SIGNALING_HASH was not triggered for any of test endpoints */ 64 | assert_false(zrtp_stream_did_event_receive(zrtp_test_session_get_stream_by_idx(g_alice_sid, 0), 65 | ZRTP_EVENT_WRONG_SIGNALING_HASH)); 66 | 67 | assert_false(zrtp_stream_did_event_receive(zrtp_test_session_get_stream_by_idx(g_bob_sid, 0), 68 | ZRTP_EVENT_WRONG_SIGNALING_HASH)); 69 | 70 | /* Release test setup */ 71 | release_alice_bob(); 72 | } 73 | 74 | static void zrtp_hash_import_wrong_test() { 75 | zrtp_status_t s; 76 | char wrong_alice_zrtp_hash[ZRTP_SIGN_ZRTP_HASH_LENGTH]; 77 | zrtp_stream_t *bob_zrtp_stream; 78 | 79 | /* Create two test sessions, one for Alice and one for Bob and link them into test secure channel */ 80 | prepare_alice_bob(); 81 | 82 | bob_zrtp_stream = zrtp_stream_for_test_stream(zrtp_test_session_get_stream_by_idx(g_bob_sid, 0)); 83 | assert_non_null(bob_zrtp_stream); 84 | 85 | /* Let's provide wrong hash to bob */ 86 | zrtp_memset(wrong_alice_zrtp_hash, 6, ZRTP_SIGN_ZRTP_HASH_LENGTH); 87 | 88 | s = zrtp_signaling_hash_set(bob_zrtp_stream, wrong_alice_zrtp_hash, ZRTP_SIGN_ZRTP_HASH_LENGTH); 89 | assert_int_equal(zrtp_status_ok, s); 90 | 91 | /* Start and wait for Secure */ 92 | start_alice_bob_and_wait4secure(); 93 | 94 | /* Check if Alice don't receive ZRTP_EVENT_WRONG_SIGNALING_HASH, but Bob should get one */ 95 | assert_false(zrtp_stream_did_event_receive(zrtp_test_session_get_stream_by_idx(g_alice_sid, 0), 96 | ZRTP_EVENT_WRONG_SIGNALING_HASH)); 97 | 98 | assert_true(zrtp_stream_did_event_receive(zrtp_test_session_get_stream_by_idx(g_bob_sid, 0), 99 | ZRTP_EVENT_WRONG_SIGNALING_HASH)); 100 | 101 | /* Release test setup */ 102 | release_alice_bob(); 103 | } 104 | 105 | 106 | int main(void) { 107 | const UnitTest tests[] = { 108 | unit_test_setup_teardown(zrtp_hash_export_import_sunny_test, setup, teardown), 109 | unit_test_setup_teardown(zrtp_hash_import_wrong_test, setup, teardown), 110 | }; 111 | 112 | return run_tests(tests); 113 | } 114 | -------------------------------------------------------------------------------- /third_party/bgaes/bg2zrtp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2008 Philip R. Zimmermann. All rights reserved. 3 | * Contact: http://www.philzimmermann.com 4 | * For licensing and other legal details, see the file zrtp_legal.c. 5 | * 6 | * Viktor Krikun 7 | */ 8 | 9 | #ifndef __BG2ZRTP_H__ 10 | #define __BG2ZRTP_H__ 11 | 12 | /* Define platform byte order for Brian Gladman's AES */ 13 | #include "zrtp_config.h" 14 | 15 | #define IS_BIG_ENDIAN 4321 16 | #define IS_LITTLE_ENDIAN 1234 17 | 18 | 19 | #if ZRTP_BYTE_ORDER == ZBO_LITTLE_ENDIAN 20 | #define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 21 | #elif ZRTP_BYTE_ORDER == ZBO_BIG_ENDIAN 22 | #define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 23 | #else 24 | #error "Can't define byte order for BG AES. Edit zrtp_system.h" 25 | #endif 26 | 27 | 28 | /* Define integers for Brian Gladman's AES */ 29 | 30 | #define BRG_UI8 31 | typedef uint8_t uint_8t; 32 | 33 | #define BRG_UI16 34 | typedef uint16_t uint_16t; 35 | 36 | #define BRG_UI32 37 | //typedef uint32_t uint_32t; 38 | typedef unsigned int uint_32t; 39 | 40 | #define BRG_UI64 41 | typedef uint64_t uint_64t; 42 | 43 | 44 | #endif /*__BG2ZRTP_H__*/ 45 | -------------------------------------------------------------------------------- /third_party/bgaes/sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 01/08/2005 31 | */ 32 | 33 | #ifndef _SHA1_H 34 | #define _SHA1_H 35 | 36 | #include 37 | #include "brg_types.h" 38 | 39 | #define SHA1_BLOCK_SIZE 64 40 | #define SHA1_DIGEST_SIZE 20 41 | 42 | #if defined(__cplusplus) 43 | extern "C" 44 | { 45 | #endif 46 | 47 | /* type to hold the SHA256 context */ 48 | 49 | typedef struct 50 | { uint_32t count[2]; 51 | uint_32t hash[5]; 52 | uint_32t wbuf[16]; 53 | } sha1_ctx; 54 | 55 | /* Note that these prototypes are the same for both bit and */ 56 | /* byte oriented implementations. However the length fields */ 57 | /* are in bytes or bits as appropriate for the version used */ 58 | /* and bit sequences are input as arrays of bytes in which */ 59 | /* bit sequences run from the most to the least significant */ 60 | /* end of each byte */ 61 | 62 | VOID_RETURN sha1_compile(sha1_ctx ctx[1]); 63 | 64 | VOID_RETURN sha1_begin(sha1_ctx ctx[1]); 65 | VOID_RETURN sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]); 66 | VOID_RETURN sha1_end(unsigned char hval[], sha1_ctx ctx[1]); 67 | VOID_RETURN sha1(unsigned char hval[], const unsigned char data[], unsigned long len); 68 | 69 | #if defined(__cplusplus) 70 | } 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /third_party/bnlib/.gitignore: -------------------------------------------------------------------------------- 1 | # -*- mode:conf -*- 2 | /*.a 3 | /*.o 4 | /Makefile 5 | /autom4te.cache/* 6 | /bnconfig.h 7 | /config.* 8 | /configure 9 | -------------------------------------------------------------------------------- /third_party/bnlib/CHANGES: -------------------------------------------------------------------------------- 1 | 1.1.4 2 | - Added bnBasePrecompCopy, bnDoubleBasePrecompExpMod, and corresponding 3 | lbn* functions. 4 | - Fixed some stupid bugs in bnExtractBigBytes and bnExtractLittleBytes 5 | when asking for more bytes than the numbers have. 6 | 7 | 1.1.3 8 | 1999-05-09 9 | - Added bnBasePrecompBegin, bnBasePrecompEnd and bnBasePrecompExpMod, 10 | and corresponding lbn* functions. 11 | - Added some rudimentary tests of the above to bntest. 12 | - Updated dsatest to use the new functions. Speedup on 1024 bits seems 13 | to be about 3x. 14 | 15 | 1.1.2: 16 | 1998-06-22 17 | - Added bnReadBit function 18 | - Fixed corruption in bnMakeOdd_16 19 | - Clarified comments in germain.c 20 | - Fixed nasty bug in lbnModQ_16 in lbn80386.asm 21 | - renamed rand parameter to randFunc in prime.c to avoid warnings 22 | 23 | 1.1.1: 24 | - Cleaned up some test directory code 25 | 26 | 1.1: Second public release 27 | 28 | - Generalized Sophie Germain primes to variable "orders", 29 | which is the number of 2*p+1 levels that are all prime. 30 | An order-0 primeis an ordinary prime. An order-1 prime is 31 | a Sophie Germain prime. An order-3 prime also has 4*p+3 prime. 32 | (Changed hours before release; I wonder if there are bugs?) 33 | - Figured out that if p and 2*p+1 are prime, it's p that's called 34 | a Sophie Germain prime, not 2*p+1. germain.c and germtest.c 35 | updated accordingly. 2*p+1 is called a "strong prime". 36 | - Updated to not use 16-bit MSDOS-isms like "cdecl" with GCC under GO32. 37 | - Fixed a bug in primeGen() that caused it to do strange things 38 | if the first number in the sieve passed. 39 | - Fixed a memory leak in lbnExpMod 40 | - Fixed bug in lbn80386.asm lbnModQ_32 (was a complete mess) 41 | - Fixed bug in bnDoubleExpMod (one-character change; masked a bug in SKIP!) 42 | - Fixed a bug in error recovery in lbnInv 43 | - Added out-of-memory checking to bntest 44 | - Installation documentation improved, especially for non-Unix platforms. 45 | - Preprocessor trickery made compatible with some ancient sort-of-ANSI 46 | compilers. To be precise: 47 | - Not liking "#if FOO" when FOO is not defined (ANSI says FOO is "0") 48 | - Not liking long constants without "l" (ANSI says all pp math is long) 49 | - bnInit() made redundant; now called automatically by bnBegin(). 50 | - bnCmpQ(struct BigNum const *, unsigned) added. 51 | - Removed copyright disclaimers from some files so as not to confuse lawyers. 52 | - Spell-checked, corrected and improved comments in lbn16.c. Especially 53 | added a big description of Montgomery representation. 54 | - Added parens a few places to shut up compiler warnings. 55 | - Added 386 support for Unix and some GCC-specific inline assembler tricks. 56 | - Got rid of some warnings in lbn8086.h. 57 | - Improved PowerPC inline assembler for CodeWarrior 8. 58 | 59 | 1.0: Initial release (unnumbered, retroactively named 1.0) 60 | -------------------------------------------------------------------------------- /third_party/bnlib/README.bntest: -------------------------------------------------------------------------------- 1 | Test driver for low-level BigNum library correctness. 2 | 3 | In addition to the generic "bntest" program, which picks a size 4 | at compile time, there are specific test drivers, bntest16, 5 | bntest32 and bntest64 that you can compile specifically, e.g. 6 | to test multiple word sizes. 7 | 8 | bntest is different from other programs in that it invokes the 9 | low-level BigNum functions directly. It need only be linked with 10 | lbnmem.o, lbn32.o and legal.o. This is not normally desirable, but 11 | it lets this test driver isolate errors better in the bottom-level 12 | primitives. 13 | 14 | It's served very well in tracking down errors. If you write some new 15 | assembly primitives and it doesn't find a problem with them, you 16 | can have a good deal of confidence that they're correct. 17 | 18 | This program also does timing tests on basic modular exponentiation. 19 | It is invoked as bntest [modsize [expsize [expsize2]]]. 20 | If modsize is not specified, it only runs consistency checks. 21 | If expsize is not specified, it defaults to modsize. 22 | If expsize2 is not specified, it defaults to expsize. 23 | Invalid arguments produce a usage message. 24 | 25 | Example invocation lines: 26 | bntest 27 | bntest 512 28 | bntest 1024 160 29 | -------------------------------------------------------------------------------- /third_party/bnlib/bignum-ARM/README-small-memory: -------------------------------------------------------------------------------- 1 | This directory contains a stripped-down version of Colin Plumb's bnlib bignum package for ARM processors in minimal memory environments, such as embedded Wireless USB controllers. All unnecessary functions have been removed, and code has been reorganized for shrinking the memory footprint. These functions duplicate the functionality of similar functions in the main bnlib package, but with smaller memory footprints. Wireless USB only requires Diffie-Hellman, and little else. 2 | 3 | For more information, see the documentation in the main bnlib package, which is not in this directory. Or contact: 4 | 5 | Philip Zimmermann 6 | October 2007 7 | -------------------------------------------------------------------------------- /third_party/bnlib/bignum-ARM/config.h: -------------------------------------------------------------------------------- 1 | /* bnconfig.h. Generated automatically by configure. */ 2 | /* 3 | * bnconfig.h -- Configuration file for BigNum library. 4 | * 5 | * This file is automatically filled in by configure. 6 | * Everything must start out turned *off*, because configure 7 | * (or, more properly, config.status) only knows how to turn them 8 | * *on*. 9 | */ 10 | #ifndef CONFIG_H 11 | #define CONFIG_H 12 | 13 | /* Define to empty if the compiler does not support 'const' variables. */ 14 | /* #undef const */ 15 | 16 | /* Define to `unsigned' if doesn't define it. */ 17 | /* #undef size_t */ 18 | 19 | /* Checks for the presence and absence of various header files */ 20 | #define HAVE_ASSERT_H 1 21 | #define NO_ASSERT_H !HAVE_ASSERT_H 22 | #define HAVE_LIMITS_H 1 23 | #define NO_LIMITS_H !HAVE_LIMITS_H 24 | #define HAVE_STDLIB_H 1 25 | #define NO_STDLIB_H !HAVE_STDLIB_H 26 | #define HAVE_STRING_H 1 27 | #define NO_STRING_H !HAVE_STRING_H 28 | 29 | #define HAVE_STRINGS_H 0 30 | 31 | /* We go to some trouble to find accurate times... */ 32 | 33 | /* Define if you have Posix.4 glock_gettime() */ 34 | #define HAVE_CLOCK_GETTIME 0 35 | /* Define if you have Solaris-style gethrvtime() */ 36 | #define HAVE_GETHRVTIME 0 37 | /* Define if you have getrusage() */ 38 | #define HAVE_GETRUSAGE 1 39 | /* Define if you have clock() */ 40 | #define HAVE_CLOCK 1 41 | /* Define if you have time() */ 42 | #define HAVE_TIME 1 43 | 44 | /* 45 | * Define as 0 if #including automatically 46 | * #includes , and doing so explicitly causes an 47 | * error. 48 | */ 49 | #define TIME_WITH_SYS_TIME 1 50 | 51 | /* Defines for various kinds of library brokenness */ 52 | 53 | /* If not available, bcopy() is substituted */ 54 | #define HAVE_MEMMOVE 1 55 | #define NO_MEMMOVE !HAVE_MEMMOVE 56 | #define HAVE_MEMCPY 1 57 | #define NO_MEMCPY !HAVE_MEMCPY 58 | 59 | #endif /* CONFIG_H */ 60 | -------------------------------------------------------------------------------- /third_party/bnlib/bignum-ARM/kludge.h: -------------------------------------------------------------------------------- 1 | #ifndef KLUDGE_H 2 | #define KLUDGE_H 3 | 4 | /* 5 | * Kludges for not-quite-ANSI systems. 6 | * This should always be the last file included, because it may 7 | * mess up some system header files. 8 | */ 9 | 10 | /* 11 | * Some compilers complain about #if FOO if FOO isn't defined, 12 | * so do the ANSI-mandated thing explicitly... 13 | */ 14 | #ifndef NO_STDLIB_H 15 | #define NO_STDLIB_H 0 16 | #endif 17 | 18 | #ifndef NO_MEMMOVE 19 | #define NO_MEMMOVE 0 20 | #endif 21 | #if NO_MEMMOVE /* memove() not in libraries */ 22 | #define memmove(dest,src,len) bcopy(src,dest,len) 23 | #endif 24 | 25 | #ifndef NO_MEMCPY 26 | #define NO_MEMCPY 0 27 | #endif 28 | #if NO_MEMCPY /* memcpy() not in libraries */ 29 | #define memcpy(dest,src,len) bcopy(src,dest,len) 30 | #endif 31 | 32 | /* 33 | * Borland C seems to think that it's a bad idea to decleare a 34 | * structure tag and not declare the contents. I happen to think 35 | * it's a *good* idea to use such "opaque" structures wherever 36 | * possible. So shut up. 37 | */ 38 | #ifdef __BORLANDC__ 39 | #pragma warn -stu 40 | #ifndef MSDOS 41 | #define MSDOS 1 42 | #endif 43 | #endif 44 | 45 | /* Turn off warning about negation of unsigned values */ 46 | #ifdef _MSC_VER 47 | #pragma warning(disable:4146) 48 | #endif 49 | 50 | /* Cope with people forgetting to define the OS, if possible... */ 51 | #ifndef MSDOS 52 | #ifdef __MSDOS 53 | #define MSDOS 1 54 | #endif 55 | #endif 56 | #ifndef MSDOS 57 | #ifdef __MSDOS__ 58 | #define MSDOS 1 59 | #endif 60 | #endif 61 | 62 | /* By MS-DOS, we mean 16-bit brain-dead MS-DOS. Not GCC & GO32 */ 63 | #ifdef __GO32 64 | #undef MSDOS 65 | #endif 66 | #ifdef __GO32__ 67 | #undef MSDOS 68 | #endif 69 | 70 | #endif /* KLUDGE_H */ 71 | -------------------------------------------------------------------------------- /third_party/bnlib/bignum-ARM/lbnarm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * lbnarm.h - This file defines the interfaces to the ARM 3 | * assembly primitives. It is intended to be included in "lbn.h" 4 | * via the "#include BNINCLUDE" mechanism. 5 | */ 6 | 7 | #define BN_LITTLE_ENDIAN 1 8 | 9 | typedef unsigned bnword32; 10 | #define BNWORD32 bnword32 11 | 12 | /* Function prototypes for the asm routines */ 13 | void 14 | lbnMulN1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); 15 | #define lbnMulN1_32 lbnMulN1_32 16 | 17 | bnword32 18 | lbnMulAdd1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); 19 | #define lbnMulAdd1_32 lbnMulAdd1_32 20 | 21 | /* Not implemented yet */ 22 | bnword32 23 | lbnMulSub1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); 24 | #define lbnMulSub1_32 lbnMulSub1_32 25 | 26 | #if __GNUC__ && 0 27 | /* 28 | * Use the (massively cool) GNU inline-assembler extension to define 29 | * inline expansions for various operations. 30 | * 31 | * The massively cool part is that the assembler can have inputs 32 | * and outputs, and you specify the operands and which effective 33 | * addresses are legal and they get substituted into the code. 34 | * (For example, some of the code requires a zero. Rather than 35 | * specify an immediate constant, the expansion specifies an operand 36 | * of zero which can be in various places. This lets GCC use an 37 | * immediate zero, or a register which contains zero if it's available.) 38 | * 39 | * The syntax is asm("asm_code" : outputs : inputs : trashed) 40 | * %0, %1 and so on in the asm code are substituted by the operands 41 | * in left-to-right order (outputs, then inputs). 42 | * The operands contain constraint strings and values to use. 43 | * Outputs must be lvalues, inputs may be rvalues. In the constraints: 44 | * "r" means that the operand may be in a register. 45 | * "=" means that the operand is assigned to. 46 | * "%" means that this operand and the following one may be 47 | * interchanged if desirable. 48 | * "&" means that this output operand is written before the input operands 49 | * are read, so it may NOT overlap with any input operands. 50 | * "0" and "1" mean that this operand may be in the same place as the 51 | * given operand. 52 | * Multiple sets of constraints may be listed, separated by commas. 53 | * 54 | * Note that ARM multi-precision multiply syntax lists destLo before destHi. 55 | * Also, the first source (%2) may not be the same as %0 or %1. 56 | * The second source, however, may be. 57 | */ 58 | 59 | /* (ph<<32) + pl = x*y */ 60 | #define mul32_ppmm(ph,pl,x,y) \ 61 | __asm__("umull %1,%0,%2,%3" : "=&r,&r"(ph), "=&r,&r"(pl) \ 62 | : "%r,%r"(x), "r0,r1"(y)) 63 | 64 | /* (ph<<32) + pl = x*y + a */ 65 | #define mul32_ppmma(ph,pl,x,y,a) \ 66 | __asm__("umlal %1,%0,%2,%3" : "=&r"(ph), "=&r"(pl) \ 67 | : "%r"(x), "r"(y), "0"(0), "1"(a)) 68 | 69 | /* (ph<<32) + pl = x*y + a + b */ 70 | /* %4 (a) may share a register with %0, but nothing else may. */ 71 | #define mul32_ppmmaa(ph,pl,x,y,a,b) \ 72 | __asm__("adds %1, %4, %5\n\t" \ 73 | "movcc %0, #0\n\t" \ 74 | "movcs %0, #1\n\t" \ 75 | "umlal %1,%0,%2,%3" \ 76 | : "=&r"(ph), "=&r"(pl) \ 77 | : "%r"(x), "r"(y), "%r"(a), "r1"(b)) 78 | 79 | #endif /* __GNUC__ */ 80 | -------------------------------------------------------------------------------- /third_party/bnlib/bignum-ARM/lbnmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * lbnmem.c - low-level bignum memory handling. 3 | * 4 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 5 | * 6 | * Note that in all cases, the pointers passed around 7 | * are pointers to the *least* significant end of the word. 8 | * On big-endian machines, these are pointers to the *end* 9 | * of the allocated range. 10 | * 11 | * BNSECURE is a simple level of security; for more security 12 | * change these function to use locked unswappable memory. 13 | */ 14 | #ifndef HAVE_CONFIG_H 15 | #define HAVE_CONFIG_H 0 16 | #endif 17 | #if HAVE_CONFIG_H 18 | #include "bnconfig.h" 19 | #endif 20 | 21 | /* 22 | * Some compilers complain about #if FOO if FOO isn't defined, 23 | * so do the ANSI-mandated thing explicitly... 24 | */ 25 | #ifndef NO_STDLIB_H 26 | #define NO_STDLIB_H 0 27 | #endif 28 | #ifndef NO_STRING_H 29 | #define NO_STRING_H 0 30 | #endif 31 | #ifndef HAVE_STRINGS_H 32 | #define HAVE_STRINGS_H 0 33 | #endif 34 | 35 | #if !NO_STDLIB_H 36 | #include /* For malloc() & co. */ 37 | #else 38 | void *malloc(); 39 | void *realloc(); 40 | void free(); 41 | #endif 42 | 43 | #if !NO_STRING_H 44 | #include /* For memset */ 45 | #elif HAVE_STRINGS_H 46 | #include 47 | #endif 48 | 49 | #ifndef DBMALLOC 50 | #define DBMALLOC 0 51 | #endif 52 | #if DBMALLOC 53 | /* Development debugging */ 54 | #include "../dbmalloc/malloc.h" 55 | #endif 56 | 57 | #include "lbn.h" 58 | #include "lbnmem.h" 59 | 60 | #include "kludge.h" 61 | 62 | #ifndef lbnMemWipe 63 | void 64 | lbnMemWipe(void *ptr, unsigned bytes) 65 | { 66 | memset(ptr, 0, bytes); 67 | } 68 | #define lbnMemWipe(ptr, bytes) memset(ptr, 0, bytes) 69 | #endif 70 | 71 | #ifndef lbnMemAlloc 72 | void * 73 | lbnMemAlloc(unsigned bytes) 74 | { 75 | return malloc(bytes); 76 | } 77 | #define lbnMemAlloc(bytes) malloc(bytes) 78 | #endif 79 | 80 | #ifndef lbnMemFree 81 | void 82 | lbnMemFree(void *ptr, unsigned bytes) 83 | { 84 | lbnMemWipe(ptr, bytes); 85 | free(ptr); 86 | } 87 | #endif 88 | 89 | #if 0 90 | #ifndef lbnRealloc 91 | #if defined(lbnMemRealloc) || !BNSECURE 92 | void * 93 | lbnRealloc(void *ptr, unsigned oldbytes, unsigned newbytes) 94 | { 95 | if (ptr) { 96 | BIG(ptr = (char *)ptr - oldbytes;) 97 | if (newbytes < oldbytes) 98 | memmove(ptr, (char *)ptr + oldbytes-newbytes, oldbytes); 99 | } 100 | #ifdef lbnMemRealloc 101 | ptr = lbnMemRealloc(ptr, oldbytes, newbytes); 102 | #else 103 | ptr = realloc(ptr, newbytes); 104 | #endif 105 | if (ptr) { 106 | if (newbytes > oldbytes) 107 | memmove((char *)ptr + newbytes-oldbytes, ptr, oldbytes); 108 | BIG(ptr = (char *)ptr + newbytes;) 109 | } 110 | 111 | return ptr; 112 | } 113 | 114 | #else /* BNSECURE */ 115 | 116 | void * 117 | lbnRealloc(void *oldptr, unsigned oldbytes, unsigned newbytes) 118 | { 119 | void *newptr = lbnMemAlloc(newbytes); 120 | 121 | if (!newptr) 122 | return newptr; 123 | if (!oldptr) 124 | return BIGLITTLE((char *)newptr+newbytes, newptr); 125 | 126 | /* 127 | * The following copies are a bit non-obvious in the big-endian case 128 | * because one of the pointers points to the *end* of allocated memory. 129 | */ 130 | if (newbytes > oldbytes) { /* Copy all of old into part of new */ 131 | BIG(newptr = (char *)newptr + newbytes;) 132 | BIG(oldptr = (char *)oldptr - oldbytes;) 133 | memcpy(BIGLITTLE((char *)newptr-oldbytes, newptr), oldptr, 134 | oldbytes); 135 | } else { /* Copy part of old into all of new */ 136 | memcpy(newptr, BIGLITTLE((char *)oldptr-newbytes, oldptr), 137 | newbytes); 138 | BIG(newptr = (char *)newptr + newbytes;) 139 | BIG(oldptr = (char *)oldptr - oldbytes;) 140 | } 141 | 142 | lbnMemFree(oldptr, oldbytes); 143 | 144 | return newptr; 145 | } 146 | #endif /* BNSECURE */ 147 | #endif /* !lbnRealloc */ 148 | #endif 149 | -------------------------------------------------------------------------------- /third_party/bnlib/bignum-ARM/lbnmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Operations on the usual buffers of bytes 3 | */ 4 | #ifndef BNSECURE 5 | #define BNSECURE 1 6 | #endif 7 | 8 | /* 9 | * These operations act on buffers of memory, just like malloc & free. 10 | * One exception: it is not legal to pass a NULL pointer to lbnMemFree. 11 | */ 12 | 13 | #ifndef lbnMemAlloc 14 | void *lbnMemAlloc(unsigned bytes); 15 | #endif 16 | 17 | #ifndef lbnMemFree 18 | void lbnMemFree(void *ptr, unsigned bytes); 19 | #endif 20 | 21 | /* This wipes out a buffer of bytes if necessary needed. */ 22 | 23 | #ifndef lbnMemWipe 24 | #if BNSECURE 25 | void lbnMemWipe(void *ptr, unsigned bytes); 26 | #else 27 | #define lbnMemWipe(ptr, bytes) (void)(ptr,bytes) 28 | #endif 29 | #endif /* !lbnMemWipe */ 30 | 31 | /* 32 | * lbnRealloc is NOT like realloc(); it's endian-sensitive! 33 | * If lbnMemRealloc is #defined, lbnRealloc will be defined in terms of it. 34 | * It is legal to pass a NULL pointer to lbnRealloc, although oldbytes 35 | * will always be sero. 36 | */ 37 | #ifndef lbnRealloc 38 | void *lbnRealloc(void *ptr, unsigned oldbytes, unsigned newbytes); 39 | #endif 40 | 41 | 42 | /* 43 | * These macros are the ones actually used most often in the math library. 44 | * They take and return pointers to the *end* of the given buffer, and 45 | * take sizes in terms of words, not bytes. 46 | * 47 | * Note that LBNALLOC takes the pointer as an argument instead of returning 48 | * the value. 49 | * 50 | * Note also that these macros are only useable if you have included 51 | * lbn.h (for the BIG and BIGLITTLE macros), which this file does NOT include. 52 | */ 53 | 54 | #define LBNALLOC(p,type,words) BIGLITTLE( \ 55 | if ( ((p) = (type *)lbnMemAlloc((words)*sizeof*(p))) != 0) \ 56 | (p) += (words), \ 57 | (p) = (type *)lbnMemAlloc((words) * sizeof*(p)) \ 58 | ) 59 | #define LBNFREE(p,words) lbnMemFree((p) BIG(-(words)), (words) * sizeof*(p)) 60 | #define LBNREALLOC(p,old,new) \ 61 | lbnRealloc(p, (old) * sizeof*(p), (new) * sizeof*(p)) 62 | #define LBNWIPE(p,words) lbnMemWipe((p) BIG(-(words)), (words) * sizeof*(p)) 63 | 64 | -------------------------------------------------------------------------------- /third_party/bnlib/bn.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bn.c - the high-level bignum interface 6 | */ 7 | 8 | #include "bn.h" 9 | 10 | /* Functions */ 11 | void 12 | bnBegin(struct BigNum *bn) 13 | { 14 | static int bninit = 0; 15 | 16 | if (!bninit) { 17 | bnInit(); 18 | bninit = 1; 19 | } 20 | 21 | bn->ptr = 0; 22 | bn->size = 0; 23 | bn->allocated = 0; 24 | } 25 | 26 | void 27 | bnSwap(struct BigNum *a, struct BigNum *b) 28 | { 29 | void *p; 30 | unsigned t; 31 | 32 | p = a->ptr; 33 | a->ptr = b->ptr; 34 | b->ptr = p; 35 | 36 | t = a->size; 37 | a->size = b->size; 38 | b->size = t; 39 | 40 | t = a->allocated; 41 | a->allocated = b->allocated; 42 | b->allocated = t; 43 | } 44 | 45 | int (*bnYield)(void); 46 | 47 | void (*bnEnd)(struct BigNum *bn); 48 | int (*bnPrealloc)(struct BigNum *bn, unsigned bits); 49 | int (*bnCopy)(struct BigNum *dest, struct BigNum const *src); 50 | void (*bnNorm)(struct BigNum *bn); 51 | void (*bnExtractBigBytes)(struct BigNum const *bn, unsigned char *dest, 52 | unsigned lsbyte, unsigned len); 53 | int (*bnInsertBigBytes)(struct BigNum *bn, unsigned char const *src, 54 | unsigned lsbyte, unsigned len); 55 | void (*bnExtractLittleBytes)(struct BigNum const *bn, unsigned char *dest, 56 | unsigned lsbyte, unsigned len); 57 | int (*bnInsertLittleBytes)(struct BigNum *bn, unsigned char const *src, 58 | unsigned lsbyte, unsigned len); 59 | unsigned (*bnLSWord)(struct BigNum const *src); 60 | int (*bnReadBit)(struct BigNum const *bn, unsigned bit); 61 | unsigned (*bnBits)(struct BigNum const *src); 62 | int (*bnAdd)(struct BigNum *dest, struct BigNum const *src); 63 | int (*bnSub)(struct BigNum *dest, struct BigNum const *src); 64 | int (*bnCmpQ)(struct BigNum const *a, unsigned b); 65 | int (*bnSetQ)(struct BigNum *dest, unsigned src); 66 | int (*bnAddQ)(struct BigNum *dest, unsigned src); 67 | int (*bnSubQ)(struct BigNum *dest, unsigned src); 68 | int (*bnCmp)(struct BigNum const *a, struct BigNum const *b); 69 | int (*bnSquare)(struct BigNum *dest, struct BigNum const *src); 70 | int (*bnMul)(struct BigNum *dest, struct BigNum const *a, 71 | struct BigNum const *b); 72 | int (*bnMulQ)(struct BigNum *dest, struct BigNum const *a, unsigned b); 73 | int (*bnDivMod)(struct BigNum *q, struct BigNum *r, struct BigNum const *n, 74 | struct BigNum const *d); 75 | int (*bnMod)(struct BigNum *dest, struct BigNum const *src, 76 | struct BigNum const *d); 77 | unsigned (*bnModQ)(struct BigNum const *src, unsigned d); 78 | int (*bnExpMod)(struct BigNum *result, struct BigNum const *n, 79 | struct BigNum const *exp, struct BigNum const *mod); 80 | int (*bnDoubleExpMod)(struct BigNum *dest, 81 | struct BigNum const *n1, struct BigNum const *e1, 82 | struct BigNum const *n2, struct BigNum const *e2, 83 | struct BigNum const *mod); 84 | int (*bnTwoExpMod)(struct BigNum *n, struct BigNum const *exp, 85 | struct BigNum const *mod); 86 | int (*bnGcd)(struct BigNum *dest, struct BigNum const *a, 87 | struct BigNum const *b); 88 | int (*bnInv)(struct BigNum *dest, struct BigNum const *src, 89 | struct BigNum const *mod); 90 | int (*bnLShift)(struct BigNum *dest, unsigned amt); 91 | void (*bnRShift)(struct BigNum *dest, unsigned amt); 92 | unsigned (*bnMakeOdd)(struct BigNum *n); 93 | int (*bnBasePrecompBegin)(struct BnBasePrecomp *pre, struct BigNum const *base, 94 | struct BigNum const *mod, unsigned maxebits); 95 | int (*bnBasePrecompCopy)(struct BnBasePrecomp *dst, 96 | struct BnBasePrecomp const *src); 97 | void (*bnBasePrecompEnd)(struct BnBasePrecomp *pre); 98 | int (*bnBasePrecompExpMod)(struct BigNum *dest, 99 | struct BnBasePrecomp const *pre, struct BigNum const *exp, 100 | struct BigNum const *mod); 101 | int (*bnDoubleBasePrecompExpMod)(struct BigNum *dest, 102 | struct BnBasePrecomp const *pre1, struct BigNum const *exp1, 103 | struct BnBasePrecomp const *pre2, struct BigNum const *exp2, 104 | struct BigNum const *mod); 105 | -------------------------------------------------------------------------------- /third_party/bnlib/bn00.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bn00.c - auto-size-detecting bn??.c file. 6 | * 7 | * Written in 1995 by Colin Plumb. 8 | */ 9 | 10 | #include "bnsize00.h" 11 | 12 | #if BNSIZE64 13 | 14 | /* Include all of the C source file by reference */ 15 | #include "bn64.c" 16 | #include "bninit64.c" 17 | 18 | #elif BNSIZE32 19 | 20 | /* Include all of the C source file by reference */ 21 | #include "bn32.c" 22 | #include "bninit32.c" 23 | 24 | #else /* BNSIZE16 */ 25 | 26 | /* Include all of the C source file by reference */ 27 | #include "bn16.c" 28 | #include "bninit16.c" 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /third_party/bnlib/bn16.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bn16.h - interface to 16-bit bignum routines. 6 | */ 7 | struct BigNum; 8 | struct BnBasePrecomp; 9 | 10 | void bnInit_16(void); 11 | void bnEnd_16(struct BigNum *bn); 12 | int bnPrealloc_16(struct BigNum *bn, unsigned bits); 13 | int bnCopy_16(struct BigNum *dest, struct BigNum const *src); 14 | int bnSwap_16(struct BigNum *a, struct BigNum *b); 15 | void bnNorm_16(struct BigNum *bn); 16 | void bnExtractBigBytes_16(struct BigNum const *bn, unsigned char *dest, 17 | unsigned lsbyte, unsigned dlen); 18 | int bnInsertBigBytes_16(struct BigNum *bn, unsigned char const *src, 19 | unsigned lsbyte, unsigned len); 20 | void bnExtractLittleBytes_16(struct BigNum const *bn, unsigned char *dest, 21 | unsigned lsbyte, unsigned dlen); 22 | int bnInsertLittleBytes_16(struct BigNum *bn, unsigned char const *src, 23 | unsigned lsbyte, unsigned len); 24 | unsigned bnLSWord_16(struct BigNum const *src); 25 | int bnReadBit_16(struct BigNum const *bn, unsigned bit); 26 | unsigned bnBits_16(struct BigNum const *src); 27 | int bnAdd_16(struct BigNum *dest, struct BigNum const *src); 28 | int bnSub_16(struct BigNum *dest, struct BigNum const *src); 29 | int bnCmpQ_16(struct BigNum const *a, unsigned b); 30 | int bnSetQ_16(struct BigNum *dest, unsigned src); 31 | int bnAddQ_16(struct BigNum *dest, unsigned src); 32 | int bnSubQ_16(struct BigNum *dest, unsigned src); 33 | int bnCmp_16(struct BigNum const *a, struct BigNum const *b); 34 | int bnSquare_16(struct BigNum *dest, struct BigNum const *src); 35 | int bnMul_16(struct BigNum *dest, struct BigNum const *a, 36 | struct BigNum const *b); 37 | int bnMulQ_16(struct BigNum *dest, struct BigNum const *a, unsigned b); 38 | int bnDivMod_16(struct BigNum *q, struct BigNum *r, struct BigNum const *n, 39 | struct BigNum const *d); 40 | int bnMod_16(struct BigNum *dest, struct BigNum const *src, 41 | struct BigNum const *d); 42 | unsigned bnModQ_16(struct BigNum const *src, unsigned d); 43 | int bnExpMod_16(struct BigNum *dest, struct BigNum const *n, 44 | struct BigNum const *exp, struct BigNum const *mod); 45 | int bnDoubleExpMod_16(struct BigNum *dest, 46 | struct BigNum const *n1, struct BigNum const *e1, 47 | struct BigNum const *n2, struct BigNum const *e2, 48 | struct BigNum const *mod); 49 | int bnTwoExpMod_16(struct BigNum *n, struct BigNum const *exp, 50 | struct BigNum const *mod); 51 | int bnGcd_16(struct BigNum *dest, struct BigNum const *a, 52 | struct BigNum const *b); 53 | int bnInv_16(struct BigNum *dest, struct BigNum const *src, 54 | struct BigNum const *mod); 55 | int bnLShift_16(struct BigNum *dest, unsigned amt); 56 | void bnRShift_16(struct BigNum *dest, unsigned amt); 57 | unsigned bnMakeOdd_16(struct BigNum *n); 58 | int bnBasePrecompBegin_16(struct BnBasePrecomp *pre, struct BigNum const *base, 59 | struct BigNum const *mod, unsigned maxebits); 60 | void bnBasePrecompEnd_16(struct BnBasePrecomp *pre); 61 | int bnBasePrecompExpMod_16(struct BigNum *dest, struct BnBasePrecomp const *pre, 62 | struct BigNum const *exp, struct BigNum const *mod); 63 | int bnDoubleBasePrecompExpMod_16(struct BigNum *dest, 64 | struct BnBasePrecomp const *pre1, struct BigNum const *exp1, 65 | struct BnBasePrecomp const *pre2, struct BigNum const *exp2, 66 | struct BigNum const *mod); 67 | -------------------------------------------------------------------------------- /third_party/bnlib/bn32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bn32.h - interface to 32-bit bignum routines. 6 | */ 7 | struct BigNum; 8 | struct BnBasePrecomp; 9 | 10 | void bnInit_32(void); 11 | void bnEnd_32(struct BigNum *bn); 12 | int bnPrealloc_32(struct BigNum *bn, unsigned bits); 13 | int bnCopy_32(struct BigNum *dest, struct BigNum const *src); 14 | int bnSwap_32(struct BigNum *a, struct BigNum *b); 15 | void bnNorm_32(struct BigNum *bn); 16 | void bnExtractBigBytes_32(struct BigNum const *bn, unsigned char *dest, 17 | unsigned lsbyte, unsigned dlen); 18 | int bnInsertBigBytes_32(struct BigNum *bn, unsigned char const *src, 19 | unsigned lsbyte, unsigned len); 20 | void bnExtractLittleBytes_32(struct BigNum const *bn, unsigned char *dest, 21 | unsigned lsbyte, unsigned dlen); 22 | int bnInsertLittleBytes_32(struct BigNum *bn, unsigned char const *src, 23 | unsigned lsbyte, unsigned len); 24 | unsigned bnLSWord_32(struct BigNum const *src); 25 | int bnReadBit_32(struct BigNum const *bn, unsigned bit); 26 | unsigned bnBits_32(struct BigNum const *src); 27 | int bnAdd_32(struct BigNum *dest, struct BigNum const *src); 28 | int bnSub_32(struct BigNum *dest, struct BigNum const *src); 29 | int bnCmpQ_32(struct BigNum const *a, unsigned b); 30 | int bnSetQ_32(struct BigNum *dest, unsigned src); 31 | int bnAddQ_32(struct BigNum *dest, unsigned src); 32 | int bnSubQ_32(struct BigNum *dest, unsigned src); 33 | int bnCmp_32(struct BigNum const *a, struct BigNum const *b); 34 | int bnSquare_32(struct BigNum *dest, struct BigNum const *src); 35 | int bnMul_32(struct BigNum *dest, struct BigNum const *a, 36 | struct BigNum const *b); 37 | int bnMulQ_32(struct BigNum *dest, struct BigNum const *a, unsigned b); 38 | int bnDivMod_32(struct BigNum *q, struct BigNum *r, struct BigNum const *n, 39 | struct BigNum const *d); 40 | int bnMod_32(struct BigNum *dest, struct BigNum const *src, 41 | struct BigNum const *d); 42 | unsigned bnModQ_32(struct BigNum const *src, unsigned d); 43 | int bnExpMod_32(struct BigNum *dest, struct BigNum const *n, 44 | struct BigNum const *exp, struct BigNum const *mod); 45 | int bnDoubleExpMod_32(struct BigNum *dest, 46 | struct BigNum const *n1, struct BigNum const *e1, 47 | struct BigNum const *n2, struct BigNum const *e2, 48 | struct BigNum const *mod); 49 | int bnTwoExpMod_32(struct BigNum *n, struct BigNum const *exp, 50 | struct BigNum const *mod); 51 | int bnGcd_32(struct BigNum *dest, struct BigNum const *a, 52 | struct BigNum const *b); 53 | int bnInv_32(struct BigNum *dest, struct BigNum const *src, 54 | struct BigNum const *mod); 55 | int bnLShift_32(struct BigNum *dest, unsigned amt); 56 | void bnRShift_32(struct BigNum *dest, unsigned amt); 57 | unsigned bnMakeOdd_32(struct BigNum *n); 58 | int bnBasePrecompBegin_32(struct BnBasePrecomp *pre, struct BigNum const *base, 59 | struct BigNum const *mod, unsigned maxebits); 60 | void bnBasePrecompEnd_32(struct BnBasePrecomp *pre); 61 | int bnBasePrecompExpMod_32(struct BigNum *dest, struct BnBasePrecomp const *pre, 62 | struct BigNum const *exp, struct BigNum const *mod); 63 | int bnDoubleBasePrecompExpMod_32(struct BigNum *dest, 64 | struct BnBasePrecomp const *pre1, struct BigNum const *exp1, 65 | struct BnBasePrecomp const *pre2, struct BigNum const *exp2, 66 | struct BigNum const *mod); 67 | -------------------------------------------------------------------------------- /third_party/bnlib/bn64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bn64.h - interface to 64-bit bignum routines. 6 | */ 7 | struct BigNum; 8 | struct BnBasePrecomp; 9 | 10 | void bnInit_64(void); 11 | void bnEnd_64(struct BigNum *bn); 12 | int bnPrealloc_64(struct BigNum *bn, unsigned bits); 13 | int bnCopy_64(struct BigNum *dest, struct BigNum const *src); 14 | int bnSwap_64(struct BigNum *a, struct BigNum *b); 15 | void bnNorm_64(struct BigNum *bn); 16 | void bnExtractBigBytes_64(struct BigNum const *bn, unsigned char *dest, 17 | unsigned lsbyte, unsigned dlen); 18 | int bnInsertBigBytes_64(struct BigNum *bn, unsigned char const *src, 19 | unsigned lsbyte, unsigned len); 20 | void bnExtractLittleBytes_64(struct BigNum const *bn, unsigned char *dest, 21 | unsigned lsbyte, unsigned dlen); 22 | int bnInsertLittleBytes_64(struct BigNum *bn, unsigned char const *src, 23 | unsigned lsbyte, unsigned len); 24 | unsigned bnLSWord_64(struct BigNum const *src); 25 | int bnReadBit_64(struct BigNum const *bn, unsigned bit); 26 | unsigned bnBits_64(struct BigNum const *src); 27 | int bnAdd_64(struct BigNum *dest, struct BigNum const *src); 28 | int bnSub_64(struct BigNum *dest, struct BigNum const *src); 29 | int bnCmpQ_64(struct BigNum const *a, unsigned b); 30 | int bnSetQ_64(struct BigNum *dest, unsigned src); 31 | int bnAddQ_64(struct BigNum *dest, unsigned src); 32 | int bnSubQ_64(struct BigNum *dest, unsigned src); 33 | int bnCmp_64(struct BigNum const *a, struct BigNum const *b); 34 | int bnSquare_64(struct BigNum *dest, struct BigNum const *src); 35 | int bnMul_64(struct BigNum *dest, struct BigNum const *a, 36 | struct BigNum const *b); 37 | int bnMulQ_64(struct BigNum *dest, struct BigNum const *a, unsigned b); 38 | int bnDivMod_64(struct BigNum *q, struct BigNum *r, struct BigNum const *n, 39 | struct BigNum const *d); 40 | int bnMod_64(struct BigNum *dest, struct BigNum const *src, 41 | struct BigNum const *d); 42 | unsigned bnModQ_64(struct BigNum const *src, unsigned d); 43 | int bnExpMod_64(struct BigNum *dest, struct BigNum const *n, 44 | struct BigNum const *exp, struct BigNum const *mod); 45 | int bnDoubleExpMod_64(struct BigNum *dest, 46 | struct BigNum const *n1, struct BigNum const *e1, 47 | struct BigNum const *n2, struct BigNum const *e2, 48 | struct BigNum const *mod); 49 | int bnTwoExpMod_64(struct BigNum *n, struct BigNum const *exp, 50 | struct BigNum const *mod); 51 | int bnGcd_64(struct BigNum *dest, struct BigNum const *a, 52 | struct BigNum const *b); 53 | int bnInv_64(struct BigNum *dest, struct BigNum const *src, 54 | struct BigNum const *mod); 55 | int bnLShift_64(struct BigNum *dest, unsigned amt); 56 | void bnRShift_64(struct BigNum *dest, unsigned amt); 57 | unsigned bnMakeOdd_64(struct BigNum *n); 58 | int bnBasePrecompBegin_64(struct BnBasePrecomp *pre, struct BigNum const *base, 59 | struct BigNum const *mod, unsigned maxebits); 60 | void bnBasePrecompEnd_64(struct BnBasePrecomp *pre); 61 | int bnBasePrecompExpMod_64(struct BigNum *dest, struct BnBasePrecomp const *pre, 62 | struct BigNum const *exp, struct BigNum const *mod); 63 | int bnDoubleBasePrecompExpMod_64(struct BigNum *dest, 64 | struct BnBasePrecomp const *pre1, struct BigNum const *exp1, 65 | struct BnBasePrecomp const *pre2, struct BigNum const *exp2, 66 | struct BigNum const *mod); 67 | -------------------------------------------------------------------------------- /third_party/bnlib/bn68000.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bn68000.c - bnInit() for Motorola 680x0 family, 16 or 32-bit. 6 | * 7 | * Written in 1995 by Colin Plumb. 8 | */ 9 | 10 | #include "lbn.h" 11 | #include "bn16.h" 12 | #include "bn32.h" 13 | 14 | #ifndef BNINCLUDE 15 | #error You must define BNINCLUDE to lbn68000.h to use assembly primitives. 16 | #endif 17 | 18 | void 19 | bnInit(void) 20 | { 21 | if (is68020()) 22 | bnInit_32(); 23 | else 24 | bnInit_16(); 25 | } 26 | -------------------------------------------------------------------------------- /third_party/bnlib/bn8086.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bn8086.c - bnInit() for Intel x86 family in 16-bit mode. 6 | * 7 | * Written in 1995 by Colin Plumb. 8 | */ 9 | 10 | #include "lbn.h" 11 | #include "bn16.h" 12 | #include "bn32.h" 13 | 14 | #ifndef BNINCLUDE 15 | #error You must define BNINCLUDE to lbn8086.h to use assembly primitives. 16 | #endif 17 | 18 | void 19 | bnInit(void) 20 | { 21 | if (not386()) 22 | bnInit_16(); 23 | else 24 | bnInit_32(); 25 | } 26 | -------------------------------------------------------------------------------- /third_party/bnlib/bnconfig.hin: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bnconfig.h -- Configuration file for BigNum library. 6 | * 7 | * This file is automatically filled in by configure. 8 | * Everything must start out turned *off*, because configure 9 | * (or, more properly, config.status) only knows how to turn them 10 | * *on*. 11 | */ 12 | #ifndef CONFIG_H 13 | #define CONFIG_H 14 | 15 | /* Define to empty if the compiler does not support 'const' variables. */ 16 | #undef const 17 | 18 | /* Define to `unsigned' if doesn't define it. */ 19 | #undef size_t 20 | 21 | /* Checks for the presence and absence of various header files */ 22 | #define HAVE_ASSERT_H 0 23 | #define NO_ASSERT_H !HAVE_ASSERT_H 24 | #define HAVE_LIMITS_H 0 25 | #define NO_LIMITS_H !HAVE_LIMITS_H 26 | #define HAVE_STDLIB_H 0 27 | #define NO_STDLIB_H !HAVE_STDLIB_H 28 | #define HAVE_STRING_H 0 29 | #define NO_STRING_H !HAVE_STRING_H 30 | 31 | #define HAVE_STRINGS_H 0 32 | 33 | /* We go to some trouble to find accurate times... */ 34 | 35 | /* Define if you have Posix.4 glock_gettime() */ 36 | #define HAVE_CLOCK_GETTIME 0 37 | /* Define if you have Solaris-style gethrvtime() */ 38 | #define HAVE_GETHRVTIME 0 39 | /* Define if you have getrusage() */ 40 | #define HAVE_GETRUSAGE 0 41 | /* Define if you have clock() */ 42 | #define HAVE_CLOCK 0 43 | /* Define if you have time() */ 44 | #define HAVE_TIME 0 45 | 46 | /* 47 | * Define as 0 if #including automatically 48 | * #includes , and doing so explicitly causes an 49 | * error. 50 | */ 51 | #define TIME_WITH_SYS_TIME 0 52 | 53 | /* Defines for various kinds of library brokenness */ 54 | 55 | /* If not available, bcopy() is substituted */ 56 | #define HAVE_MEMMOVE 0 57 | #define NO_MEMMOVE !HAVE_MEMMOVE 58 | #define HAVE_MEMCPY 0 59 | #define NO_MEMCPY !HAVE_MEMCPY 60 | 61 | #endif /* CONFIG_H */ 62 | -------------------------------------------------------------------------------- /third_party/bnlib/bnconfig.win: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bnconfig.h -- Configuration file for BigNum library. 6 | * 7 | * This file is automatically filled in by configure. 8 | * Everything must start out turned *off*, because configure 9 | * (or, more properly, config.status) only knows how to turn them 10 | * *on*. 11 | */ 12 | #ifndef CONFIG_H 13 | #define CONFIG_H 14 | 15 | /* Define to empty if the compiler does not support 'const' variables. */ 16 | #undef const 17 | 18 | /* Define to `unsigned' if doesn't define it. */ 19 | #undef size_t 20 | 21 | /* Checks for the presence and absence of various header files */ 22 | #define HAVE_ASSERT_H 1 23 | #define NO_ASSERT_H !HAVE_ASSERT_H 24 | #define HAVE_LIMITS_H 1 25 | #define NO_LIMITS_H !HAVE_LIMITS_H 26 | #define HAVE_STDLIB_H 1 27 | #define NO_STDLIB_H !HAVE_STDLIB_H 28 | #define HAVE_STRING_H 1 29 | #define NO_STRING_H !HAVE_STRING_H 30 | 31 | #define HAVE_STRINGS_H 0 32 | 33 | /* We go to some trouble to find accurate times... */ 34 | 35 | /* Define if you have Posix.4 glock_gettime() */ 36 | #define HAVE_CLOCK_GETTIME 0 37 | /* Define if you have Solaris-style gethrvtime() */ 38 | #define HAVE_GETHRVTIME 0 39 | /* Define if you have getrusage() */ 40 | #define HAVE_GETRUSAGE 0 41 | /* Define if you have clock() */ 42 | #define HAVE_CLOCK 0 43 | /* Define if you have time() */ 44 | #define HAVE_TIME 0 45 | 46 | /* 47 | * Define as 0 if #including automatically 48 | * #includes , and doing so explicitly causes an 49 | * error. 50 | */ 51 | #define TIME_WITH_SYS_TIME 0 52 | 53 | /* Defines for various kinds of library brokenness */ 54 | 55 | /* If not available, bcopy() is substituted */ 56 | #define HAVE_MEMMOVE 1 57 | #define NO_MEMMOVE !HAVE_MEMMOVE 58 | #define HAVE_MEMCPY 1 59 | #define NO_MEMCPY !HAVE_MEMCPY 60 | 61 | #endif /* CONFIG_H */ 62 | -------------------------------------------------------------------------------- /third_party/bnlib/bninit16.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bninit16.c - Provide an init function that sets things up for 16-bit 6 | * operation. This is a seaparate tiny file so you can compile two bn 7 | * packages into the library and write a custom init routine. 8 | * 9 | * Written in 1995 by Colin Plumb. 10 | */ 11 | 12 | #include "bn.h" 13 | #include "bn16.h" 14 | 15 | void 16 | bnInit(void) 17 | { 18 | bnInit_16(); 19 | } 20 | -------------------------------------------------------------------------------- /third_party/bnlib/bninit32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bninit32.c - Provide an init function that sets things up for 32-bit 6 | * operation. This is a seaparate tiny file so you can compile two bn 7 | * packages into the library and write a custom init routine. 8 | * 9 | * Written in 1995 by Colin Plumb. 10 | */ 11 | 12 | #include "bn.h" 13 | #include "bn32.h" 14 | 15 | void 16 | bnInit(void) 17 | { 18 | bnInit_32(); 19 | } 20 | -------------------------------------------------------------------------------- /third_party/bnlib/bninit64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bninit64.c - Provide an init function that sets things up for 64-bit 6 | * operation. This is a seaparate tiny file so you can compile two bn 7 | * packages into the library and write a custom init routine. 8 | * 9 | * Written in 1995 by Colin Plumb. 10 | */ 11 | 12 | #include "bn.h" 13 | #include "bn64.h" 14 | 15 | void 16 | bnInit(void) 17 | { 18 | bnInit_64(); 19 | } 20 | -------------------------------------------------------------------------------- /third_party/bnlib/bnprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bnprint.c - Print a bignum, for debugging purposes. 6 | */ 7 | #ifndef HAVE_CONFIG_H 8 | #define HAVE_CONFIG_H 0 9 | #endif 10 | #if HAVE_CONFIG_H 11 | #include "bnconfig.h" 12 | #endif 13 | 14 | /* 15 | * Some compilers complain about #if FOO if FOO isn't defined, 16 | * so do the ANSI-mandated thing explicitly... 17 | */ 18 | #ifndef NO_STRING_H 19 | #define NO_STRING_H 0 20 | #endif 21 | #ifndef HAVE_STRINGS_H 22 | #define HAVE_STRINGS_H 0 23 | #endif 24 | 25 | #include 26 | 27 | #if !NO_STRING_H 28 | #include 29 | #elif HAVE_STRINGS_H 30 | #include 31 | #endif 32 | 33 | #include "bn.h" 34 | #include "bnprint.h" 35 | 36 | #include "kludge.h" 37 | 38 | int 39 | bnPrint(FILE *f, char const *prefix, struct BigNum const *bn, 40 | char const *suffix) 41 | { 42 | unsigned char temp[32]; /* How much to print on one line */ 43 | unsigned len; 44 | size_t i; 45 | 46 | if (prefix && fputs(prefix, f) < 0) 47 | return EOF; 48 | 49 | len = (bnBits(bn) + 7)/ 8; 50 | 51 | if (!len) { 52 | if (putc('0', f) < 0) 53 | return EOF; 54 | } else { 55 | while (len > sizeof(temp)) { 56 | len -= sizeof(temp); 57 | bnExtractBigBytes(bn, temp, len, sizeof(temp)); 58 | for (i = 0; i < sizeof(temp); i++) 59 | if (fprintf(f, "%02X", temp[i]) < 0) 60 | return EOF; 61 | if (putc('\\', f) < 0 || putc('\n', f) < 0) 62 | return EOF; 63 | if (prefix) { 64 | i = strlen(prefix); 65 | while (i--) 66 | if (putc(' ', f) < 0) 67 | return EOF; 68 | } 69 | } 70 | bnExtractBigBytes(bn, temp, 0, len); 71 | for (i = 0; i < len; i++) 72 | if (fprintf(f, "%02X", temp[i]) < 0) 73 | return EOF; 74 | } 75 | return suffix ? fputs(suffix, f) : 0; 76 | } 77 | -------------------------------------------------------------------------------- /third_party/bnlib/bnprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | #ifndef BNPRINT_H 6 | #define BNPRINT_H 7 | 8 | #include 9 | struct BigNum; 10 | 11 | int bnPrint(FILE *f, char const *prefix, struct BigNum const *bn, 12 | char const *suffix); 13 | 14 | #endif /* BNPRINT_H */ 15 | -------------------------------------------------------------------------------- /third_party/bnlib/bnsize00.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bnsize00.h - pick the correct machine word size to use. 6 | */ 7 | #include "lbn.h" /* Get basic information */ 8 | 9 | #if !BNSIZE64 && !BNSIZE32 && !BNSIZE16 && defined(BNWORD64) 10 | # if defined(BNWORD128) || (defined(lbnMulAdd1_64) && defined(lbnMulSub1_64)) 11 | # define BNSIZE64 1 12 | # elif defined(mul64_ppmm) || defined(mul64_ppmma) || defined(mul64_ppmmaa) 13 | # define BNSIZE64 1 14 | # endif 15 | #endif 16 | 17 | #if !BNSIZE64 && !BNSIZE32 && !BNSIZE16 && defined(BNWORD32) 18 | # if defined(BNWORD64) || (defined(lbnMulAdd1_32) && defined(lbnMulSub1_32)) 19 | # define BNSIZE32 1 20 | # elif defined(mul32_ppmm) || defined(mul32_ppmma) || defined(mul32_ppmmaa) 21 | # define BNSIZE32 1 22 | # endif 23 | #endif 24 | 25 | #if !BNSIZE64 && !BNSIZE32 && !BNSIZE16 && defined(BNWORD16) 26 | # if defined(BNWORD32) || (defined(lbnMulAdd1_16) && defined(lbnMulSub1_16)) 27 | # define BNSIZE16 1 28 | # elif defined(mul16_ppmm) || defined(mul16_ppmma) || defined(mul16_ppmmaa) 29 | # define BNSIZE16 1 30 | # endif 31 | #endif 32 | 33 | #if !BNSIZE64 && !BNSIZE32 && !BNSIZE16 34 | #error Unable to find a viable word size to compile bignum library. 35 | #endif 36 | -------------------------------------------------------------------------------- /third_party/bnlib/bntest00.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * bntest00.c - auto-size-detecting bntest??.c file. 6 | * 7 | * Written in 1995 by Colin Plumb. 8 | */ 9 | 10 | #include "bnsize00.h" 11 | 12 | #if BNSIZE64 13 | 14 | #include "bntest64.c" 15 | 16 | #elif BNSIZE32 17 | 18 | #include "bntest32.c" 19 | 20 | #else /* BNSIZE16 */ 21 | 22 | #include "bntest16.c" 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /third_party/bnlib/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | aclocal 4 | autoconf 5 | 6 | -------------------------------------------------------------------------------- /third_party/bnlib/cfg: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1995 Colin Plumb. All rights reserved. 2 | # For licensing and other legal details, see the file legal.c. 3 | # 4 | ./configure CFLAGS="$CFLAGS -O3 -g0 -W -Wall" 5 | -------------------------------------------------------------------------------- /third_party/bnlib/cfg.debug: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1995 Colin Plumb. All rights reserved. 2 | # For licensing and other legal details, see the file legal.c. 3 | # 4 | ./configure CFLAGS="$CFLAGS -O0 -g3" 5 | -------------------------------------------------------------------------------- /third_party/bnlib/germain.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | struct BigNum; 6 | 7 | /* Generate a Sophie Germain prime */ 8 | int germainPrimeGen(struct BigNum *bn, unsigned order, 9 | int (*f)(void *arg, int c), void *arg); 10 | /* The same, but search for using the given step size */ 11 | int germainPrimeGenStrong(struct BigNum *bn, struct BigNum const *step, 12 | unsigned order, int (*f)(void *arg, int c), void *arg); 13 | -------------------------------------------------------------------------------- /third_party/bnlib/jacobi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * Compute the Jacobi symbol (small prime case only). 6 | */ 7 | #include "bn.h" 8 | #include "jacobi.h" 9 | 10 | /* 11 | * For a small (usually prime, but not necessarily) prime p, 12 | * compute Jacobi(p,bn), which is -1, 0 or +1, using the following rules: 13 | * Jacobi(x, y) = Jacobi(x mod y, y) 14 | * Jacobi(0, y) = 0 15 | * Jacobi(1, y) = 1 16 | * Jacobi(2, y) = 0 if y is even, +1 if y is +/-1 mod 8, -1 if y = +/-3 mod 8 17 | * Jacobi(x1*x2, y) = Jacobi(x1, y) * Jacobi(x2, y) (used with x1 = 2 & x1 = 4) 18 | * If x and y are both odd, then 19 | * Jacobi(x, y) = Jacobi(y, x) * (-1 if x = y = 3 mod 4, +1 otherwise) 20 | */ 21 | int 22 | bnJacobiQ(unsigned p, struct BigNum const *bn) 23 | { 24 | int j = 1; 25 | unsigned u = bnLSWord(bn); 26 | 27 | if (!(u & 1)) 28 | return 0; /* Don't *do* that */ 29 | 30 | /* First, get rid of factors of 2 in p */ 31 | while ((p & 3) == 0) 32 | p >>= 2; 33 | if ((p & 1) == 0) { 34 | p >>= 1; 35 | if ((u ^ u>>1) & 2) 36 | j = -j; /* 3 (011) or 5 (101) mod 8 */ 37 | } 38 | if (p == 1) 39 | return j; 40 | /* Then, apply quadratic reciprocity */ 41 | if (p & u & 2) /* p = u = 3 (mod 4? */ 42 | j = -j; 43 | /* And reduce u mod p */ 44 | u = bnModQ(bn, p); 45 | 46 | /* Now compute Jacobi(u,p), u < p */ 47 | while (u) { 48 | while ((u & 3) == 0) 49 | u >>= 2; 50 | if ((u & 1) == 0) { 51 | u >>= 1; 52 | if ((p ^ p>>1) & 2) 53 | j = -j; /* 3 (011) or 5 (101) mod 8 */ 54 | } 55 | if (u == 1) 56 | return j; 57 | /* Now both u and p are odd, so use quadratic reciprocity */ 58 | if (u < p) { 59 | unsigned t = u; u = p; p = t; 60 | if (u & p & 2) /* u = p = 3 (mod 4? */ 61 | j = -j; 62 | } 63 | /* Now u >= p, so it can be reduced */ 64 | u %= p; 65 | } 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /third_party/bnlib/jacobi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * For a small (usually prime, but not necessarily) prime p, 6 | * Return Jacobi(p,bn), which is -1, 0 or +1. 7 | * bn must be odd. 8 | */ 9 | struct BigNum; 10 | int bnJacobiQ(unsigned p, struct BigNum const *bn); 11 | -------------------------------------------------------------------------------- /third_party/bnlib/kludge.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | #ifndef KLUDGE_H 6 | #define KLUDGE_H 7 | 8 | /* 9 | * Kludges for not-quite-ANSI systems. 10 | * This should always be the last file included, because it may 11 | * mess up some system header files. 12 | */ 13 | 14 | /* 15 | * Some compilers complain about #if FOO if FOO isn't defined, 16 | * so do the ANSI-mandated thing explicitly... 17 | */ 18 | #ifndef NO_STDLIB_H 19 | #define NO_STDLIB_H 0 20 | #endif 21 | 22 | #ifndef NO_MEMMOVE 23 | #define NO_MEMMOVE 0 24 | #endif 25 | #if NO_MEMMOVE /* memove() not in libraries */ 26 | #define memmove(dest,src,len) bcopy(src,dest,len) 27 | #endif 28 | 29 | #ifndef NO_MEMCPY 30 | #define NO_MEMCPY 0 31 | #endif 32 | #if NO_MEMCPY /* memcpy() not in libraries */ 33 | #define memcpy(dest,src,len) bcopy(src,dest,len) 34 | #endif 35 | 36 | /* 37 | * Borland C seems to think that it's a bad idea to decleare a 38 | * structure tag and not declare the contents. I happen to think 39 | * it's a *good* idea to use such "opaque" structures wherever 40 | * possible. So shut up. 41 | */ 42 | #ifdef __BORLANDC__ 43 | #pragma warn -stu 44 | #ifndef MSDOS 45 | #define MSDOS 1 46 | #endif 47 | #endif 48 | 49 | /* Turn off warning about negation of unsigned values */ 50 | #ifdef _MSC_VER 51 | #pragma warning(disable:4146) 52 | #endif 53 | 54 | /* Cope with people forgetting to define the OS, if possible... */ 55 | #ifndef MSDOS 56 | #ifdef __MSDOS 57 | #define MSDOS 1 58 | #endif 59 | #endif 60 | #ifndef MSDOS 61 | #ifdef __MSDOS__ 62 | #define MSDOS 1 63 | #endif 64 | #endif 65 | 66 | /* By MS-DOS, we mean 16-bit brain-dead MS-DOS. Not GCC & GO32 */ 67 | #ifdef __GO32 68 | #undef MSDOS 69 | #endif 70 | #ifdef __GO32__ 71 | #undef MSDOS 72 | #endif 73 | 74 | #endif /* KLUDGE_H */ 75 | -------------------------------------------------------------------------------- /third_party/bnlib/lbn00.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * lbn00.c - auto-size-detecting lbn??.c file. 6 | * 7 | * Written in 1995 by Colin Plumb. 8 | */ 9 | 10 | #include "bnsize00.h" 11 | 12 | #if BNSIZE64 13 | 14 | /* Include all of the C source file by reference */ 15 | #include "lbn64.c" 16 | 17 | #elif BNSIZE32 18 | 19 | /* Include all of the C source file by reference */ 20 | #include "lbn32.c" 21 | 22 | #else /* BNSIZE16 */ 23 | 24 | /* Include all of the C source file by reference */ 25 | #include "lbn16.c" 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /third_party/bnlib/lbn68000.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * lbn68000.h - 16-bit bignum primitives for the 68000 (or 68010) processors. 6 | * 7 | * These primitives use little-endian word order. 8 | * (The order of bytes within words is irrelevant.) 9 | */ 10 | #define BN_LITTLE_ENDIAN 1 11 | 12 | typedef unsigned short bnword16 13 | #define BNWORD16 bnword16 14 | 15 | bnword16 lbnSub1_16(bnword16 *num, unsigned len, bnword16 borrow); 16 | bnword16 lbnAdd1_16(bnword16 *num, unsigned len, bnword16 carry); 17 | void lbnMulN1_16(bnword16 *out, bnword16 const *in, unsigned len, bnword16 k); 18 | bnword16 19 | lbnMulAdd1_16(bnword16 *out, bnword16 const *in, unsigned len, bnword16 k); 20 | bnword16 21 | lbnMulSub1_16(bnword16 *out, bnword16 const *in, unsigned len, bnword16 k); 22 | bnword16 lbnDiv21_16(bnword16 *q, bnword16 nh, bnword16 nl, bnword16 d); 23 | unsigned lbnModQ_16(bnword16 const *n, unsigned len, bnword16 d); 24 | 25 | int is68020(void); 26 | 27 | /* #define the values to exclude the C versions */ 28 | #define lbnSub1_16 lbnSub1_16 29 | #define lbnAdd1_16 lbnAdd1_16 30 | #define lbnMulN1_16 lbnMulN1_16 31 | #define lbnMulAdd1_16 lbnMulAdd1_16 32 | #define lbnMulSub1_16 lbnMulSub1_16 33 | #define lbnDiv21_16 lbnDiv21_16 34 | #define lbnModQ_16 lbnModQ_16 35 | 36 | /* Also include the 68020 definitions for 16/32 bit switching versions. */ 37 | #include 38 | -------------------------------------------------------------------------------- /third_party/bnlib/lbn68020.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * lbn68020.h - 32-bit bignum primitives for the 68020 (or 683xx) processors. 6 | * 7 | * These primitives use little-endian word order. 8 | * (The order of bytes within words is irrelevant.) 9 | */ 10 | #define BN_LITTLE_ENDIAN 1 11 | 12 | typedef unsigned long bnword32; 13 | #define BNWORD32 bnword32 14 | 15 | bnword32 lbnSub1_32(bnword32 *num, unsigned len, bnword32 borrow); 16 | bnword32 lbnAdd1_32(bnword32 *num, unsigned len, bnword32 carry); 17 | void lbnMulN1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); 18 | bnword32 19 | lbnMulAdd1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); 20 | bnword32 21 | lbnMulSub1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); 22 | bnword32 lbnDiv21_32(bnword32 *q, bnword32 nh, bnword32 nl, bnword32 d); 23 | unsigned lbnModQ_32(bnword32 const *n, unsigned len, unsigned d); 24 | 25 | /* #define the values to exclude the C versions */ 26 | #define lbnSub1_32 lbnSub1_32 27 | #define lbnAdd1_32 lbnAdd1_32 28 | #define lbnMulN1_32 lbnMulN1_32 29 | #define lbnMulAdd1_32 lbnMulAdd1_32 30 | #define lbnMulSub1_32 lbnMulSub1_32 31 | #define lbnDiv21_32 lbnDiv21_32 32 | #define lbnModQ_32 lbnModQ_32 33 | -------------------------------------------------------------------------------- /third_party/bnlib/lbn8086.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * lbn8086.h - This file defines the interfaces to the 8086 6 | * assembly primitives for 16-bit MS-DOS environments. 7 | * It is intended to be included in "lbn.h" 8 | * via the "#include BNINCLUDE" mechanism. 9 | */ 10 | 11 | #define BN_LITTLE_ENDIAN 1 12 | 13 | #ifdef __cplusplus 14 | /* These assembly-language primitives use C names */ 15 | extern "C" { 16 | #endif 17 | 18 | /* Set up the appropriate types */ 19 | typedef unsigned short bnword16; 20 | #define BNWORD16 bnword16 21 | typedef unsigned long bnword32; 22 | #define BNWORD32 bnword32 23 | 24 | void __cdecl __far 25 | lbnMulN1_16(bnword16 __far *out, bnword16 const __far *in, 26 | unsigned len, bnword16 k); 27 | #define lbnMulN1_16 lbnMulN1_16 28 | 29 | bnword16 __cdecl __far 30 | lbnMulAdd1_16(bnword16 __far *out, bnword16 const __far *in, 31 | unsigned len, bnword16 k); 32 | #define lbnMulAdd1_16 lbnMulAdd1_16 33 | 34 | bnword16 __cdecl __far 35 | lbnMulSub1_16(bnword16 __far *out, bnword16 const __far *in, 36 | unsigned len, bnword16 k); 37 | #define lbnMulSub1_16 lbnMulSub1_16 38 | 39 | bnword16 __cdecl __far 40 | lbnDiv21_16(bnword16 __far *q, bnword16 nh, bnword16 nl, bnword16 d); 41 | #define lbnDiv21_16 lbnDiv21_16 42 | 43 | bnword16 __cdecl __far 44 | lbnModQ_16(bnword16 const __far *n, unsigned len, bnword16 d); 45 | #define lbnModQ_16 lbnModQ_16 46 | 47 | 48 | 49 | void __cdecl __far 50 | lbnMulN1_32(bnword32 __far *out, bnword32 const __far *in, 51 | unsigned len, bnword32 k); 52 | #define lbnMulN1_32 lbnMulN1_32 53 | 54 | bnword32 __cdecl __far 55 | lbnMulAdd1_32(bnword32 __far *out, bnword32 const __far *in, 56 | unsigned len, bnword32 k); 57 | #define lbnMulAdd1_32 lbnMulAdd1_32 58 | 59 | bnword32 __cdecl __far 60 | lbnMulSub1_32(bnword32 __far *out, bnword32 const __far *in, 61 | unsigned len, bnword32 k); 62 | #define lbnMulSub1_32 lbnMulSub1_32 63 | 64 | bnword32 __cdecl __far 65 | lbnDiv21_32(bnword32 __far *q, bnword32 nh, bnword32 nl, bnword32 d); 66 | #define lbnDiv21_32 lbnDiv21_32 67 | 68 | bnword16 __cdecl __far 69 | lbnModQ_32(bnword32 const __far *n, unsigned len, bnword32 d); 70 | #define lbnModQ_32 lbnModQ_32 71 | 72 | int __cdecl __far not386(void); 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | -------------------------------------------------------------------------------- /third_party/bnlib/lbn960jx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * lbn960jx.h - This file defines the interfaces to assembly primitives 6 | * for the the Intel i960Jx series of processors. In fact, these thould 7 | * work on any i960 series processor, but haven't been tested. 8 | * It is intended to be included in "lbn.h" 9 | * via the "#include BNINCLUDE" mechanism. 10 | */ 11 | 12 | #define BN_LITTLE_ENDIAN 1 13 | 14 | typedef unsigned long bnword32; 15 | #define BNWORD32 bnword32; 16 | 17 | 18 | #ifdef __cplusplus 19 | /* These assembly-language primitives use C names */ 20 | extern "C" { 21 | #endif 22 | 23 | /* Function prototypes for the asm routines */ 24 | void 25 | lbnMulN1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); 26 | #define lbnMulN1_32 lbnMulN1_32 27 | 28 | bnword32 29 | lbnMulAdd1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); 30 | #define lbnMulAdd1_32 lbnMulAdd1_32 31 | 32 | bnword32 33 | lbnMulSub1_32(bnword32 *out, bnword32 const *in, unsigned len, bnword32 k); 34 | #define lbnMulSub1_32 lbnMulSub1_32 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | -------------------------------------------------------------------------------- /third_party/bnlib/lbnalpha.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * lbnalpha.h - header file that declares the Alpha assembly-language 6 | * subroutines. It is intended to be included via the BNINCLUDE 7 | * mechanism. 8 | */ 9 | 10 | #define BN_LITTLE_ENDIAN 1 11 | 12 | typedef unsigned long bnword64; 13 | #define BNWORD64 bnword64 14 | 15 | #ifdef __cplusplus 16 | /* These assembly-language primitives use C names */ 17 | extern "C" { 18 | #endif 19 | 20 | void lbnMulN1_64(bnword64 *out, bnword64 const *in, unsigned len, bnword64 k); 21 | #define lbnMulN1_64 lbnMulN1_64 22 | 23 | bnword64 24 | lbnMulAdd1_64(bnword64 *out, bnword64 const *in, unsigned len, bnword64 k); 25 | #define lbnMulAdd1_64 lbnMulAdd1_64 26 | 27 | bnword64 28 | lbnMulSub1_64(bnword64 *out, bnword64 const *in, unsigned len, bnword64 k); 29 | #define lbnMulSub1_64 lbnMulSub1_64 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /third_party/bnlib/lbnmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * lbnmem.c - low-level bignum memory handling. 6 | * 7 | * Note that in all cases, the pointers passed around 8 | * are pointers to the *least* significant end of the word. 9 | * On big-endian machines, these are pointers to the *end* 10 | * of the allocated range. 11 | * 12 | * BNSECURE is a simple level of security; for more security 13 | * change these function to use locked unswappable memory. 14 | */ 15 | #ifndef HAVE_CONFIG_H 16 | #define HAVE_CONFIG_H 0 17 | #endif 18 | #if HAVE_CONFIG_H 19 | #include "bnconfig.h" 20 | #endif 21 | 22 | /* 23 | * Some compilers complain about #if FOO if FOO isn't defined, 24 | * so do the ANSI-mandated thing explicitly... 25 | */ 26 | #ifndef NO_STDLIB_H 27 | #define NO_STDLIB_H 0 28 | #endif 29 | #ifndef NO_STRING_H 30 | #define NO_STRING_H 0 31 | #endif 32 | #ifndef HAVE_STRINGS_H 33 | #define HAVE_STRINGS_H 0 34 | #endif 35 | 36 | #if !NO_STDLIB_H 37 | #include /* For malloc() & co. */ 38 | #else 39 | void *malloc(); 40 | void *realloc(); 41 | void free(); 42 | #endif 43 | 44 | #if !NO_STRING_H 45 | #include /* For memset */ 46 | #elif HAVE_STRINGS_H 47 | #include 48 | #endif 49 | 50 | #ifndef DBMALLOC 51 | #define DBMALLOC 0 52 | #endif 53 | #if DBMALLOC 54 | /* Development debugging */ 55 | #include "../dbmalloc/malloc.h" 56 | #endif 57 | 58 | #include "lbn.h" 59 | #include "lbnmem.h" 60 | 61 | #include "kludge.h" 62 | 63 | #include "zrtp.h" 64 | 65 | #ifndef lbnMemWipe 66 | void 67 | lbnMemWipe(void *ptr, unsigned bytes) 68 | { 69 | zrtp_memset(ptr, 0, bytes); 70 | } 71 | #define lbnMemWipe(ptr, bytes) memset(ptr, 0, bytes) 72 | #endif 73 | 74 | #ifndef lbnMemAlloc 75 | void * 76 | lbnMemAlloc(unsigned bytes) 77 | { 78 | return zrtp_sys_alloc(bytes); 79 | } 80 | #endif 81 | 82 | #ifndef lbnMemFree 83 | void 84 | lbnMemFree(void *ptr, unsigned bytes) 85 | { 86 | lbnMemWipe(ptr, bytes); 87 | zrtp_sys_free(ptr); 88 | } 89 | #endif 90 | 91 | #ifndef lbnRealloc 92 | #if defined(lbnMemRealloc) || !BNSECURE 93 | void * 94 | lbnRealloc(void *ptr, unsigned oldbytes, unsigned newbytes) 95 | { 96 | if (ptr) { 97 | BIG(ptr = (char *)ptr - oldbytes;) 98 | if (newbytes < oldbytes) 99 | memmove(ptr, (char *)ptr + oldbytes-newbytes, oldbytes); 100 | } 101 | #ifdef lbnMemRealloc 102 | ptr = lbnMemRealloc(ptr, oldbytes, newbytes); 103 | #else 104 | ptr = realloc(ptr, newbytes); 105 | #endif 106 | if (ptr) { 107 | if (newbytes > oldbytes) 108 | memmove((char *)ptr + newbytes-oldbytes, ptr, oldbytes); 109 | BIG(ptr = (char *)ptr + newbytes;) 110 | } 111 | 112 | return ptr; 113 | } 114 | 115 | #else /* BNSECURE */ 116 | 117 | void * 118 | lbnRealloc(void *oldptr, unsigned oldbytes, unsigned newbytes) 119 | { 120 | void *newptr = lbnMemAlloc(newbytes); 121 | 122 | if (!newptr) 123 | return newptr; 124 | if (!oldptr) 125 | return BIGLITTLE((char *)newptr+newbytes, newptr); 126 | 127 | /* 128 | * The following copies are a bit non-obvious in the big-endian case 129 | * because one of the pointers points to the *end* of allocated memory. 130 | */ 131 | if (newbytes > oldbytes) { /* Copy all of old into part of new */ 132 | BIG(newptr = (char *)newptr + newbytes;) 133 | BIG(oldptr = (char *)oldptr - oldbytes;) 134 | memcpy(BIGLITTLE((char *)newptr-oldbytes, newptr), oldptr, 135 | oldbytes); 136 | } else { /* Copy part of old into all of new */ 137 | memcpy(newptr, BIGLITTLE((char *)oldptr-newbytes, oldptr), 138 | newbytes); 139 | BIG(newptr = (char *)newptr + newbytes;) 140 | BIG(oldptr = (char *)oldptr - oldbytes;) 141 | } 142 | 143 | lbnMemFree(oldptr, oldbytes); 144 | 145 | return newptr; 146 | } 147 | #endif /* BNSECURE */ 148 | #endif /* !lbnRealloc */ 149 | -------------------------------------------------------------------------------- /third_party/bnlib/lbnmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * Operations on the usual buffers of bytes 6 | */ 7 | #ifndef BNSECURE 8 | #define BNSECURE 1 9 | #endif 10 | 11 | /* 12 | * These operations act on buffers of memory, just like malloc & free. 13 | * One exception: it is not legal to pass a NULL pointer to lbnMemFree. 14 | */ 15 | 16 | #ifndef lbnMemAlloc 17 | void *lbnMemAlloc(unsigned bytes); 18 | #endif 19 | 20 | #ifndef lbnMemFree 21 | void lbnMemFree(void *ptr, unsigned bytes); 22 | #endif 23 | 24 | /* This wipes out a buffer of bytes if necessary needed. */ 25 | 26 | #ifndef lbnMemWipe 27 | #if BNSECURE 28 | void lbnMemWipe(void *ptr, unsigned bytes); 29 | #else 30 | #define lbnMemWipe(ptr, bytes) (void)(ptr,bytes) 31 | #endif 32 | #endif /* !lbnMemWipe */ 33 | 34 | /* 35 | * lbnRealloc is NOT like realloc(); it's endian-sensitive! 36 | * If lbnMemRealloc is #defined, lbnRealloc will be defined in terms of it. 37 | * It is legal to pass a NULL pointer to lbnRealloc, although oldbytes 38 | * will always be sero. 39 | */ 40 | #ifndef lbnRealloc 41 | void *lbnRealloc(void *ptr, unsigned oldbytes, unsigned newbytes); 42 | #endif 43 | 44 | 45 | /* 46 | * These macros are the ones actually used most often in the math library. 47 | * They take and return pointers to the *end* of the given buffer, and 48 | * take sizes in terms of words, not bytes. 49 | * 50 | * Note that LBNALLOC takes the pointer as an argument instead of returning 51 | * the value. 52 | * 53 | * Note also that these macros are only useable if you have included 54 | * lbn.h (for the BIG and BIGLITTLE macros), which this file does NOT include. 55 | */ 56 | 57 | #define LBNALLOC(p,type,words) BIGLITTLE( \ 58 | if ( ((p) = (type *)lbnMemAlloc((words)*sizeof*(p))) != 0) \ 59 | (p) += (words), \ 60 | (p) = (type *)lbnMemAlloc((words) * sizeof*(p)) \ 61 | ) 62 | #define LBNFREE(p,words) lbnMemFree((p) BIG(-(words)), (words) * sizeof*(p)) 63 | #define LBNREALLOC(p,old,new) \ 64 | lbnRealloc(p, (old) * sizeof*(p), (new) * sizeof*(p)) 65 | #define LBNWIPE(p,words) lbnMemWipe((p) BIG(-(words)), (words) * sizeof*(p)) 66 | 67 | -------------------------------------------------------------------------------- /third_party/bnlib/lbnppc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | #ifndef LBNPPC_H 6 | #define LBNPPC_H 7 | 8 | /* 9 | * Assembly-language routines for the Power PC processor. 10 | * Annoyingly, the Power PC does not have 64/32->32 bit divide, 11 | * so the C code should be reasonably fast. But it does have 12 | * 32x32->64-bit multiplies, and these routines provide access 13 | * to that. 14 | * 15 | * In versions of CodeWarrior before 8.0, there was no PPC assembler, 16 | * so a kludged-up one in CPP is used. This requires casting an 17 | * array of unsigneds to function pointer type, and a function pointer 18 | * is not a pointer to the code, but rather a pointer to a (code,TOC) 19 | * pointer pair which we fake up. 20 | * 21 | * CodeWarrior 8.0 supports PCC assembly, which is used directly. 22 | */ 23 | 24 | /* 25 | * Bignums are stored in arrays of 32-bit words, and the least 26 | * significant 32-bit word has the lowest address, thus "little-endian". 27 | * The C code is slightly more efficient this way, so unless the 28 | * processor cares (the PowerPC, like most RISCs, doesn't), it is 29 | * best to use BN_LITTLE_ENDIAN. 30 | * Note that this has NOTHING to do with the order of bytes within a 32-bit 31 | * word; the math library is insensitive to that. 32 | */ 33 | #define BN_LITTLE_ENDIAN 1 34 | 35 | typedef unsigned bnword32; 36 | #define BNWORD32 bnword32 37 | 38 | #if __MWERKS__ < 0x800 39 | 40 | /* Shared transition vector array */ 41 | extern unsigned const * const lbnPPC_tv[]; 42 | 43 | /* A function pointer on the PowerPC is a pointer to a transition vector */ 44 | #define lbnMulN1_32 \ 45 | ((void (*)(bnword32 *, bnword32 const *, unsigned, bnword32))(lbnPPC_tv+0)) 46 | #define lbnMulAdd1_32 \ 47 | ((bnword32 (*)(bnword32 *, bnword32 const *, unsigned, bnword32))(lbnPPC_tv+1)) 48 | #define lbnMulSub1_32 \ 49 | ((bnword32 (*)(bnword32 *, bnword32 const *, unsigned, bnword32))(lbnPPC_tv+2)) 50 | 51 | #else /* __MWERKS__ >= 0x800 */ 52 | 53 | void lbnMulN1_32(bnword32 *, bnword32 const *, unsigned, bnword32); 54 | #define lbnMulN1_32 lbnMulN1_32 55 | bnword32 lbnMulAdd1_32(bnword32 *, bnword32 const *, unsigned, bnword32); 56 | #define lbnMulAdd1_32 lbnMulAdd1_32 57 | bnword32 lbnMulSub1_32(bnword32 *, bnword32 const *, unsigned, bnword32); 58 | #define lbnMulSub1_32 lbnMulSub1_32 59 | 60 | #endif /* __MWERKS__ >= 0x800 */ 61 | 62 | #endif /* LBNPPC_H */ 63 | -------------------------------------------------------------------------------- /third_party/bnlib/legal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * We want the copyright string to be accessable to the unix strings command 6 | * in the final linked binary, and we don't want the linker to remove it if 7 | * it's not referenced, so we do that by using the volatile qualifier. 8 | * 9 | * ANSI C standard, section 3.5.3: "An object that has volatile-qualified 10 | * type may be modified in ways unknown to the implementation or have 11 | * other unknown side effects." Yes, we can't expect a compiler to 12 | * understand law... 13 | */ 14 | extern volatile const char bnCopyright[]; 15 | -------------------------------------------------------------------------------- /third_party/bnlib/prime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | struct BigNum; 6 | 7 | /* Generate a prime >= bn. leaving the result in bn. */ 8 | int primeGen(struct BigNum *bn, unsigned (*randfunc)(unsigned), 9 | int (*f)(void *arg, int c), void *arg, unsigned exponent, ...); 10 | 11 | /* 12 | * Generate a prime of the form bn + k*step. Step must be even and 13 | * bn must be odd. 14 | */ 15 | int primeGenStrong(struct BigNum *bn, struct BigNum const *step, 16 | int (*f)(void *arg, int c), void *arg); 17 | -------------------------------------------------------------------------------- /third_party/bnlib/sieve.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * sieve.h - Trial division for prime finding. 6 | * 7 | * This is generally not intended for direct use by a user of the library; 8 | * the prime.c and dhprime.c functions. are more likely to be used. 9 | * However, a special application may need these. 10 | */ 11 | struct BigNum; 12 | 13 | /* Remove multiples of a single number from the sieve */ 14 | void 15 | sieveSingle(unsigned char *array, unsigned size, unsigned start, unsigned step); 16 | 17 | /* Build a sieve starting at the number and incrementing by "step". */ 18 | int sieveBuild(unsigned char *array, unsigned size, struct BigNum const *bn, 19 | unsigned step, unsigned dbl); 20 | 21 | /* Similar, but uses a >16-bit step size */ 22 | int sieveBuildBig(unsigned char *array, unsigned size, struct BigNum const *bn, 23 | struct BigNum const *step, unsigned dbl); 24 | 25 | /* Return the next bit set in the sieve (or 0 on failure) */ 26 | unsigned sieveSearch(unsigned char const *array, unsigned size, unsigned start); 27 | -------------------------------------------------------------------------------- /third_party/bnlib/sizetest.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | #include "bnsize00.h" 6 | 7 | #if BNSIZE16 8 | #error Using 16-bit math library 9 | #elif BNSIZE32 10 | #error Using 32-bit math library 11 | #elif BNSIZE64 12 | #error Using 64-bit math library 13 | #else 14 | #error No math library size defined 15 | #endif 16 | -------------------------------------------------------------------------------- /third_party/bnlib/test/README.dhtest: -------------------------------------------------------------------------------- 1 | Test driver for Diffie-Hellman key agreement operations. 2 | 3 | This program generates Diffie-Hellman moduli and does a sample 4 | key agreement with them. 5 | 6 | The command line is a seed string which is used to generate the 7 | public modulus. The use of a seed lets you verify that the 8 | modulus was not generated in a weak manner. 9 | 10 | Currently, the list of key sizes to generate is compiled in. 11 | 12 | After key generation, the program performs a sample key agreement. 13 | 14 | The primes used in SKIP were generated with the seed in the file 15 | Gandhi, which contains 79 bytes plus a newline: 16 | Whatever you do will be insignificant, but it is very important that you do it. 17 | 18 | Example invocation lines: 19 | 20 | dhtest arbitrary seed string 21 | dhtest `cat Gandhi` 22 | -------------------------------------------------------------------------------- /third_party/bnlib/test/README.dsatest: -------------------------------------------------------------------------------- 1 | Test driver for Digital Signature Algorithm operations. 2 | 3 | This program generates DSA keys (currently, of a few compiled-in 4 | sizes) and does timing tests on DSA operations. 5 | 6 | The command line is a seed string which is used to generate the 7 | public parameters. The use of a seed lets you verify that the 8 | key was not generated in a weak manner. 9 | 10 | Currently, the list of key sizes to generate is compiled in. 11 | 12 | After key generation, the program DSA-signs and verifies a 13 | random message, and displays the timing. 14 | 15 | Example invocation lines: 16 | 17 | dsatest arbitrary seed string 18 | dsatest foo 19 | -------------------------------------------------------------------------------- /third_party/bnlib/test/README.rsatest: -------------------------------------------------------------------------------- 1 | Rsatest is a test driver for RSA operations. 2 | 3 | Rsatest takes a list of vecimal key sizes (in bits) on the command 4 | line, and generates keys of those sizes. It generates keys randomly, 5 | using keyboard timings for a random number source, then tests the 6 | resultant keys, doing an encryption, a decryption, a signing and a 7 | verification. 8 | 9 | Example invocation lines: 10 | 11 | rsatest 512 768 1024 12 | rsatest 2048 13 | -------------------------------------------------------------------------------- /third_party/bnlib/test/first.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | -------------------------------------------------------------------------------- /third_party/bnlib/test/kb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * kb.h - interface for keyboard I/O 6 | */ 7 | 8 | /* The implementation is in kbunix.c, kbmsdos.c, kbvms.c, etc. */ 9 | 10 | void kbCbreak(void), kbNorm(void); 11 | int kbGet(void); 12 | void kbFlush(int thorough); 13 | -------------------------------------------------------------------------------- /third_party/bnlib/test/kbmsdos.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1993 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * MS-DOS non-echoing keyboard routines. 6 | */ 7 | 8 | #include /* For getch() and kbhit() */ 9 | #include /* For raise() */ 10 | #ifdef _MSC_VER 11 | #include /* For clock() */ 12 | #else 13 | #include /* For sleep() */ 14 | #endif 15 | 16 | #include "kb.h" 17 | #include "random.h" /* For randEvent() */ 18 | 19 | /* These are pretty boring */ 20 | void kbCbreak(void) { } 21 | void kbNorm(void) { } 22 | 23 | int kbGet(void) 24 | { 25 | int c; 26 | 27 | c = getch(); 28 | if (c == 0) 29 | c = 0x100 + getch(); 30 | 31 | /* 32 | * Borland C's getch() uses int 0x21 function 0x7, 33 | * which does not detect break. So we do it explicitly. 34 | */ 35 | if (c == 3) 36 | raise(SIGINT); 37 | 38 | randEvent(c); 39 | 40 | return c; 41 | } 42 | 43 | #ifdef _MSC_VER 44 | /* 45 | * Microsoft Visual C 1.5 (at least) does not have sleep() in the 46 | * library. So we use this crude approximation. ("crude" because, 47 | * assuming CLOCKS_PER_SEC is 18.2, it rounds to 18 to avoid floating 48 | * point math.) 49 | */ 50 | #ifndef CLOCKS_PER_SEC 51 | #define CLOCKS_PER_SEC CLK_TCK 52 | #endif 53 | static unsigned 54 | sleep(unsigned t) 55 | { 56 | clock_t target; 57 | 58 | target = clock() + t * (unsigned)CLOCKS_PER_SEC; 59 | while (clock() < target) 60 | ; 61 | return 0; 62 | } 63 | #endif 64 | 65 | void kbFlush(int thorough) 66 | { 67 | do { 68 | while(kbhit()) 69 | (void)getch(); 70 | if (!thorough) 71 | break; 72 | /* Extra thorough: wait for one second of quiet */ 73 | sleep(1); 74 | } while (kbhit()); 75 | } 76 | -------------------------------------------------------------------------------- /third_party/bnlib/test/keygen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | #include 6 | struct PubKey; 7 | struct SecKey; 8 | 9 | int 10 | genRsaKey(struct PubKey *pub, struct SecKey *sec, 11 | unsigned bits, unsigned exp, FILE *file); 12 | -------------------------------------------------------------------------------- /third_party/bnlib/test/keys.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * keys.c - allocate and free PubKey and SecKey structures. 6 | */ 7 | 8 | #include "first.h" 9 | 10 | #include "bn.h" 11 | 12 | #include "keys.h" 13 | #include "usuals.h" 14 | 15 | void 16 | pubKeyBegin(struct PubKey *pub) 17 | { 18 | if (pub) { 19 | bnBegin(&pub->n); 20 | bnBegin(&pub->e); 21 | } 22 | } 23 | 24 | void 25 | pubKeyEnd(struct PubKey *pub) 26 | { 27 | if (pub) { 28 | bnEnd(&pub->n); 29 | bnEnd(&pub->e); 30 | wipe(pub); 31 | } 32 | } 33 | 34 | void 35 | secKeyBegin(struct SecKey *sec) 36 | { 37 | if (sec) { 38 | bnBegin(&sec->d); 39 | bnBegin(&sec->p); 40 | bnBegin(&sec->q); 41 | bnBegin(&sec->u); 42 | } 43 | } 44 | 45 | void 46 | secKeyEnd(struct SecKey *sec) 47 | { 48 | if (sec) { 49 | bnEnd(&sec->d); 50 | bnEnd(&sec->p); 51 | bnEnd(&sec->q); 52 | bnEnd(&sec->u); 53 | wipe(sec); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /third_party/bnlib/test/keys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | #ifndef KEYS_H 6 | #define KEYS_H 7 | 8 | /* 9 | * Structures for keys. 10 | */ 11 | 12 | #include "bn.h" 13 | 14 | /* A structure to hold a public key */ 15 | struct PubKey { 16 | struct BigNum n; /* The public modulus */ 17 | struct BigNum e; /* The public exponent */ 18 | }; 19 | 20 | /* A structure to hold a secret key */ 21 | struct SecKey { 22 | struct BigNum d; /* Decryption exponent */ 23 | struct BigNum p; /* The smaller factor of n */ 24 | struct BigNum q; /* The larger factor of n */ 25 | struct BigNum u; /* 1/p (mod q) */ 26 | }; 27 | 28 | void pubKeyBegin(struct PubKey *pub); 29 | void pubKeyEnd(struct PubKey *pub); 30 | 31 | void secKeyBegin(struct SecKey *sec); 32 | void secKeyEnd(struct SecKey *sec); 33 | 34 | #endif /* KEYS_H */ 35 | -------------------------------------------------------------------------------- /third_party/bnlib/test/kludge.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | #ifndef KLUDGE_H 6 | #define KLUDGE_H 7 | 8 | /* 9 | * Kludges for not-quite-ANSI systems. 10 | * This should always be the last file included, because it may 11 | * mess up some system header files. 12 | */ 13 | 14 | #if NO_MEMMOVE /* memove() not in libraries */ 15 | #define memmove(dest,src,len) bcopy(src,dest,len) 16 | #endif 17 | 18 | #if NO_STRTOUL /* strtoul() not in libraries */ 19 | #define strtoul strtol /* Close enough */ 20 | #endif 21 | 22 | #if NO_RAISE /* raise() not in libraries */ 23 | #include /* For getpid() - kill() is in */ 24 | #define raise(sig) kill(getpid(),sig) 25 | #endif 26 | 27 | /* 28 | * Make Microsoft Visual C shut the hell up about a few things... 29 | * Warning 4116 complains about the alignof() macro, saying: 30 | * warning C4116: unnamed type definition in parentheses 31 | * I do not know of a reasonable way to recode to eliminate this warning. 32 | * Warning 4761 complains about passing an expression (which has 33 | * type int) to a function expecting something narrower - like 34 | * a ringmask, if ringmask is set to 8 bits. The error is: 35 | * warning C4761: integral size mismatch in argument : conversion supplied 36 | * I do not know of a reasonable way to recode to eliminate this warning. 37 | */ 38 | #ifdef _MSC_VER 39 | #pragma warning(disable: 4116 4761) 40 | #endif 41 | 42 | /* 43 | * Borland C seems to think that it's a bad idea to decleare a 44 | * structure tag and not declare the contents. I happen to think 45 | * it's a *good* idea to use such "opaque" structures wherever 46 | * possible. So shut up. 47 | */ 48 | #ifdef __BORLANDC__ 49 | #pragma warn -stu 50 | #endif 51 | 52 | /* Cope with people forgetting to define the OS, if possible... */ 53 | 54 | #if !defined(MSDOS) && defined(__MSDOS__) 55 | #define MSDOS 1 56 | #endif 57 | 58 | #if !defined(UNIX) && (defined(unix) || defined (__unix__)) 59 | #define UNIX 1 60 | #endif 61 | 62 | 63 | #endif /* KLUDGE_H */ 64 | -------------------------------------------------------------------------------- /third_party/bnlib/test/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | #ifndef MD5_H 6 | #define MD5_H 7 | 8 | #include 9 | #include "usuals.h" 10 | 11 | struct MD5Context { 12 | word32 buf[4]; 13 | word32 bytes[2]; 14 | word32 in[16]; 15 | }; 16 | 17 | void MD5Init(struct MD5Context *context); 18 | void MD5Update(struct MD5Context *context, byte const *buf, size_t len); 19 | void MD5Final(unsigned char digest[16], struct MD5Context *context); 20 | void MD5Transform(word32 buf[4], word32 const in[16]); 21 | 22 | void byteSwap(word32 *buf, unsigned words); 23 | 24 | #endif /* !MD5_H */ 25 | -------------------------------------------------------------------------------- /third_party/bnlib/test/noise.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * Noise.h - get environmental noise for RNG 6 | * 7 | * The interface is system-independent, but the 8 | * implementation should be highly system-dependent, 9 | * to get at as much state as possible. 10 | */ 11 | 12 | #include "usuals.h" 13 | 14 | word32 noise(void); 15 | -------------------------------------------------------------------------------- /third_party/bnlib/test/posix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * This file includes , if it's available, and 6 | * declares a bunch of functions with "traditional" values if not. 7 | * The GNU Libc Manual (node "Version Supported") says this is impossible; 8 | * I wonder what they think of this. 9 | */ 10 | 11 | #include 12 | 13 | /* 14 | * See if this is a POSIX . A POSIX system *may* define 15 | * a macro for ARG_MAX, but it may instead defined _SC_ARG_MAX 16 | * in and require you yo use sysconf() to get the value. 17 | * However, a POSIX system is supposed to defined _POSIX_ARG_MAX 18 | * in with the value of 4096, the POSIX-mandated lower 19 | * bound on ARG_MAX or sysconf(_SC_ARG_MAX). 20 | * A POSIX system is supposed to define most of these, so checking for 21 | * them *all* is overkill, but it's easy enough... 22 | */ 23 | #ifndef HAVE_UNISTD_H 24 | #ifdef __POSIX__ /* Defined by GCC on POSIX systems */ 25 | #define HAVE_UNISTD_H 1 26 | #elif defined(_POSIX_ARG_MAX) || defined(_POSIX_CHILD_MAX) 27 | #define HAVE_UNISTD_H 1 28 | #elif defined(_POSIX_LINK_MAX) || defined(_POSIX_MAX_CANON) 29 | #define HAVE_UNISTD_H 1 30 | #elif defined(_POSIX_MAX_INPUT) || defined(_POSIX_NAME_MAX) 31 | #define HAVE_UNISTD_H 1 32 | #elif defined(_POSIX_NGROUPS_MAX) || defined(_POSIX_OPEN_MAX) 33 | #define HAVE_UNISTD_H 1 34 | #elif defined(_POSIX_PATH_MAX) || defined(_POSIX_PIPE_BUF) 35 | #define HAVE_UNISTD_H 1 36 | #elif defined(_POSIX_RE_DUP_MAX) || defined(_POSIX_SSIZE_MAX) 37 | #define HAVE_UNISTD_H 1 38 | #elif defined(_POSIX_STREAM_MAX) || defined (_POSIX_TZNAME_MAX) 39 | #define HAVE_UNISTD_H 1 40 | #endif 41 | #endif 42 | 43 | #if HAVE_UNISTD_H 44 | #include 45 | #elif defined(MSDOS) 46 | #include /* Where MSDOS keeps such things */ 47 | #else 48 | /* Not POSIX - declare the portions of we need manually. */ 49 | int ioctl(int fd, int request, void *arg); 50 | int isatty(int fd); 51 | int read(int fd, void *buf, int nbytes); 52 | unsigned sleep(unsigned seconds); 53 | #endif 54 | -------------------------------------------------------------------------------- /third_party/bnlib/test/pt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994, 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * primetest.c - Test driver for prime generation. 6 | */ 7 | 8 | #include "first.h" 9 | #include 10 | #include /* For strtoul() */ 11 | 12 | #include "bn.h" 13 | #include "bnprint.h" 14 | #include "cputime.h" 15 | #include "prime.h" 16 | #include "noise.h" 17 | 18 | #include "kludge.h" 19 | 20 | #define bnPut(prompt, bn) bnPrint(stdout, prompt, bn, "\n") 21 | 22 | /* 23 | * Generate a new RSA key, with the specified number of bits and 24 | * public exponent. The high two bits of each prime are always 25 | * set to make the number more difficult to factor by forcing the 26 | * number into the high end of the range. 27 | */ 28 | 29 | struct Progress { 30 | FILE *f; 31 | unsigned column; 32 | unsigned wrap; 33 | }; 34 | 35 | static int 36 | primeProgress(void *arg, int c) 37 | { 38 | struct Progress *p = arg; 39 | if (++p->column > p->wrap) { 40 | putc('\n', p->f); 41 | p->column = 1; 42 | } 43 | putc(c, p->f); 44 | fflush(p->f); 45 | return 0; 46 | } 47 | 48 | static int 49 | hextoval(char c) 50 | { 51 | if (c < '0') 52 | return -1; 53 | c -= '0'; 54 | if (c < 10) 55 | return c; 56 | c -= 'A'-'0'; 57 | c &= ~('a'-'A'); 58 | if (c >= 0 && c < 6) 59 | return c+10; 60 | return -1; 61 | } 62 | 63 | static int 64 | stringToBn(struct BigNum *bn, char const *string) 65 | { 66 | size_t len = strlen(string); 67 | char buf; 68 | int i, j; 69 | 70 | (void)bnSetQ(bn, 0); 71 | 72 | if (len & 1) { 73 | i = hextoval(*string++); 74 | if (i < 0) 75 | return 0; 76 | buf = i; 77 | if (bnInsertBigBytes(bn, &buf, len/2, 1) < 0) 78 | return -1; 79 | } 80 | len /= 2; 81 | while (len--) { 82 | i = hextoval(*string++); 83 | if (i < 0) 84 | return 0; 85 | j = hextoval(*string++); 86 | if (j < 0) 87 | return 0; 88 | buf = i*16 + j; 89 | if (bnInsertBigBytes(bn, &buf, len, 1) < 0) 90 | return -1; 91 | } 92 | return 1; /* Success */ 93 | } 94 | 95 | static int 96 | primeTest(char const *string) 97 | { 98 | int modexps = 0; 99 | struct BigNum bn; /* Temporary */ 100 | int i, j; 101 | struct Progress progress; 102 | #if CLOCK_AVAIL 103 | timetype start, stop; 104 | unsigned long curs, tots = 0; 105 | unsigned curms, totms = 0; 106 | #endif 107 | progress.f = stdout; 108 | progress.wrap = 78; 109 | 110 | bnBegin(&bn); 111 | 112 | /* Find p - choose a starting place */ 113 | i = stringToBn(&bn, string); 114 | if (i < 1) { 115 | if (i < 0) 116 | goto error; 117 | printf("Malformed string: \"%s\"\n", string); 118 | bnEnd(&bn); 119 | return 0; 120 | } 121 | 122 | /* And search for primes */ 123 | for (j = 0; j < 40; j++) { 124 | progress.column = 0; 125 | #if CLOCK_AVAIL 126 | gettime(&start); 127 | #endif 128 | i = primeGen(&bn, 0, primeProgress, &progress, 0); 129 | if (i < 0) 130 | goto error; 131 | #if CLOCK_AVAIL 132 | gettime(&stop); 133 | subtime(stop, start); 134 | tots += curs = sec(stop); 135 | totms += curms = msec(stop); 136 | #endif 137 | modexps += i; 138 | putchar('\n'); /* Signal done */ 139 | printf("%d modular exponentiations performed", i); 140 | #if CLOCK_AVAIL 141 | printf(" in %lu.%03u s", curs, curms); 142 | #endif 143 | putchar('\n'); 144 | bnPut("n = ", &bn); 145 | if (bnAddQ(&bn, 2) < 0) 146 | goto error; 147 | } 148 | 149 | bnEnd(&bn); 150 | printf("Total %d modular exponentiations performed", modexps); 151 | #if CLOCK_AVAIL 152 | tots += totms/1000; 153 | totms %= 1000; 154 | printf(" in %lu.%03u s\n", tots, totms); 155 | totms += 1000 * (tots % j); 156 | tots /= j; 157 | totms /= j; 158 | tots += totms / 1000; 159 | totms %= 1000; 160 | printf("Average time: %lu.%03u s", tots, totms); 161 | #endif 162 | putchar('\n'); 163 | 164 | /* And that's it... success! */ 165 | return 1; 166 | error: 167 | puts("\nError!"); 168 | bnEnd(&bn); 169 | return -1; 170 | } 171 | 172 | int 173 | main(int argc, char **argv) 174 | { 175 | if (argc < 2) { 176 | fprintf(stderr, "Usage: %s ...\n", argv[0]); 177 | fputs("\ 178 | This finds the next primes after the given hex strings.\n", stderr); 179 | return 1; 180 | } 181 | 182 | bnInit(); 183 | 184 | while (--argc) 185 | primeTest(*++argv); 186 | 187 | return 0; 188 | } 189 | -------------------------------------------------------------------------------- /third_party/bnlib/test/random.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | #include "usuals.h" 6 | 7 | int randSourceSet(char const *string, unsigned len, int pri); 8 | 9 | void randBytes(byte *dest, unsigned len); 10 | unsigned randRange(unsigned range); 11 | 12 | unsigned randEvent(int event); 13 | void randFlush(void); 14 | 15 | void randAccum(unsigned count); 16 | -------------------------------------------------------------------------------- /third_party/bnlib/test/randpool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | #include "usuals.h" 6 | 7 | /* Set this to whatever you need (must be > 512) */ 8 | #define RANDPOOLBITS 3072 9 | 10 | void randPoolStir(void); 11 | void randPoolAddBytes(byte const *buf, unsigned len); 12 | void randPoolGetBytes(byte *buf, unsigned len); 13 | byte randPoolGetByte(void); 14 | -------------------------------------------------------------------------------- /third_party/bnlib/test/rsaglue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * rsaglue.h - RSA encryption and decryption 6 | */ 7 | #ifndef RSAGLUE_H 8 | #define RSAGLUE_H 9 | 10 | struct PubKey; 11 | struct SecKey; 12 | struct BigNum; 13 | #include "usuals.h" 14 | 15 | #define RSAGLUE_NOMEM -1 /* Ran out of memory */ 16 | #define RSAGLUE_TOOBIG -2 /* Key too big (currently impossible) */ 17 | #define RSAGLUE_TOOSMALL -3 /* Key too small (encryption only) */ 18 | #define RSAGLUE_CORRUPT -4 /* Decrypted data corrupt (decrypt only) */ 19 | #define RSAGLUE_UNRECOG -5 /* Unrecognized data (decrypt only) */ 20 | 21 | /* Declarations */ 22 | int rsaKeyTooBig(struct PubKey const *pub, struct SecKey const *sec); 23 | 24 | int 25 | rsaPublicEncrypt(struct BigNum *bn, byte const *in, unsigned len, 26 | struct PubKey const *pub); 27 | int 28 | rsaPrivateEncrypt(struct BigNum *bn, byte const *in, unsigned len, 29 | struct PubKey const *pub, struct SecKey const *sec); 30 | int 31 | rsaPublicDecrypt(byte *buf, unsigned len, struct BigNum *bn, 32 | struct PubKey const *pub); 33 | int 34 | rsaPrivateDecrypt(byte *buf, unsigned len, struct BigNum *bn, 35 | struct PubKey const *pub, struct SecKey const *sec); 36 | 37 | #endif /* !RSAGLUE_H */ 38 | -------------------------------------------------------------------------------- /third_party/bnlib/test/sha.h: -------------------------------------------------------------------------------- 1 | /* --------------------------------- SHA.H ------------------------------- */ 2 | 3 | /* 4 | * NIST Secure Hash Algorithm. 5 | * 6 | * Written 2 September 1992, Peter C. Gutmann. 7 | * This implementation placed in the public domain. 8 | * 9 | * Modified 1 June 1993, Colin Plumb. 10 | * Renamed to SHA and comments updated a bit 1 November 1995, Colin Plumb. 11 | * These modifications placed in the public domain. 12 | * 13 | * Comments to pgut1@cs.aukuni.ac.nz 14 | */ 15 | 16 | /* Typedefs for various word sizes */ 17 | #include "types.h" 18 | 19 | /* 20 | * Since 64-bit machines are the wave of the future, we may as well 21 | * support them directly. 22 | */ 23 | 24 | /* The SHA block size and message digest sizes, in bytes */ 25 | 26 | #define SHA_BLOCKSIZE 64 27 | #define SHA_DIGESTSIZE 20 28 | 29 | /* 30 | * The structure for storing SHA info. 31 | * data[] is placed first in case offsets of 0 are faster 32 | * for some reason; it's the most often accessed field. 33 | */ 34 | 35 | struct SHAContext { 36 | word32 data[ 16 ]; /* SHA data buffer */ 37 | word32 digest[ 5 ]; /* Message digest */ 38 | #ifdef HAVE64 39 | word64 count; 40 | #else 41 | word32 countHi, countLo; /* 64-bit byte count */ 42 | #endif 43 | }; 44 | 45 | /* Which standard? FIPS 180 or FIPS 180.1? */ 46 | 47 | #define SHA_VERSION 1 48 | 49 | /* Whether the machine is little-endian or not */ 50 | 51 | #if !defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN) 52 | #define BIG_ENDIAN 1 53 | #endif 54 | 55 | void shaInit(struct SHAContext *sha); 56 | void shaTransform(struct SHAContext *sha); 57 | void shaUpdate(struct SHAContext *sha, word8 const *buffer, unsigned count); 58 | void shaFinal(struct SHAContext *shaInfo, word8 *hash); 59 | -------------------------------------------------------------------------------- /third_party/bnlib/test/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | #ifndef TYPES_H 6 | #define TYPES_H 7 | 8 | #include 9 | 10 | #if UCHAR_MAX == 0xff 11 | typedef unsigned char word8; 12 | typedef signed char int8; 13 | #endif 14 | 15 | #if UINT_MAX == 0xffffu 16 | typedef unsigned word16; 17 | typedef int int16; 18 | #elif USHRT_MAX == 0xffffu 19 | typedef unsigned short word16; 20 | typedef short int16; 21 | #endif 22 | 23 | #if UINT_MAX == 0xffffffffu 24 | typedef unsigned word32; 25 | typedef int int32; 26 | #elif ULONG_MAX == 0xffffffffu 27 | typedef unsigned long word32; 28 | typedef long int32; 29 | #endif 30 | 31 | #if ULONG_MAX > 0xffffffffu 32 | typedef unsigned long word64; 33 | typedef long int64; 34 | #ifndef HAVE64 35 | #define HAVE64 1 36 | #endif 37 | #elif defined(ULONGLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULLONG_MAX) 38 | typedef unsigned long long word64; 39 | typedef long long int64; 40 | #ifndef HAVE64 41 | #define HAVE64 1 42 | #endif 43 | #endif 44 | 45 | #endif /* !TYPES_H */ 46 | -------------------------------------------------------------------------------- /third_party/bnlib/test/userio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | */ 5 | #include 6 | 7 | #define userPrintf printf 8 | #define userPuts(s) fputs(s, stdout) 9 | #define userFlush() fflush(stdout) 10 | #define userPutc putchar 11 | -------------------------------------------------------------------------------- /third_party/bnlib/test/usuals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995 Colin Plumb. All rights reserved. 3 | * For licensing and other legal details, see the file legal.c. 4 | * 5 | * usuals.h - Typedefs and #defines used widely. 6 | */ 7 | #ifndef USUALS_H 8 | #define USUALS_H 9 | 10 | #include 11 | 12 | #if UCHAR_MAX == 0xff 13 | typedef unsigned char byte; 14 | typedef signed char int8; 15 | #else 16 | #error This machine has no 8-bit type 17 | #endif 18 | 19 | #if UINT_MAX == 0xffffu 20 | typedef unsigned word16; 21 | typedef int int16; 22 | #elif USHRT_MAX == 0xffffu 23 | typedef unsigned short word16; 24 | typedef short int16; 25 | #else 26 | #error This machine has no 16-bit type 27 | #endif 28 | 29 | #if UINT_MAX == 0xffffffffu 30 | typedef unsigned int word32; 31 | typedef int int32; 32 | #elif ULONG_MAX == 0xffffffffu 33 | typedef unsigned long word32; 34 | typedef long int32; 35 | #else 36 | #error This machine has no 32-bit type 37 | #endif 38 | 39 | #include /* Prototype for memset */ 40 | /* 41 | * Wipe sensitive data. 42 | * Note that this takes a structure, not a pointer to one! 43 | */ 44 | #define wipe(x) memset(x, 0, sizeof(*(x))) 45 | 46 | #endif /* USUALS_H */ 47 | --------------------------------------------------------------------------------