Repo created
This commit is contained in:
parent
81b91f4139
commit
f8c34fa5ee
22732 changed files with 4815320 additions and 2 deletions
227
TMessagesProj/jni/third_party/libsrtp/CHANGES
vendored
Normal file
227
TMessagesProj/jni/third_party/libsrtp/CHANGES
vendored
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
Changelog
|
||||
|
||||
2.2.0-pre (This version)
|
||||
|
||||
Major changes
|
||||
|
||||
All code has been reformatted to be consistent. A .clang-format file and format.sh script has been added that can be use to verify and enforce consistent formatting. An automated check on code formatting is now part of travis build.
|
||||
|
||||
Other changes
|
||||
|
||||
PR #409 - Compatibilty with LibreSSL
|
||||
|
||||
PR #406 - Fix unprotect when pktlen < (2*mki_size + tag_len)
|
||||
|
||||
PR #405 - Prevent potential double free
|
||||
|
||||
PR #404 - Add back extern to global variables
|
||||
|
||||
PR #403 - Set gcm IV directly with EVP_CipherInit_ex
|
||||
|
||||
PR #401 - Fix memory access issue in srtp_get_session_keys()
|
||||
|
||||
PR #398 - Fix memory access fixes when invalid profiles where used
|
||||
|
||||
PR #391 - Return NULL when allocating memory of size zero
|
||||
|
||||
PR #390 - Bitvector of length zero is not valid
|
||||
|
||||
PR #385 - Treat warnings as errors on travis builds
|
||||
|
||||
PR #388 - Moved externs from crypto_kernel into its own header
|
||||
|
||||
PR #379 - Fixed several compiler warnings from Firefox builds
|
||||
|
||||
PR #377 - Removed variable init code in rdbx which never gets used
|
||||
|
||||
PR #381 - Added error in case the platform is not detected
|
||||
|
||||
PR #376 - Add coverity scan to travis builds
|
||||
|
||||
PR #374 - Add a big endian build on travis
|
||||
|
||||
PR #373 - Fixed buffer size issue in test/srtp_driver.c
|
||||
|
||||
PR #372 - Make rtp_decoder compile on MinGW
|
||||
|
||||
PR #367 - Rename configure.in to configure.ac
|
||||
|
||||
PR #365 - Replace calls to free() with srtp_crypto_free()
|
||||
|
||||
PR #364 - Add valgrind to travis and fix leaks in tests
|
||||
|
||||
PR #363 - Change smtp_crypto_alloc to initialize memory to zero
|
||||
|
||||
PR #354 - Fix potential leak if cloning of stream fails
|
||||
|
||||
PR #340 - Fix potential leak in srtp_add_stream()
|
||||
|
||||
PR #323 - Fix running test in out of source builds
|
||||
|
||||
Issue #316 - Remove VERSION file
|
||||
|
||||
2.1.0
|
||||
|
||||
Compatibility changes
|
||||
|
||||
PR #253 - Cipher type cleanup for AES
|
||||
When libSRTP is compiled with OpenSSL and the AES 256 ICM cipher is used
|
||||
with RTCP an incorrect initialization vector is formed.
|
||||
This change will break backwards compatibility with older versions (1.5,
|
||||
2.0) of libSRTP when using the AES 256 ICM cipher with OpenSSL for RTCP.
|
||||
|
||||
PR #259 - Sequence number incorrectly masked for AES GCM IV
|
||||
The initialization vector for AES GCM encryption was incorrectly formed on
|
||||
little endian machines.
|
||||
This change will break backwards compatibility with older versions (1.5,
|
||||
2.0) of libSRTP when using the AES GCM cipher for RTCP.
|
||||
|
||||
PR #287 - Fix OOB read in key generation for encrypted headers with GCM ciphers
|
||||
Adds padding of GCM salt to the corresponding ICM length used for header
|
||||
encryption.
|
||||
This change will break backwards compatibility with version 2.0 of libSRTP
|
||||
when using the header encryption extension with the AES GCM cipher.
|
||||
|
||||
Major changes
|
||||
|
||||
PR #204 - OpenSSL performance improvements
|
||||
Changed key expansion to occur once per key instead of once per packet.
|
||||
|
||||
PR #209 - Restore AES-192 under BoringSSL
|
||||
BoringSSL supports AES-192 and is now enabled in libSRTP.
|
||||
|
||||
PR #224 - Master Key Identifiers (MKI) Support patch
|
||||
Adds MKI support with up to 4 keys.
|
||||
|
||||
PR #234 - Report SSRC instead of srtp_stream_t in srtp_event_data_t
|
||||
srtp_stream_t is an opaque type making the event framework almost useless.
|
||||
Now the SSRC is returned instead for use as a key in the public API.
|
||||
|
||||
PR #238 - Configure changes and improvements
|
||||
CFLAGS check more shell neutral, quotation fixes, always generate and
|
||||
install pkg-config file, improved OpenSSL discovery and linking, remove
|
||||
-fPIC flag on Windows, fix shared library generation under Cygwin, replace
|
||||
hardcoded CFLAGS with compiler checks, and regenerate configure after
|
||||
configure.in changes.
|
||||
|
||||
PR #241 & PR #261 - Improved logging API to receive log messages from libSRTP
|
||||
Provides a logging API and the ability to enable logging to stdout and a
|
||||
file, as well as a switch to enable all internal debug modules.
|
||||
|
||||
PR #289 - Added support for set and get the roll-over-counter
|
||||
Adds an API to set and get the ROC in an (S)RTP session.
|
||||
|
||||
PR #304 - Fix (S)RTP and (S)RTCP for big endian machines
|
||||
The structures srtp_hdr_t, srtcp_hdr_t and srtcp_trailer_t were defined
|
||||
incorrectly on big endian systems.
|
||||
|
||||
Other changes
|
||||
|
||||
PR #149 - Don't create a symlink if there is no $(SHAREDLIBVERSION)
|
||||
|
||||
PR #151 - Make srtp_driver compile for MIPS
|
||||
|
||||
PR #160 - Use PKG_PROG_PKG_CONFIG to find correct pkg-config
|
||||
|
||||
PR #167 - Additional RTCP and SRTCP tests
|
||||
|
||||
PR #169 - Identified merge conflict created by commit 6b71fb9
|
||||
|
||||
PR #173 - Avoid error 'possibly undefined macro: AM_PROG_AR'
|
||||
|
||||
PR #174 - Avoid warning 'The macro AC_TRY_LINK is obsolete.'
|
||||
|
||||
PR #175 - Remove 2nd -fPIC
|
||||
|
||||
PR #182 - Add a length check before reading packet data
|
||||
|
||||
PR #191 - On debug, output correct endianness of SSRC
|
||||
|
||||
PR #192 - Replace octet_string_is_eq with a constant-time implementation
|
||||
|
||||
PR #195 - Add missing __cplusplus header guards
|
||||
|
||||
PR #198 - Update sha1_driver.c to avoid memory leaks
|
||||
|
||||
PR #202 - Add an explicit cast to avoid a printf format warning on macOS
|
||||
|
||||
PR #205 - Update Windows build files to Visual Studio 2015
|
||||
|
||||
PR #207 - Fix to install-win.bat syntax, and add installation of x64 libraries
|
||||
|
||||
PR #208 - Make replace_cipher and replace_auth public again
|
||||
|
||||
PR #211 - Changes for OpenSSL 1.1.0 compatibility
|
||||
|
||||
PR #213 - Add cast to `unsigned int` in call to printf in test
|
||||
|
||||
PR #214 - Avoid empty initializer braces
|
||||
|
||||
PR #222 - Fix issue: No consistency when use some srtp_* functions
|
||||
|
||||
PR #231 - Advance version on master in preparation for 2.1 release
|
||||
|
||||
PR #232 - Update Travis, do not build with OpenSSL on OSX
|
||||
|
||||
PR #233 - crypto/replay/rdbx.c: Return type of srtp_index_guess from int to
|
||||
int32_t
|
||||
|
||||
PR #236 - test/rtp_decoder.c: Removed superfluous conditional
|
||||
|
||||
PR #237 - test/rtp_decoder.c: spring cleaning
|
||||
|
||||
PR #239 - octet_string_set_to_zero() delegates to OPENSSL_cleanse() if
|
||||
available, if not it will use srtp_cleanse() to zero memory
|
||||
|
||||
PR #243 - EKT is not really supported yet, remove from install
|
||||
|
||||
PR #244 - Add simple error checking in timing test to avoid false results
|
||||
|
||||
PR #245 - Add missing srtp_cipher_dealloc calls when test fails
|
||||
|
||||
PR #246 - test/rtp_decoder: Add missing conditional
|
||||
|
||||
PR #248 - New README.md that integrates intro, credits and references from
|
||||
/doc/ and is used to generate documentation
|
||||
|
||||
PR #249 - Remove support for generic aesicm from configure.in
|
||||
|
||||
PR #250 - Update README.md, incorrect tag for link
|
||||
|
||||
PR #255 - Cleanup outdated comment related to MKI
|
||||
|
||||
PR #258 - Add AES-GCM to DTLS-SRTP Protection Profiles
|
||||
|
||||
PR #263 - Cleaning up and removing duplicated and outdated code
|
||||
|
||||
PR #265 - Introduction of unit test framework: CUTest
|
||||
|
||||
PR #267 - crypto/kernel/err.c: Include datatypes.h
|
||||
|
||||
PR #272 - Reduce literal constants
|
||||
|
||||
PR #273 - SRTP AEAD SRTCP initialization vector regression tests
|
||||
|
||||
PR #274 - Update Travis build - add ccache
|
||||
|
||||
PR #276 - Reference and docs updates
|
||||
|
||||
PR #278 - Removed crypto/test/auth_driver.c and test/lfsr.c
|
||||
|
||||
PR #279 - Bump copyright year
|
||||
|
||||
PR #283 - Add missing docs in srtp.h
|
||||
|
||||
PR #284 - Add strict-prototypes warning if supported
|
||||
|
||||
PR #291 - Use const char * for srtp_set_debug_module()
|
||||
|
||||
PR #294 - Fix incorrect result of rdb_increment on overflow
|
||||
|
||||
PR #300 - Standalone tests
|
||||
|
||||
PR #301 - Configure fixes
|
||||
|
||||
PR #302 - Fix warning regarding unused variable
|
||||
|
||||
PR #303 - Makefile.in: Add gnu as match for shared lib suffix
|
||||
1
TMessagesProj/jni/third_party/libsrtp/LIBSRTP_VERSION
vendored
Normal file
1
TMessagesProj/jni/third_party/libsrtp/LIBSRTP_VERSION
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
2.2.0-pre
|
||||
35
TMessagesProj/jni/third_party/libsrtp/LICENSE
vendored
Normal file
35
TMessagesProj/jni/third_party/libsrtp/LICENSE
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
2
TMessagesProj/jni/third_party/libsrtp/OWNERS
vendored
Normal file
2
TMessagesProj/jni/third_party/libsrtp/OWNERS
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
mattdr@chromium.org
|
||||
phoglund@chromium.org
|
||||
15
TMessagesProj/jni/third_party/libsrtp/README.chromium
vendored
Normal file
15
TMessagesProj/jni/third_party/libsrtp/README.chromium
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
Name: libsrtp
|
||||
URL: https://github.com/cisco/libsrtp
|
||||
Version: 94ac00d5ac6409e3f6409e4a5edfcdbdaa7fdabe
|
||||
License: 3-clause BSD
|
||||
License File: LICENSE
|
||||
Security Critical: Yes
|
||||
|
||||
Description:
|
||||
Libsrtp provides secure media transmission in a real
|
||||
time communication. It's used with libjingle which
|
||||
provides the p2p session setup.
|
||||
|
||||
Local Modifications:
|
||||
Removed many unused files, e.g. all non-OpenSSL cipher implementations.
|
||||
Renamed VERSION to LIBSRTP_VERSION.
|
||||
487
TMessagesProj/jni/third_party/libsrtp/README.md
vendored
Normal file
487
TMessagesProj/jni/third_party/libsrtp/README.md
vendored
Normal file
|
|
@ -0,0 +1,487 @@
|
|||
[](https://travis-ci.org/cisco/libsrtp)
|
||||
[](https://scan.coverity.com/projects/cisco-libsrtp)
|
||||
|
||||
<a name="introduction-to-libsrtp"></a>
|
||||
# Introduction to libSRTP
|
||||
|
||||
This package provides an implementation of the Secure Real-time
|
||||
Transport Protocol (SRTP), the Universal Security Transform (UST), and
|
||||
a supporting cryptographic kernel. The SRTP API is documented in include/srtp.h,
|
||||
and the library is in libsrtp2.a (after compilation).
|
||||
|
||||
This document describes libSRTP, the Open Source Secure RTP library
|
||||
from Cisco Systems, Inc. RTP is the Real-time Transport Protocol, an
|
||||
IETF standard for the transport of real-time data such as telephony,
|
||||
audio, and video, defined by [RFC 3550](https://www.ietf.org/rfc/rfc3550.txt).
|
||||
Secure RTP (SRTP) is an RTP profile for providing confidentiality to RTP data
|
||||
and authentication to the RTP header and payload. SRTP is an IETF Standard,
|
||||
defined in [RFC 3711](https://www.ietf.org/rfc/rfc3711.txt), and was developed
|
||||
in the IETF Audio/Video Transport (AVT) Working Group. This library supports
|
||||
all of the mandatory features of SRTP, but not all of the optional features. See
|
||||
the [Supported Features](#supported-features) section for more detailed information.
|
||||
|
||||
This document is also used to generate the documentation files in the /doc/
|
||||
folder where a more detailed reference to the libSRTP API and related functions
|
||||
can be created (requires installing doxygen.). The reference material is created
|
||||
automatically from comments embedded in some of the C header files. The
|
||||
documentation is organized into modules in order to improve its clarity. These
|
||||
modules do not directly correspond to files. An underlying cryptographic kernel
|
||||
provides much of the basic functionality of libSRTP but is mostly undocumented
|
||||
because it does its work behind the scenes.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="contact"></a>
|
||||
# Contact Us
|
||||
|
||||
- [libsrtp@lists.packetizer.com](mailto:libsrtp@lists.packetizer.com) general mailing list for news / announcements / discussions. This is an open list, see
|
||||
[https://lists.packetizer.com/mailman/listinfo/libsrtp](https://lists.packetizer.com/mailman/listinfo/libsrtp) for singing up.
|
||||
|
||||
- [libsrtp-security@lists.packetizer.com](mailto:libsrtp-security@lists.packetizer.com) for disclosing security issues to the libsrtp maintenance team. This is a closed list but anyone can send to it.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="contents"></a>
|
||||
## Contents
|
||||
|
||||
- [Introduction to libSRTP](#introduction-to-libsrtp)
|
||||
- [Contact Us](#contact)
|
||||
- [Contents](#contents)
|
||||
- [License and Disclaimer](#license-and-disclaimer)
|
||||
- [libSRTP Overview](#libsrtp-overview)
|
||||
- [Secure RTP Background](#secure-rtp-background)
|
||||
- [Supported Features](#supported-features)
|
||||
- [Implementation Notes](#implementation-notes)
|
||||
- [Installing and Building libSRTP](#installing-and-building-libsrtp)
|
||||
- [Changing Build Configuration](#changing-build-configuration)
|
||||
- [Applications](#applications)
|
||||
- [Example Code](#example-code)
|
||||
- [Credits](#credits)
|
||||
- [References](#references)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="license-and-disclaimer"></a>
|
||||
# License and Disclaimer
|
||||
|
||||
libSRTP is distributed under the following license, which is included
|
||||
in the source code distribution. It is reproduced in the manual in
|
||||
case you got the library from another source.
|
||||
|
||||
> Copyright (c) 2001-2017 Cisco Systems, Inc. All rights reserved.
|
||||
>
|
||||
> Redistribution and use in source and binary forms, with or without
|
||||
> modification, are permitted provided that the following conditions
|
||||
> are met:
|
||||
>
|
||||
> - Redistributions of source code must retain the above copyright
|
||||
> notice, this list of conditions and the following disclaimer.
|
||||
> - Redistributions in binary form must reproduce the above copyright
|
||||
> notice, this list of conditions and the following disclaimer in
|
||||
> the documentation and/or other materials provided with the distribution.
|
||||
> - Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
> contributors may be used to endorse or promote products derived
|
||||
> from this software without specific prior written permission.
|
||||
>
|
||||
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
> "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
> LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
> FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
> COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
> INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
> (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
> SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
> HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
> STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
> ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
> OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="libsrtp-overview"></a>
|
||||
# libSRTP Overview
|
||||
|
||||
libSRTP provides functions for protecting RTP and RTCP. RTP packets
|
||||
can be encrypted and authenticated (using the `srtp_protect()`
|
||||
function), turning them into SRTP packets. Similarly, SRTP packets
|
||||
can be decrypted and have their authentication verified (using the
|
||||
`srtp_unprotect()` function), turning them into RTP packets. Similar
|
||||
functions apply security to RTCP packets.
|
||||
|
||||
The typedef `srtp_stream_t` points to a structure holding all of the
|
||||
state associated with an SRTP stream, including the keys and
|
||||
parameters for cipher and message authentication functions and the
|
||||
anti-replay data. A particular `srtp_stream_t` holds the information
|
||||
needed to protect a particular RTP and RTCP stream. This datatype
|
||||
is intentionally opaque in order to better seperate the libSRTP
|
||||
API from its implementation.
|
||||
|
||||
Within an SRTP session, there can be multiple streams, each
|
||||
originating from a particular sender. Each source uses a distinct
|
||||
stream context to protect the RTP and RTCP stream that it is
|
||||
originating. The typedef `srtp_t` points to a structure holding all of
|
||||
the state associated with an SRTP session. There can be multiple
|
||||
stream contexts associated with a single `srtp_t`. A stream context
|
||||
cannot exist indepent from an `srtp_t`, though of course an `srtp_t` can
|
||||
be created that contains only a single stream context. A device
|
||||
participating in an SRTP session must have a stream context for each
|
||||
source in that session, so that it can process the data that it
|
||||
receives from each sender.
|
||||
|
||||
In libSRTP, a session is created using the function `srtp_create()`.
|
||||
The policy to be implemented in the session is passed into this
|
||||
function as an `srtp_policy_t` structure. A single one of these
|
||||
structures describes the policy of a single stream. These structures
|
||||
can also be linked together to form an entire session policy. A linked
|
||||
list of `srtp_policy_t` structures is equivalent to a session policy.
|
||||
In such a policy, we refer to a single `srtp_policy_t` as an *element*.
|
||||
|
||||
An `srtp_policy_t` strucutre contains two `crypto_policy_t` structures
|
||||
that describe the cryptograhic policies for RTP and RTCP, as well as
|
||||
the SRTP master key and the SSRC value. The SSRC describes what to
|
||||
protect (e.g. which stream), and the `crypto_policy_t` structures
|
||||
describe how to protect it. The key is contained in a policy element
|
||||
because it simplifies the interface to the library. In many cases, it
|
||||
is desirable to use the same cryptographic policies across all of the
|
||||
streams in a session, but to use a distinct key for each stream. A
|
||||
`crypto_policy_t` structure can be initialized by using either the
|
||||
`crypto_policy_set_rtp_default()` or `crypto_policy_set_rtcp_default()`
|
||||
functions, which set a crypto policy structure to the default policies
|
||||
for RTP and RTCP protection, respectively.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="secure-rtp-background"></a>
|
||||
## Secure RTP Background
|
||||
|
||||
In this section we review SRTP and introduce some terms that are used
|
||||
in libSRTP. An RTP session is defined by a pair of destination
|
||||
transport addresses, that is, a network address plus a pair of UDP
|
||||
ports for RTP and RTCP. RTCP, the RTP control protocol, is used to
|
||||
coordinate between the participants in an RTP session, e.g. to provide
|
||||
feedback from receivers to senders. An *SRTP session* is
|
||||
similarly defined; it is just an RTP session for which the SRTP
|
||||
profile is being used. An SRTP session consists of the traffic sent
|
||||
to the SRTP or SRTCP destination transport addresses. Each
|
||||
participant in a session is identified by a synchronization source
|
||||
(SSRC) identifier. Some participants may not send any SRTP traffic;
|
||||
they are called receivers, even though they send out SRTCP traffic,
|
||||
such as receiver reports.
|
||||
|
||||
RTP allows multiple sources to send RTP and RTCP traffic during the
|
||||
same session. The synchronization source identifier (SSRC) is used to
|
||||
distinguish these sources. In libSRTP, we call the SRTP and SRTCP
|
||||
traffic from a particular source a *stream*. Each stream has its own
|
||||
SSRC, sequence number, rollover counter, and other data. A particular
|
||||
choice of options, cryptographic mechanisms, and keys is called a
|
||||
*policy*. Each stream within a session can have a distinct policy
|
||||
applied to it. A session policy is a collection of stream policies.
|
||||
|
||||
A single policy can be used for all of the streams in a given session,
|
||||
though the case in which a single *key* is shared across multiple
|
||||
streams requires care. When key sharing is used, the SSRC values that
|
||||
identify the streams **must** be distinct. This requirement can be
|
||||
enforced by using the convention that each SRTP and SRTCP key is used
|
||||
for encryption by only a single sender. In other words, the key is
|
||||
shared only across streams that originate from a particular device (of
|
||||
course, other SRTP participants will need to use the key for
|
||||
decryption). libSRTP supports this enforcement by detecting the case
|
||||
in which a key is used for both inbound and outbound data.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="supported-features"></a>
|
||||
## Supported Features
|
||||
|
||||
This library supports all of the mandatory-to-implement features of
|
||||
SRTP (as defined in [RFC 3711](https://www.ietf.org/rfc/rfc3711.txt)). Some of these
|
||||
features can be selected (or de-selected) at run time by setting an
|
||||
appropriate policy; this is done using the structure `srtp_policy_t`.
|
||||
Some other behaviors of the protocol can be adapted by defining an
|
||||
approriate event handler for the exceptional events; see the SRTPevents
|
||||
section in the generated documentation.
|
||||
|
||||
Some options that are described in the SRTP specification are not
|
||||
supported. This includes
|
||||
|
||||
- key derivation rates other than zero,
|
||||
- the cipher F8,
|
||||
- the use of the packet index to select between master keys.
|
||||
|
||||
The user should be aware that it is possible to misuse this libary,
|
||||
and that the result may be that the security level it provides is
|
||||
inadequate. If you are implementing a feature using this library, you
|
||||
will want to read the Security Considerations section of [RFC 3711](https://www.ietf.org/rfc/rfc3711.txt).
|
||||
In addition, it is important that you read and understand the
|
||||
terms outlined in the [License and Disclaimer](#license-and-disclaimer) section.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="implementation-notes"></a>
|
||||
## Implementation Notes
|
||||
|
||||
* The `srtp_protect()` function assumes that the buffer holding the
|
||||
rtp packet has enough storage allocated that the authentication
|
||||
tag can be written to the end of that packet. If this assumption
|
||||
is not valid, memory corruption will ensue.
|
||||
|
||||
* Automated tests for the crypto functions are provided through
|
||||
the `cipher_type_self_test()` and `auth_type_self_test()` functions.
|
||||
These functions should be used to test each port of this code
|
||||
to a new platform.
|
||||
|
||||
* Replay protection is contained in the crypto engine, and
|
||||
tests for it are provided.
|
||||
|
||||
* This implementation provides calls to initialize, protect, and
|
||||
unprotect RTP packets, and makes as few as possible assumptions
|
||||
about how these functions will be called. For example, the
|
||||
caller is not expected to provide packets in order (though if
|
||||
they're called more than 65k out of sequence, synchronization
|
||||
will be lost).
|
||||
|
||||
* The sequence number in the rtp packet is used as the low 16 bits
|
||||
of the sender's local packet index. Note that RTP will start its
|
||||
sequence number in a random place, and the SRTP layer just jumps
|
||||
forward to that number at its first invocation. An earlier
|
||||
version of this library used initial sequence numbers that are
|
||||
less than 32,768; this trick is no longer required as the
|
||||
`rdbx_estimate_index(...)` function has been made smarter.
|
||||
|
||||
* The replay window for (S)RTCP is hardcoded to 128 bits in length.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="installing-and-building-libsrtp"></a>
|
||||
# Installing and Building libSRTP
|
||||
|
||||
To install libSRTP, download the latest release of the distribution
|
||||
from [https://github.com/cisco/libsrtp/releases](https://github.com/cisco/libsrtp/releases).
|
||||
You probably want to get the most recent release. Unpack the distribution and
|
||||
extract the source files; the directory into which the source files
|
||||
will go is named `libsrtp-A-B-C` where `A` is the version number, `B` is the
|
||||
major release number and `C` is the minor release number.
|
||||
|
||||
libSRTP uses the GNU `autoconf` and `make` utilities (BSD make will not work; if
|
||||
both versions of make are on your platform, you can invoke GNU make as
|
||||
`gmake`.). In the `libsrtp` directory, run the configure script and then
|
||||
make:
|
||||
|
||||
~~~.txt
|
||||
./configure [ options ]
|
||||
make
|
||||
~~~
|
||||
|
||||
The configure script accepts the following options:
|
||||
|
||||
Option | Description
|
||||
-------------------------------|--------------------
|
||||
\-\-help \-h | Display help
|
||||
\-\-enable-debug-logging | Enable debug logging in all modules
|
||||
\-\-enable-log-stdout | Enable logging to stdout
|
||||
\-\-enable-openssl | Enable OpenSSL crypto engine
|
||||
\-\-enable-openssl-kdf | Enable OpenSSL KDF algorithm
|
||||
\-\-with-log-file | Use file for logging
|
||||
\-\-with-openssl-dir | Location of OpenSSL installation
|
||||
|
||||
By default there is no log output, logging can be enabled to be output to stdout
|
||||
or a given file using the configure options.
|
||||
|
||||
This package has been tested on the following platforms: Mac OS X
|
||||
(powerpc-apple-darwin1.4), Cygwin (i686-pc-cygwin), Solaris
|
||||
(sparc-sun-solaris2.6), RedHat Linux 7.1 and 9 (i686-pc-linux), and
|
||||
OpenBSD (sparc-unknown-openbsd2.7).
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="changing-build-configuration"></a>
|
||||
## Changing Build Configuration
|
||||
|
||||
To build the `./configure` script mentioned above, libSRTP relies on the
|
||||
[automake](https://www.gnu.org/software/automake/) toolchain. Since
|
||||
`./configure` is built from `configure.in` by automake, if you make changes in
|
||||
how `./configure` works (e.g., to add a new library dependency), you will need
|
||||
to rebuild `./configure` and commit the updated version. In addition to
|
||||
automake itself, you will need to have the `pkgconfig` tools installed as well.
|
||||
|
||||
For example, on macOS:
|
||||
|
||||
```
|
||||
brew install automake pkgconfig
|
||||
# Edit configure.in
|
||||
autoremake -ivf
|
||||
```
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="applications"></a>
|
||||
# Applications
|
||||
|
||||
Several test drivers and a simple and portable srtp application are
|
||||
included in the `test/` subdirectory.
|
||||
|
||||
Test driver | Function tested
|
||||
--------- | -------
|
||||
kernel_driver | crypto kernel (ciphers, auth funcs, rng)
|
||||
srtp_driver | srtp in-memory tests (does not use the network)
|
||||
rdbx_driver | rdbx (extended replay database)
|
||||
roc_driver | extended sequence number functions
|
||||
replay_driver | replay database
|
||||
cipher_driver | ciphers
|
||||
auth_driver | hash functions
|
||||
|
||||
The app `rtpw` is a simple rtp application which reads words from
|
||||
`/usr/dict/words` and then sends them out one at a time using [s]rtp.
|
||||
Manual srtp keying uses the -k option; automated key management
|
||||
using gdoi will be added later.
|
||||
|
||||
usage:
|
||||
~~~.txt
|
||||
rtpw [[-d <debug>]* [-k|b <key> [-a][-e <key size>][-g]] [-s | -r] dest_ip dest_port] | [-l]
|
||||
~~~
|
||||
|
||||
Either the -s (sender) or -r (receiver) option must be chosen. The
|
||||
values `dest_ip`, `dest_port` are the IP address and UDP port to which
|
||||
the dictionary will be sent, respectively.
|
||||
|
||||
The options are:
|
||||
|
||||
Option | Description
|
||||
--------- | -------
|
||||
-s | (S)RTP sender - causes app to send words
|
||||
-r | (S)RTP receive - causes app to receive words
|
||||
-k <key> | use SRTP master key <key>, where the key is a hexadecimal (without the leading "0x")
|
||||
-b <key> | same as -k but with base64 encoded key
|
||||
-e <keysize> | encrypt/decrypt (for data confidentiality) (requires use of -k option as well) (use 128, 192, or 256 for keysize)
|
||||
-g | use AES-GCM mode (must be used with -e)
|
||||
-a | message authentication (requires use of -k option as well)
|
||||
-l | list the available debug modules
|
||||
-d <debug> | turn on debugging for module <debug>
|
||||
|
||||
In order to get random 30-byte values for use as key/salt pairs , you
|
||||
can use the following bash function to format the output of
|
||||
`/dev/random` (where that device is available).
|
||||
|
||||
~~~.txt
|
||||
function randhex() {
|
||||
cat /dev/random | od --read-bytes=32 --width=32 -x | awk '{ print $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16 }'
|
||||
}
|
||||
~~~
|
||||
|
||||
An example of an SRTP session using two rtpw programs follows:
|
||||
|
||||
~~~.txt
|
||||
set k=c1eec3717da76195bb878578790af71c4ee9f859e197a414a78d5abc7451
|
||||
|
||||
[sh1]$ test/rtpw -s -k $k -e 128 -a 0.0.0.0 9999
|
||||
Security services: confidentiality message authentication
|
||||
set master key/salt to C1EEC3717DA76195BB878578790AF71C/4EE9F859E197A414A78D5ABC7451
|
||||
setting SSRC to 2078917053
|
||||
sending word: A
|
||||
sending word: a
|
||||
sending word: aa
|
||||
sending word: aal
|
||||
...
|
||||
|
||||
[sh2]$ test/rtpw -r -k $k -e 128 -a 0.0.0.0 9999
|
||||
security services: confidentiality message authentication
|
||||
set master key/salt to C1EEC3717DA76195BB878578790AF71C/4EE9F859E197A414A78D5ABC7451
|
||||
19 octets received from SSRC 2078917053 word: A
|
||||
19 octets received from SSRC 2078917053 word: a
|
||||
20 octets received from SSRC 2078917053 word: aa
|
||||
21 octets received from SSRC 2078917053 word: aal
|
||||
...
|
||||
~~~
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="example-code"></a>
|
||||
## Example Code
|
||||
|
||||
This section provides a simple example of how to use libSRTP. The
|
||||
example code lacks error checking, but is functional. Here we assume
|
||||
that the value ssrc is already set to describe the SSRC of the stream
|
||||
that we are sending, and that the functions `get_rtp_packet()` and
|
||||
`send_srtp_packet()` are available to us. The former puts an RTP packet
|
||||
into the buffer and returns the number of octets written to that
|
||||
buffer. The latter sends the RTP packet in the buffer, given the
|
||||
length as its second argument.
|
||||
|
||||
~~~.c
|
||||
srtp_t session;
|
||||
srtp_policy_t policy;
|
||||
|
||||
// Set key to predetermined value
|
||||
uint8_t key[30] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D};
|
||||
|
||||
// initialize libSRTP
|
||||
srtp_init();
|
||||
|
||||
// default policy values
|
||||
memset(&policy, 0x0, sizeof(srtp_policy_t));
|
||||
|
||||
// set policy to describe a policy for an SRTP stream
|
||||
crypto_policy_set_rtp_default(&policy.rtp);
|
||||
crypto_policy_set_rtcp_default(&policy.rtcp);
|
||||
policy.ssrc = ssrc;
|
||||
policy.key = key;
|
||||
policy.next = NULL;
|
||||
|
||||
// allocate and initialize the SRTP session
|
||||
srtp_create(&session, &policy);
|
||||
|
||||
// main loop: get rtp packets, send srtp packets
|
||||
while (1) {
|
||||
char rtp_buffer[2048];
|
||||
unsigned len;
|
||||
|
||||
len = get_rtp_packet(rtp_buffer);
|
||||
srtp_protect(session, rtp_buffer, &len);
|
||||
send_srtp_packet(rtp_buffer, len);
|
||||
}
|
||||
~~~
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="credits"></a>
|
||||
# Credits
|
||||
|
||||
The original implementation and documentation of libSRTP was written
|
||||
by David McGrew of Cisco Systems, Inc. in order to promote the use,
|
||||
understanding, and interoperability of Secure RTP. Michael Jerris
|
||||
contributed support for building under MSVC. Andris Pavenis
|
||||
contributed many important fixes. Brian West contributed changes to
|
||||
enable dynamic linking. Yves Shumann reported documentation bugs.
|
||||
Randell Jesup contributed a working SRTCP implementation and other
|
||||
fixes. Steve Underwood contributed x86_64 portability changes. We also give
|
||||
thanks to Fredrik Thulin, Brian Weis, Mark Baugher, Jeff Chan, Bill
|
||||
Simon, Douglas Smith, Bill May, Richard Preistley, Joe Tardo and
|
||||
others for contributions, comments, and corrections.
|
||||
|
||||
This reference material, when applicable, in this documenation was generated
|
||||
using the doxygen utility for automatic documentation of source code.
|
||||
|
||||
Copyright 2001-2005 by David A. McGrew, Cisco Systems, Inc.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
<a name="references"></a>
|
||||
# References
|
||||
|
||||
SRTP and ICM References
|
||||
September, 2005
|
||||
|
||||
Secure RTP is defined in [RFC 3711](https://www.ietf.org/rfc/rfc3711.txt).
|
||||
The counter mode definition is in Section 4.1.1.
|
||||
|
||||
SHA-1 is defined in [FIPS PUB 180-4](http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
||||
|
||||
HMAC is defined in [RFC 2104](https://www.ietf.org/rfc/rfc2104.txt)
|
||||
and HMAC-SHA1 test vectors are available
|
||||
in [RFC 2202](https://www.ietf.org/rfc/rfc2202.txt).
|
||||
|
||||
AES-GCM usage in SRTP is defined in [RFC 7714](https://www.ietf.org/html/rfc7714)
|
||||
578
TMessagesProj/jni/third_party/libsrtp/crypto/cipher/aes_gcm_ossl.c
vendored
Normal file
578
TMessagesProj/jni/third_party/libsrtp/crypto/cipher/aes_gcm_ossl.c
vendored
Normal file
|
|
@ -0,0 +1,578 @@
|
|||
/*
|
||||
* aes_gcm_ossl.c
|
||||
*
|
||||
* AES Galois Counter Mode
|
||||
*
|
||||
* John A. Foley
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include "aes_icm_ossl.h"
|
||||
#include "aes_gcm_ossl.h"
|
||||
#include "alloc.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "crypto_types.h"
|
||||
#include "cipher_types.h"
|
||||
|
||||
srtp_debug_module_t srtp_mod_aes_gcm = {
|
||||
0, /* debugging is off by default */
|
||||
"aes gcm" /* printable module name */
|
||||
};
|
||||
|
||||
/*
|
||||
* For now we only support 8 and 16 octet tags. The spec allows for
|
||||
* optional 12 byte tag, which may be supported in the future.
|
||||
*/
|
||||
#define GCM_AUTH_TAG_LEN 16
|
||||
#define GCM_AUTH_TAG_LEN_8 8
|
||||
|
||||
/*
|
||||
* This function allocates a new instance of this crypto engine.
|
||||
* The key_len parameter should be one of 28 or 44 for
|
||||
* AES-128-GCM or AES-256-GCM respectively. Note that the
|
||||
* key length includes the 14 byte salt value that is used when
|
||||
* initializing the KDF.
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_alloc(srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *gcm;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "allocating cipher with key length %d",
|
||||
key_len);
|
||||
debug_print(srtp_mod_aes_gcm, "allocating cipher with tag length %d", tlen);
|
||||
|
||||
/*
|
||||
* Verify the key_len is valid for one of: AES-128/256
|
||||
*/
|
||||
if (key_len != SRTP_AES_GCM_128_KEY_LEN_WSALT &&
|
||||
key_len != SRTP_AES_GCM_256_KEY_LEN_WSALT) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
if (tlen != GCM_AUTH_TAG_LEN && tlen != GCM_AUTH_TAG_LEN_8) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
/* allocate memory a cipher of type aes_gcm */
|
||||
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
|
||||
if (*c == NULL) {
|
||||
return (srtp_err_status_alloc_fail);
|
||||
}
|
||||
|
||||
gcm = (srtp_aes_gcm_ctx_t *)srtp_crypto_alloc(sizeof(srtp_aes_gcm_ctx_t));
|
||||
if (gcm == NULL) {
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return (srtp_err_status_alloc_fail);
|
||||
}
|
||||
|
||||
gcm->ctx = EVP_CIPHER_CTX_new();
|
||||
if (gcm->ctx == NULL) {
|
||||
srtp_crypto_free(gcm);
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* set pointers */
|
||||
(*c)->state = gcm;
|
||||
|
||||
/* setup cipher attributes */
|
||||
switch (key_len) {
|
||||
case SRTP_AES_GCM_128_KEY_LEN_WSALT:
|
||||
(*c)->type = &srtp_aes_gcm_128_openssl;
|
||||
(*c)->algorithm = SRTP_AES_GCM_128;
|
||||
gcm->key_size = SRTP_AES_128_KEY_LEN;
|
||||
gcm->tag_len = tlen;
|
||||
break;
|
||||
case SRTP_AES_GCM_256_KEY_LEN_WSALT:
|
||||
(*c)->type = &srtp_aes_gcm_256_openssl;
|
||||
(*c)->algorithm = SRTP_AES_GCM_256;
|
||||
gcm->key_size = SRTP_AES_256_KEY_LEN;
|
||||
gcm->tag_len = tlen;
|
||||
break;
|
||||
}
|
||||
|
||||
/* set key size */
|
||||
(*c)->key_len = key_len;
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function deallocates a GCM session
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_dealloc(srtp_cipher_t *c)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *ctx;
|
||||
|
||||
ctx = (srtp_aes_gcm_ctx_t *)c->state;
|
||||
if (ctx) {
|
||||
EVP_CIPHER_CTX_free(ctx->ctx);
|
||||
/* zeroize the key material */
|
||||
octet_string_set_to_zero(ctx, sizeof(srtp_aes_gcm_ctx_t));
|
||||
srtp_crypto_free(ctx);
|
||||
}
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(c);
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_gcm_openssl_context_init(...) initializes the aes_gcm_context
|
||||
* using the value in key[].
|
||||
*
|
||||
* the key is the secret key
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_context_init(void *cv,
|
||||
const uint8_t *key)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
const EVP_CIPHER *evp;
|
||||
|
||||
c->dir = srtp_direction_any;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "key: %s",
|
||||
srtp_octet_string_hex_string(key, c->key_size));
|
||||
|
||||
switch (c->key_size) {
|
||||
case SRTP_AES_256_KEY_LEN:
|
||||
evp = EVP_aes_256_gcm();
|
||||
break;
|
||||
case SRTP_AES_128_KEY_LEN:
|
||||
evp = EVP_aes_128_gcm();
|
||||
break;
|
||||
default:
|
||||
return (srtp_err_status_bad_param);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!EVP_CipherInit_ex(c->ctx, evp, NULL, key, NULL, 0)) {
|
||||
return (srtp_err_status_init_fail);
|
||||
}
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_gcm_openssl_set_iv(c, iv) sets the counter value to the exor of iv with
|
||||
* the offset
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_set_iv(
|
||||
void *cv,
|
||||
uint8_t *iv,
|
||||
srtp_cipher_direction_t direction)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
|
||||
if (direction != srtp_direction_encrypt &&
|
||||
direction != srtp_direction_decrypt) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
c->dir = direction;
|
||||
|
||||
debug_print(srtp_mod_aes_gcm, "setting iv: %s",
|
||||
v128_hex_string((v128_t *)iv));
|
||||
|
||||
if (!EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_SET_IVLEN, 12, 0)) {
|
||||
return (srtp_err_status_init_fail);
|
||||
}
|
||||
|
||||
if (!EVP_CipherInit_ex(c->ctx, NULL, NULL, NULL, iv,
|
||||
(c->dir == srtp_direction_encrypt ? 1 : 0))) {
|
||||
return (srtp_err_status_init_fail);
|
||||
}
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function processes the AAD
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* aad Additional data to process for AEAD cipher suites
|
||||
* aad_len length of aad buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_set_aad(void *cv,
|
||||
const uint8_t *aad,
|
||||
uint32_t aad_len)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
int rv;
|
||||
|
||||
/*
|
||||
* Set dummy tag, OpenSSL requires the Tag to be set before
|
||||
* processing AAD
|
||||
*/
|
||||
|
||||
/*
|
||||
* OpenSSL never write to address pointed by the last parameter of
|
||||
* EVP_CIPHER_CTX_ctrl while EVP_CTRL_GCM_SET_TAG (in reality,
|
||||
* OpenSSL copy its content to the context), so we can make
|
||||
* aad read-only in this function and all its wrappers.
|
||||
*/
|
||||
unsigned char dummy_tag[GCM_AUTH_TAG_LEN];
|
||||
memset(dummy_tag, 0x0, GCM_AUTH_TAG_LEN);
|
||||
EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_SET_TAG, c->tag_len, &dummy_tag);
|
||||
|
||||
rv = EVP_Cipher(c->ctx, NULL, aad, aad_len);
|
||||
if (rv != aad_len) {
|
||||
return (srtp_err_status_algo_fail);
|
||||
} else {
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function encrypts a buffer using AES GCM mode
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* enc_len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_encrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
if (c->dir != srtp_direction_encrypt && c->dir != srtp_direction_decrypt) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
/*
|
||||
* Encrypt the data
|
||||
*/
|
||||
EVP_Cipher(c->ctx, buf, buf, *enc_len);
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function calculates and returns the GCM tag for a given context.
|
||||
* This should be called after encrypting the data. The *len value
|
||||
* is increased by the tag size. The caller must ensure that *buf has
|
||||
* enough room to accept the appended tag.
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_get_tag(void *cv,
|
||||
uint8_t *buf,
|
||||
uint32_t *len)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
/*
|
||||
* Calculate the tag
|
||||
*/
|
||||
EVP_Cipher(c->ctx, NULL, NULL, 0);
|
||||
|
||||
/*
|
||||
* Retreive the tag
|
||||
*/
|
||||
EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_GET_TAG, c->tag_len, buf);
|
||||
|
||||
/*
|
||||
* Increase encryption length by desired tag size
|
||||
*/
|
||||
*len = c->tag_len;
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function decrypts a buffer using AES GCM mode
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* enc_len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_gcm_openssl_decrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
srtp_aes_gcm_ctx_t *c = (srtp_aes_gcm_ctx_t *)cv;
|
||||
if (c->dir != srtp_direction_encrypt && c->dir != srtp_direction_decrypt) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the tag before decrypting
|
||||
*/
|
||||
EVP_CIPHER_CTX_ctrl(c->ctx, EVP_CTRL_GCM_SET_TAG, c->tag_len,
|
||||
buf + (*enc_len - c->tag_len));
|
||||
EVP_Cipher(c->ctx, buf, buf, *enc_len - c->tag_len);
|
||||
|
||||
/*
|
||||
* Check the tag
|
||||
*/
|
||||
if (EVP_Cipher(c->ctx, NULL, NULL, 0)) {
|
||||
return (srtp_err_status_auth_fail);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reduce the buffer size by the tag length since the tag
|
||||
* is not part of the original payload
|
||||
*/
|
||||
*enc_len -= c->tag_len;
|
||||
|
||||
return (srtp_err_status_ok);
|
||||
}
|
||||
|
||||
/*
|
||||
* Name of this crypto engine
|
||||
*/
|
||||
static const char srtp_aes_gcm_128_openssl_description[] =
|
||||
"AES-128 GCM using openssl";
|
||||
static const char srtp_aes_gcm_256_openssl_description[] =
|
||||
"AES-256 GCM using openssl";
|
||||
|
||||
/*
|
||||
* KAT values for AES self-test. These
|
||||
* values we're derived from independent test code
|
||||
* using OpenSSL.
|
||||
*/
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_test_case_0_key[SRTP_AES_GCM_128_KEY_LEN_WSALT] = {
|
||||
0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
|
||||
0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0a, 0x0b, 0x0c,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static uint8_t srtp_aes_gcm_test_case_0_iv[12] = {
|
||||
0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
|
||||
0xde, 0xca, 0xf8, 0x88
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_test_case_0_plaintext[60] = {
|
||||
0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
|
||||
0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
|
||||
0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
|
||||
0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
|
||||
0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
|
||||
0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
|
||||
0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
|
||||
0xba, 0x63, 0x7b, 0x39
|
||||
};
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_test_case_0_aad[20] = {
|
||||
0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
|
||||
0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
|
||||
0xab, 0xad, 0xda, 0xd2
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_test_case_0_ciphertext[76] = {
|
||||
0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
|
||||
0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
|
||||
0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
|
||||
0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
|
||||
0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
|
||||
0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
|
||||
0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
|
||||
0x3d, 0x58, 0xe0, 0x91,
|
||||
/* the last 16 bytes are the tag */
|
||||
0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb,
|
||||
0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_0a = {
|
||||
SRTP_AES_GCM_128_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_gcm_test_case_0_key, /* key */
|
||||
srtp_aes_gcm_test_case_0_iv, /* packet index */
|
||||
60, /* octets in plaintext */
|
||||
srtp_aes_gcm_test_case_0_plaintext, /* plaintext */
|
||||
68, /* octets in ciphertext */
|
||||
srtp_aes_gcm_test_case_0_ciphertext, /* ciphertext + tag */
|
||||
20, /* octets in AAD */
|
||||
srtp_aes_gcm_test_case_0_aad, /* AAD */
|
||||
GCM_AUTH_TAG_LEN_8, /* */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_0 = {
|
||||
SRTP_AES_GCM_128_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_gcm_test_case_0_key, /* key */
|
||||
srtp_aes_gcm_test_case_0_iv, /* packet index */
|
||||
60, /* octets in plaintext */
|
||||
srtp_aes_gcm_test_case_0_plaintext, /* plaintext */
|
||||
76, /* octets in ciphertext */
|
||||
srtp_aes_gcm_test_case_0_ciphertext, /* ciphertext + tag */
|
||||
20, /* octets in AAD */
|
||||
srtp_aes_gcm_test_case_0_aad, /* AAD */
|
||||
GCM_AUTH_TAG_LEN, /* */
|
||||
&srtp_aes_gcm_test_case_0a /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_test_case_1_key[SRTP_AES_GCM_256_KEY_LEN_WSALT] = {
|
||||
0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
|
||||
0xa5, 0x59, 0x09, 0xc5, 0x54, 0x66, 0x93, 0x1c,
|
||||
0xaf, 0xf5, 0x26, 0x9a, 0x21, 0xd5, 0x14, 0xb2,
|
||||
0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0a, 0x0b, 0x0c,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static uint8_t srtp_aes_gcm_test_case_1_iv[12] = {
|
||||
0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
|
||||
0xde, 0xca, 0xf8, 0x88
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_test_case_1_plaintext[60] = {
|
||||
0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
|
||||
0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
|
||||
0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
|
||||
0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
|
||||
0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
|
||||
0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
|
||||
0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
|
||||
0xba, 0x63, 0x7b, 0x39
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_test_case_1_aad[20] = {
|
||||
0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
|
||||
0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
|
||||
0xab, 0xad, 0xda, 0xd2
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_gcm_test_case_1_ciphertext[76] = {
|
||||
0x0b, 0x11, 0xcf, 0xaf, 0x68, 0x4d, 0xae, 0x46,
|
||||
0xc7, 0x90, 0xb8, 0x8e, 0xb7, 0x6a, 0x76, 0x2a,
|
||||
0x94, 0x82, 0xca, 0xab, 0x3e, 0x39, 0xd7, 0x86,
|
||||
0x1b, 0xc7, 0x93, 0xed, 0x75, 0x7f, 0x23, 0x5a,
|
||||
0xda, 0xfd, 0xd3, 0xe2, 0x0e, 0x80, 0x87, 0xa9,
|
||||
0x6d, 0xd7, 0xe2, 0x6a, 0x7d, 0x5f, 0xb4, 0x80,
|
||||
0xef, 0xef, 0xc5, 0x29, 0x12, 0xd1, 0xaa, 0x10,
|
||||
0x09, 0xc9, 0x86, 0xc1,
|
||||
/* the last 16 bytes are the tag */
|
||||
0x45, 0xbc, 0x03, 0xe6, 0xe1, 0xac, 0x0a, 0x9f,
|
||||
0x81, 0xcb, 0x8e, 0x5b, 0x46, 0x65, 0x63, 0x1d,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_1a = {
|
||||
SRTP_AES_GCM_256_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_gcm_test_case_1_key, /* key */
|
||||
srtp_aes_gcm_test_case_1_iv, /* packet index */
|
||||
60, /* octets in plaintext */
|
||||
srtp_aes_gcm_test_case_1_plaintext, /* plaintext */
|
||||
68, /* octets in ciphertext */
|
||||
srtp_aes_gcm_test_case_1_ciphertext, /* ciphertext + tag */
|
||||
20, /* octets in AAD */
|
||||
srtp_aes_gcm_test_case_1_aad, /* AAD */
|
||||
GCM_AUTH_TAG_LEN_8, /* */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
static const srtp_cipher_test_case_t srtp_aes_gcm_test_case_1 = {
|
||||
SRTP_AES_GCM_256_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_gcm_test_case_1_key, /* key */
|
||||
srtp_aes_gcm_test_case_1_iv, /* packet index */
|
||||
60, /* octets in plaintext */
|
||||
srtp_aes_gcm_test_case_1_plaintext, /* plaintext */
|
||||
76, /* octets in ciphertext */
|
||||
srtp_aes_gcm_test_case_1_ciphertext, /* ciphertext + tag */
|
||||
20, /* octets in AAD */
|
||||
srtp_aes_gcm_test_case_1_aad, /* AAD */
|
||||
GCM_AUTH_TAG_LEN, /* */
|
||||
&srtp_aes_gcm_test_case_1a /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the vector function table for this crypto engine.
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_gcm_128_openssl = {
|
||||
srtp_aes_gcm_openssl_alloc,
|
||||
srtp_aes_gcm_openssl_dealloc,
|
||||
srtp_aes_gcm_openssl_context_init,
|
||||
srtp_aes_gcm_openssl_set_aad,
|
||||
srtp_aes_gcm_openssl_encrypt,
|
||||
srtp_aes_gcm_openssl_decrypt,
|
||||
srtp_aes_gcm_openssl_set_iv,
|
||||
srtp_aes_gcm_openssl_get_tag,
|
||||
srtp_aes_gcm_128_openssl_description,
|
||||
&srtp_aes_gcm_test_case_0,
|
||||
SRTP_AES_GCM_128
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the vector function table for this crypto engine.
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_gcm_256_openssl = {
|
||||
srtp_aes_gcm_openssl_alloc,
|
||||
srtp_aes_gcm_openssl_dealloc,
|
||||
srtp_aes_gcm_openssl_context_init,
|
||||
srtp_aes_gcm_openssl_set_aad,
|
||||
srtp_aes_gcm_openssl_encrypt,
|
||||
srtp_aes_gcm_openssl_decrypt,
|
||||
srtp_aes_gcm_openssl_set_iv,
|
||||
srtp_aes_gcm_openssl_get_tag,
|
||||
srtp_aes_gcm_256_openssl_description,
|
||||
&srtp_aes_gcm_test_case_1,
|
||||
SRTP_AES_GCM_256
|
||||
};
|
||||
538
TMessagesProj/jni/third_party/libsrtp/crypto/cipher/aes_icm_ossl.c
vendored
Normal file
538
TMessagesProj/jni/third_party/libsrtp/crypto/cipher/aes_icm_ossl.c
vendored
Normal file
|
|
@ -0,0 +1,538 @@
|
|||
/*
|
||||
* aes_icm_ossl.c
|
||||
*
|
||||
* AES Integer Counter Mode
|
||||
*
|
||||
* John A. Foley
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
* 2/24/2012: This module was modified to use CiscoSSL for AES counter
|
||||
* mode. Eddy Lem contributed the code to allow this.
|
||||
*
|
||||
* 12/20/2012: Added support for AES-192 and AES-256.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include "aes_icm_ossl.h"
|
||||
#include "crypto_types.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "alloc.h"
|
||||
#include "cipher_types.h"
|
||||
|
||||
srtp_debug_module_t srtp_mod_aes_icm = {
|
||||
0, /* debugging is off by default */
|
||||
"aes icm ossl" /* printable module name */
|
||||
};
|
||||
|
||||
/*
|
||||
* integer counter mode works as follows:
|
||||
*
|
||||
* 16 bits
|
||||
* <----->
|
||||
* +------+------+------+------+------+------+------+------+
|
||||
* | nonce | packet index | ctr |---+
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* |
|
||||
* +------+------+------+------+------+------+------+------+ v
|
||||
* | salt |000000|->(+)
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* |
|
||||
* +---------+
|
||||
* | encrypt |
|
||||
* +---------+
|
||||
* |
|
||||
* +------+------+------+------+------+------+------+------+ |
|
||||
* | keystream block |<--+
|
||||
* +------+------+------+------+------+------+------+------+
|
||||
*
|
||||
* All fields are big-endian
|
||||
*
|
||||
* ctr is the block counter, which increments from zero for
|
||||
* each packet (16 bits wide)
|
||||
*
|
||||
* packet index is distinct for each packet (48 bits wide)
|
||||
*
|
||||
* nonce can be distinct across many uses of the same key, or
|
||||
* can be a fixed value per key, or can be per-packet randomness
|
||||
* (64 bits)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This function allocates a new instance of this crypto engine.
|
||||
* The key_len parameter should be one of 30, 38, or 46 for
|
||||
* AES-128, AES-192, and AES-256 respectively. Note, this key_len
|
||||
* value is inflated, as it also accounts for the 112 bit salt
|
||||
* value. The tlen argument is for the AEAD tag length, which
|
||||
* isn't used in counter mode.
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_openssl_alloc(srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *icm;
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "allocating cipher with key length %d",
|
||||
key_len);
|
||||
|
||||
/*
|
||||
* Verify the key_len is valid for one of: AES-128/192/256
|
||||
*/
|
||||
if (key_len != SRTP_AES_ICM_128_KEY_LEN_WSALT &&
|
||||
key_len != SRTP_AES_ICM_192_KEY_LEN_WSALT &&
|
||||
key_len != SRTP_AES_ICM_256_KEY_LEN_WSALT) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* allocate memory a cipher of type aes_icm */
|
||||
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
|
||||
if (*c == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
icm = (srtp_aes_icm_ctx_t *)srtp_crypto_alloc(sizeof(srtp_aes_icm_ctx_t));
|
||||
if (icm == NULL) {
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
icm->ctx = EVP_CIPHER_CTX_new();
|
||||
if (icm->ctx == NULL) {
|
||||
srtp_crypto_free(icm);
|
||||
srtp_crypto_free(*c);
|
||||
*c = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* set pointers */
|
||||
(*c)->state = icm;
|
||||
|
||||
/* setup cipher parameters */
|
||||
switch (key_len) {
|
||||
case SRTP_AES_ICM_128_KEY_LEN_WSALT:
|
||||
(*c)->algorithm = SRTP_AES_ICM_128;
|
||||
(*c)->type = &srtp_aes_icm_128;
|
||||
icm->key_size = SRTP_AES_128_KEY_LEN;
|
||||
break;
|
||||
case SRTP_AES_ICM_192_KEY_LEN_WSALT:
|
||||
(*c)->algorithm = SRTP_AES_ICM_192;
|
||||
(*c)->type = &srtp_aes_icm_192;
|
||||
icm->key_size = SRTP_AES_192_KEY_LEN;
|
||||
break;
|
||||
case SRTP_AES_ICM_256_KEY_LEN_WSALT:
|
||||
(*c)->algorithm = SRTP_AES_ICM_256;
|
||||
(*c)->type = &srtp_aes_icm_256;
|
||||
icm->key_size = SRTP_AES_256_KEY_LEN;
|
||||
break;
|
||||
}
|
||||
|
||||
/* set key size */
|
||||
(*c)->key_len = key_len;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function deallocates an instance of this engine
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_openssl_dealloc(srtp_cipher_t *c)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *ctx;
|
||||
|
||||
if (c == NULL) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the EVP context
|
||||
*/
|
||||
ctx = (srtp_aes_icm_ctx_t *)c->state;
|
||||
if (ctx != NULL) {
|
||||
EVP_CIPHER_CTX_free(ctx->ctx);
|
||||
/* zeroize the key material */
|
||||
octet_string_set_to_zero(ctx, sizeof(srtp_aes_icm_ctx_t));
|
||||
srtp_crypto_free(ctx);
|
||||
}
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(c);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_icm_openssl_context_init(...) initializes the aes_icm_context
|
||||
* using the value in key[].
|
||||
*
|
||||
* the key is the secret key
|
||||
*
|
||||
* the salt is unpredictable (but not necessarily secret) data which
|
||||
* randomizes the starting point in the keystream
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_openssl_context_init(void *cv,
|
||||
const uint8_t *key)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
const EVP_CIPHER *evp;
|
||||
|
||||
/*
|
||||
* set counter and initial values to 'offset' value, being careful not to
|
||||
* go past the end of the key buffer
|
||||
*/
|
||||
v128_set_to_zero(&c->counter);
|
||||
v128_set_to_zero(&c->offset);
|
||||
memcpy(&c->counter, key + c->key_size, SRTP_SALT_LEN);
|
||||
memcpy(&c->offset, key + c->key_size, SRTP_SALT_LEN);
|
||||
|
||||
/* force last two octets of the offset to zero (for srtp compatibility) */
|
||||
c->offset.v8[SRTP_SALT_LEN] = c->offset.v8[SRTP_SALT_LEN + 1] = 0;
|
||||
c->counter.v8[SRTP_SALT_LEN] = c->counter.v8[SRTP_SALT_LEN + 1] = 0;
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "key: %s",
|
||||
srtp_octet_string_hex_string(key, c->key_size));
|
||||
debug_print(srtp_mod_aes_icm, "offset: %s", v128_hex_string(&c->offset));
|
||||
|
||||
switch (c->key_size) {
|
||||
case SRTP_AES_256_KEY_LEN:
|
||||
evp = EVP_aes_256_ctr();
|
||||
break;
|
||||
case SRTP_AES_192_KEY_LEN:
|
||||
evp = EVP_aes_192_ctr();
|
||||
break;
|
||||
case SRTP_AES_128_KEY_LEN:
|
||||
evp = EVP_aes_128_ctr();
|
||||
break;
|
||||
default:
|
||||
return srtp_err_status_bad_param;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!EVP_EncryptInit_ex(c->ctx, evp, NULL, key, NULL)) {
|
||||
return srtp_err_status_fail;
|
||||
} else {
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* aes_icm_set_iv(c, iv) sets the counter value to the exor of iv with
|
||||
* the offset
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_openssl_set_iv(
|
||||
void *cv,
|
||||
uint8_t *iv,
|
||||
srtp_cipher_direction_t dir)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
v128_t nonce;
|
||||
|
||||
/* set nonce (for alignment) */
|
||||
v128_copy_octet_string(&nonce, iv);
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "setting iv: %s", v128_hex_string(&nonce));
|
||||
|
||||
v128_xor(&c->counter, &c->offset, &nonce);
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "set_counter: %s",
|
||||
v128_hex_string(&c->counter));
|
||||
|
||||
if (!EVP_EncryptInit_ex(c->ctx, NULL, NULL, NULL, c->counter.v8)) {
|
||||
return srtp_err_status_fail;
|
||||
} else {
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This function encrypts a buffer using AES CTR mode
|
||||
*
|
||||
* Parameters:
|
||||
* c Crypto context
|
||||
* buf data to encrypt
|
||||
* enc_len length of encrypt buffer
|
||||
*/
|
||||
static srtp_err_status_t srtp_aes_icm_openssl_encrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *enc_len)
|
||||
{
|
||||
srtp_aes_icm_ctx_t *c = (srtp_aes_icm_ctx_t *)cv;
|
||||
int len = 0;
|
||||
|
||||
debug_print(srtp_mod_aes_icm, "rs0: %s", v128_hex_string(&c->counter));
|
||||
|
||||
if (!EVP_EncryptUpdate(c->ctx, buf, &len, buf, *enc_len)) {
|
||||
return srtp_err_status_cipher_fail;
|
||||
}
|
||||
*enc_len = len;
|
||||
|
||||
if (!EVP_EncryptFinal_ex(c->ctx, buf, &len)) {
|
||||
return srtp_err_status_cipher_fail;
|
||||
}
|
||||
*enc_len += len;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* Name of this crypto engine
|
||||
*/
|
||||
static const char srtp_aes_icm_128_openssl_description[] =
|
||||
"AES-128 counter mode using openssl";
|
||||
static const char srtp_aes_icm_192_openssl_description[] =
|
||||
"AES-192 counter mode using openssl";
|
||||
static const char srtp_aes_icm_256_openssl_description[] =
|
||||
"AES-256 counter mode using openssl";
|
||||
|
||||
/*
|
||||
* KAT values for AES self-test. These
|
||||
* values came from the legacy libsrtp code.
|
||||
*/
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_128_test_case_0_key[SRTP_AES_ICM_128_KEY_LEN_WSALT] = {
|
||||
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static uint8_t srtp_aes_icm_128_test_case_0_nonce[16] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_128_test_case_0_plaintext[32] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_128_test_case_0_ciphertext[32] = {
|
||||
0xe0, 0x3e, 0xad, 0x09, 0x35, 0xc9, 0x5e, 0x80,
|
||||
0xe1, 0x66, 0xb1, 0x6d, 0xd9, 0x2b, 0x4e, 0xb4,
|
||||
0xd2, 0x35, 0x13, 0x16, 0x2b, 0x02, 0xd0, 0xf7,
|
||||
0x2a, 0x43, 0xa2, 0xfe, 0x4a, 0x5f, 0x97, 0xab
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static const srtp_cipher_test_case_t srtp_aes_icm_128_test_case_0 = {
|
||||
SRTP_AES_ICM_128_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_icm_128_test_case_0_key, /* key */
|
||||
srtp_aes_icm_128_test_case_0_nonce, /* packet index */
|
||||
32, /* octets in plaintext */
|
||||
srtp_aes_icm_128_test_case_0_plaintext, /* plaintext */
|
||||
32, /* octets in ciphertext */
|
||||
srtp_aes_icm_128_test_case_0_ciphertext, /* ciphertext */
|
||||
0, /* */
|
||||
NULL, /* */
|
||||
0, /* */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/*
|
||||
* KAT values for AES-192-CTR self-test. These
|
||||
* values came from section 7 of RFC 6188.
|
||||
*/
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_192_test_case_0_key[SRTP_AES_ICM_192_KEY_LEN_WSALT] = {
|
||||
0xea, 0xb2, 0x34, 0x76, 0x4e, 0x51, 0x7b, 0x2d,
|
||||
0x3d, 0x16, 0x0d, 0x58, 0x7d, 0x8c, 0x86, 0x21,
|
||||
0x97, 0x40, 0xf6, 0x5f, 0x99, 0xb6, 0xbc, 0xf7,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static uint8_t srtp_aes_icm_192_test_case_0_nonce[16] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_192_test_case_0_plaintext[32] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_192_test_case_0_ciphertext[32] = {
|
||||
0x35, 0x09, 0x6c, 0xba, 0x46, 0x10, 0x02, 0x8d,
|
||||
0xc1, 0xb5, 0x75, 0x03, 0x80, 0x4c, 0xe3, 0x7c,
|
||||
0x5d, 0xe9, 0x86, 0x29, 0x1d, 0xcc, 0xe1, 0x61,
|
||||
0xd5, 0x16, 0x5e, 0xc4, 0x56, 0x8f, 0x5c, 0x9a
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static const srtp_cipher_test_case_t srtp_aes_icm_192_test_case_0 = {
|
||||
SRTP_AES_ICM_192_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_icm_192_test_case_0_key, /* key */
|
||||
srtp_aes_icm_192_test_case_0_nonce, /* packet index */
|
||||
32, /* octets in plaintext */
|
||||
srtp_aes_icm_192_test_case_0_plaintext, /* plaintext */
|
||||
32, /* octets in ciphertext */
|
||||
srtp_aes_icm_192_test_case_0_ciphertext, /* ciphertext */
|
||||
0, /* */
|
||||
NULL, /* */
|
||||
0, /* */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/*
|
||||
* KAT values for AES-256-CTR self-test. These
|
||||
* values came from section 7 of RFC 6188.
|
||||
*/
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_256_test_case_0_key[SRTP_AES_ICM_256_KEY_LEN_WSALT] = {
|
||||
0x57, 0xf8, 0x2f, 0xe3, 0x61, 0x3f, 0xd1, 0x70,
|
||||
0xa8, 0x5e, 0xc9, 0x3c, 0x40, 0xb1, 0xf0, 0x92,
|
||||
0x2e, 0xc4, 0xcb, 0x0d, 0xc0, 0x25, 0xb5, 0x82,
|
||||
0x72, 0x14, 0x7c, 0xc4, 0x38, 0x94, 0x4a, 0x98,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static uint8_t srtp_aes_icm_256_test_case_0_nonce[16] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_256_test_case_0_plaintext[32] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_aes_icm_256_test_case_0_ciphertext[32] = {
|
||||
0x92, 0xbd, 0xd2, 0x8a, 0x93, 0xc3, 0xf5, 0x25,
|
||||
0x11, 0xc6, 0x77, 0xd0, 0x8b, 0x55, 0x15, 0xa4,
|
||||
0x9d, 0xa7, 0x1b, 0x23, 0x78, 0xa8, 0x54, 0xf6,
|
||||
0x70, 0x50, 0x75, 0x6d, 0xed, 0x16, 0x5b, 0xac
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static const srtp_cipher_test_case_t srtp_aes_icm_256_test_case_0 = {
|
||||
SRTP_AES_ICM_256_KEY_LEN_WSALT, /* octets in key */
|
||||
srtp_aes_icm_256_test_case_0_key, /* key */
|
||||
srtp_aes_icm_256_test_case_0_nonce, /* packet index */
|
||||
32, /* octets in plaintext */
|
||||
srtp_aes_icm_256_test_case_0_plaintext, /* plaintext */
|
||||
32, /* octets in ciphertext */
|
||||
srtp_aes_icm_256_test_case_0_ciphertext, /* ciphertext */
|
||||
0, /* */
|
||||
NULL, /* */
|
||||
0, /* */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the function table for this crypto engine.
|
||||
* note: the encrypt function is identical to the decrypt function
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_icm_128 = {
|
||||
srtp_aes_icm_openssl_alloc, /* */
|
||||
srtp_aes_icm_openssl_dealloc, /* */
|
||||
srtp_aes_icm_openssl_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_openssl_encrypt, /* */
|
||||
srtp_aes_icm_openssl_encrypt, /* */
|
||||
srtp_aes_icm_openssl_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_128_openssl_description, /* */
|
||||
&srtp_aes_icm_128_test_case_0, /* */
|
||||
SRTP_AES_ICM_128 /* */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the function table for this crypto engine.
|
||||
* note: the encrypt function is identical to the decrypt function
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_icm_192 = {
|
||||
srtp_aes_icm_openssl_alloc, /* */
|
||||
srtp_aes_icm_openssl_dealloc, /* */
|
||||
srtp_aes_icm_openssl_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_openssl_encrypt, /* */
|
||||
srtp_aes_icm_openssl_encrypt, /* */
|
||||
srtp_aes_icm_openssl_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_192_openssl_description, /* */
|
||||
&srtp_aes_icm_192_test_case_0, /* */
|
||||
SRTP_AES_ICM_192 /* */
|
||||
};
|
||||
|
||||
/*
|
||||
* This is the function table for this crypto engine.
|
||||
* note: the encrypt function is identical to the decrypt function
|
||||
*/
|
||||
const srtp_cipher_type_t srtp_aes_icm_256 = {
|
||||
srtp_aes_icm_openssl_alloc, /* */
|
||||
srtp_aes_icm_openssl_dealloc, /* */
|
||||
srtp_aes_icm_openssl_context_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_aes_icm_openssl_encrypt, /* */
|
||||
srtp_aes_icm_openssl_encrypt, /* */
|
||||
srtp_aes_icm_openssl_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_aes_icm_256_openssl_description, /* */
|
||||
&srtp_aes_icm_256_test_case_0, /* */
|
||||
SRTP_AES_ICM_256 /* */
|
||||
};
|
||||
677
TMessagesProj/jni/third_party/libsrtp/crypto/cipher/cipher.c
vendored
Normal file
677
TMessagesProj/jni/third_party/libsrtp/crypto/cipher/cipher.c
vendored
Normal file
|
|
@ -0,0 +1,677 @@
|
|||
/*
|
||||
* cipher.c
|
||||
*
|
||||
* cipher meta-functions
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "cipher.h"
|
||||
#include "crypto_types.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "alloc.h" /* for crypto_alloc(), crypto_free() */
|
||||
|
||||
srtp_debug_module_t srtp_mod_cipher = {
|
||||
0, /* debugging is off by default */
|
||||
"cipher" /* printable module name */
|
||||
};
|
||||
|
||||
srtp_err_status_t srtp_cipher_type_alloc(const srtp_cipher_type_t *ct,
|
||||
srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen)
|
||||
{
|
||||
if (!ct || !ct->alloc) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
return ((ct)->alloc((c), (key_len), (tlen)));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_dealloc(srtp_cipher_t *c)
|
||||
{
|
||||
if (!c || !c->type) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
return (((c)->type)->dealloc(c));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_init(srtp_cipher_t *c, const uint8_t *key)
|
||||
{
|
||||
if (!c || !c->type || !c->state) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
return (((c)->type)->init(((c)->state), (key)));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_set_iv(srtp_cipher_t *c,
|
||||
uint8_t *iv,
|
||||
int direction)
|
||||
{
|
||||
if (!c || !c->type || !c->state) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
return (((c)->type)->set_iv(((c)->state), iv, direction));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_output(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *num_octets_to_output)
|
||||
{
|
||||
/* zeroize the buffer */
|
||||
octet_string_set_to_zero(buffer, *num_octets_to_output);
|
||||
|
||||
/* exor keystream into buffer */
|
||||
return (((c)->type)->encrypt(((c)->state), buffer, num_octets_to_output));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_encrypt(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *num_octets_to_output)
|
||||
{
|
||||
if (!c || !c->type || !c->state) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
return (((c)->type)->encrypt(((c)->state), buffer, num_octets_to_output));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_decrypt(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *num_octets_to_output)
|
||||
{
|
||||
if (!c || !c->type || !c->state) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
|
||||
return (((c)->type)->decrypt(((c)->state), buffer, num_octets_to_output));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_get_tag(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *tag_len)
|
||||
{
|
||||
if (!c || !c->type || !c->state) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
if (!((c)->type)->get_tag) {
|
||||
return (srtp_err_status_no_such_op);
|
||||
}
|
||||
|
||||
return (((c)->type)->get_tag(((c)->state), buffer, tag_len));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_cipher_set_aad(srtp_cipher_t *c,
|
||||
const uint8_t *aad,
|
||||
uint32_t aad_len)
|
||||
{
|
||||
if (!c || !c->type || !c->state) {
|
||||
return (srtp_err_status_bad_param);
|
||||
}
|
||||
if (!((c)->type)->set_aad) {
|
||||
return (srtp_err_status_no_such_op);
|
||||
}
|
||||
|
||||
return (((c)->type)->set_aad(((c)->state), aad, aad_len));
|
||||
}
|
||||
|
||||
/* some bookkeeping functions */
|
||||
|
||||
int srtp_cipher_get_key_length(const srtp_cipher_t *c)
|
||||
{
|
||||
return c->key_len;
|
||||
}
|
||||
|
||||
/*
|
||||
* A trivial platform independent random source. The random
|
||||
* data is used for some of the cipher self-tests.
|
||||
*/
|
||||
static srtp_err_status_t srtp_cipher_rand(void *dest, uint32_t len)
|
||||
{
|
||||
#if defined(HAVE_RAND_S)
|
||||
uint8_t *dst = (uint8_t *)dest;
|
||||
while (len) {
|
||||
unsigned int val;
|
||||
errno_t err = rand_s(&val);
|
||||
|
||||
if (err != 0)
|
||||
return srtp_err_status_fail;
|
||||
|
||||
*dst++ = val & 0xff;
|
||||
len--;
|
||||
}
|
||||
#else
|
||||
/* Generic C-library (rand()) version */
|
||||
/* This is a random source of last resort */
|
||||
uint8_t *dst = (uint8_t *)dest;
|
||||
while (len) {
|
||||
int val = rand();
|
||||
/* rand() returns 0-32767 (ugh) */
|
||||
/* Is this a good enough way to get random bytes?
|
||||
It is if it passes FIPS-140... */
|
||||
*dst++ = val & 0xff;
|
||||
len--;
|
||||
}
|
||||
#endif
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
#define SELF_TEST_BUF_OCTETS 128
|
||||
#define NUM_RAND_TESTS 128
|
||||
#define MAX_KEY_LEN 64
|
||||
/*
|
||||
* srtp_cipher_type_test(ct, test_data) tests a cipher of type ct against
|
||||
* test cases provided in a list test_data of values of key, salt, iv,
|
||||
* plaintext, and ciphertext that is known to be good
|
||||
*/
|
||||
srtp_err_status_t srtp_cipher_type_test(
|
||||
const srtp_cipher_type_t *ct,
|
||||
const srtp_cipher_test_case_t *test_data)
|
||||
{
|
||||
const srtp_cipher_test_case_t *test_case = test_data;
|
||||
srtp_cipher_t *c;
|
||||
srtp_err_status_t status;
|
||||
uint8_t buffer[SELF_TEST_BUF_OCTETS];
|
||||
uint8_t buffer2[SELF_TEST_BUF_OCTETS];
|
||||
uint32_t tag_len;
|
||||
unsigned int len;
|
||||
int i, j, case_num = 0;
|
||||
unsigned k = 0;
|
||||
|
||||
debug_print(srtp_mod_cipher, "running self-test for cipher %s",
|
||||
ct->description);
|
||||
|
||||
/*
|
||||
* check to make sure that we have at least one test case, and
|
||||
* return an error if we don't - we need to be paranoid here
|
||||
*/
|
||||
if (test_case == NULL) {
|
||||
return srtp_err_status_cant_check;
|
||||
}
|
||||
|
||||
/*
|
||||
* loop over all test cases, perform known-answer tests of both the
|
||||
* encryption and decryption functions
|
||||
*/
|
||||
while (test_case != NULL) {
|
||||
/* allocate cipher */
|
||||
status = srtp_cipher_type_alloc(ct, &c, test_case->key_length_octets,
|
||||
test_case->tag_length_octets);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* test the encrypt function
|
||||
*/
|
||||
debug_print(srtp_mod_cipher, "testing encryption", NULL);
|
||||
|
||||
/* initialize cipher */
|
||||
status = srtp_cipher_init(c, test_case->key);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* copy plaintext into test buffer */
|
||||
if (test_case->ciphertext_length_octets > SELF_TEST_BUF_OCTETS) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
for (k = 0; k < test_case->plaintext_length_octets; k++) {
|
||||
buffer[k] = test_case->plaintext[k];
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_cipher, "plaintext: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
buffer, test_case->plaintext_length_octets));
|
||||
|
||||
/* set the initialization vector */
|
||||
status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx,
|
||||
srtp_direction_encrypt);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
if (c->algorithm == SRTP_AES_GCM_128 ||
|
||||
c->algorithm == SRTP_AES_GCM_256) {
|
||||
debug_print(srtp_mod_cipher, "IV: %s",
|
||||
srtp_octet_string_hex_string(test_case->idx, 12));
|
||||
|
||||
/*
|
||||
* Set the AAD
|
||||
*/
|
||||
status = srtp_cipher_set_aad(c, test_case->aad,
|
||||
test_case->aad_length_octets);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
debug_print(srtp_mod_cipher, "AAD: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->aad, test_case->aad_length_octets));
|
||||
}
|
||||
|
||||
/* encrypt */
|
||||
len = test_case->plaintext_length_octets;
|
||||
status = srtp_cipher_encrypt(c, buffer, &len);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
if (c->algorithm == SRTP_AES_GCM_128 ||
|
||||
c->algorithm == SRTP_AES_GCM_256) {
|
||||
/*
|
||||
* Get the GCM tag
|
||||
*/
|
||||
status = srtp_cipher_get_tag(c, buffer + len, &tag_len);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
len += tag_len;
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_cipher, "ciphertext: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
buffer, test_case->ciphertext_length_octets));
|
||||
|
||||
/* compare the resulting ciphertext with that in the test case */
|
||||
if (len != test_case->ciphertext_length_octets) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
status = srtp_err_status_ok;
|
||||
for (k = 0; k < test_case->ciphertext_length_octets; k++) {
|
||||
if (buffer[k] != test_case->ciphertext[k]) {
|
||||
status = srtp_err_status_algo_fail;
|
||||
debug_print(srtp_mod_cipher, "test case %d failed", case_num);
|
||||
debug_print(srtp_mod_cipher, "(failure at byte %u)", k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (status) {
|
||||
debug_print(srtp_mod_cipher, "c computed: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
buffer, 2 * test_case->plaintext_length_octets));
|
||||
debug_print(srtp_mod_cipher, "c expected: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->ciphertext,
|
||||
2 * test_case->plaintext_length_octets));
|
||||
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
|
||||
/*
|
||||
* test the decrypt function
|
||||
*/
|
||||
debug_print(srtp_mod_cipher, "testing decryption", NULL);
|
||||
|
||||
/* re-initialize cipher for decryption */
|
||||
status = srtp_cipher_init(c, test_case->key);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* copy ciphertext into test buffer */
|
||||
if (test_case->ciphertext_length_octets > SELF_TEST_BUF_OCTETS) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
for (k = 0; k < test_case->ciphertext_length_octets; k++) {
|
||||
buffer[k] = test_case->ciphertext[k];
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_cipher, "ciphertext: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
buffer, test_case->plaintext_length_octets));
|
||||
|
||||
/* set the initialization vector */
|
||||
status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx,
|
||||
srtp_direction_decrypt);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
if (c->algorithm == SRTP_AES_GCM_128 ||
|
||||
c->algorithm == SRTP_AES_GCM_256) {
|
||||
/*
|
||||
* Set the AAD
|
||||
*/
|
||||
status = srtp_cipher_set_aad(c, test_case->aad,
|
||||
test_case->aad_length_octets);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
debug_print(srtp_mod_cipher, "AAD: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->aad, test_case->aad_length_octets));
|
||||
}
|
||||
|
||||
/* decrypt */
|
||||
len = test_case->ciphertext_length_octets;
|
||||
status = srtp_cipher_decrypt(c, buffer, &len);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_cipher, "plaintext: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
buffer, test_case->plaintext_length_octets));
|
||||
|
||||
/* compare the resulting plaintext with that in the test case */
|
||||
if (len != test_case->plaintext_length_octets) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
status = srtp_err_status_ok;
|
||||
for (k = 0; k < test_case->plaintext_length_octets; k++) {
|
||||
if (buffer[k] != test_case->plaintext[k]) {
|
||||
status = srtp_err_status_algo_fail;
|
||||
debug_print(srtp_mod_cipher, "test case %d failed", case_num);
|
||||
debug_print(srtp_mod_cipher, "(failure at byte %u)", k);
|
||||
}
|
||||
}
|
||||
if (status) {
|
||||
debug_print(srtp_mod_cipher, "p computed: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
buffer, 2 * test_case->plaintext_length_octets));
|
||||
debug_print(srtp_mod_cipher, "p expected: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->plaintext,
|
||||
2 * test_case->plaintext_length_octets));
|
||||
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
|
||||
/* deallocate the cipher */
|
||||
status = srtp_cipher_dealloc(c);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* the cipher passed the test case, so move on to the next test
|
||||
* case in the list; if NULL, we'l proceed to the next test
|
||||
*/
|
||||
test_case = test_case->next_test_case;
|
||||
++case_num;
|
||||
}
|
||||
|
||||
/* now run some random invertibility tests */
|
||||
|
||||
/* allocate cipher, using paramaters from the first test case */
|
||||
test_case = test_data;
|
||||
status = srtp_cipher_type_alloc(ct, &c, test_case->key_length_octets,
|
||||
test_case->tag_length_octets);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
for (j = 0; j < NUM_RAND_TESTS; j++) {
|
||||
unsigned int length;
|
||||
unsigned int plaintext_len;
|
||||
uint8_t key[MAX_KEY_LEN];
|
||||
uint8_t iv[MAX_KEY_LEN];
|
||||
|
||||
/* choose a length at random (leaving room for IV and padding) */
|
||||
length = rand() % (SELF_TEST_BUF_OCTETS - 64);
|
||||
debug_print(srtp_mod_cipher, "random plaintext length %d\n", length);
|
||||
status = srtp_cipher_rand(buffer, length);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_cipher, "plaintext: %s",
|
||||
srtp_octet_string_hex_string(buffer, length));
|
||||
|
||||
/* copy plaintext into second buffer */
|
||||
for (i = 0; (unsigned int)i < length; i++) {
|
||||
buffer2[i] = buffer[i];
|
||||
}
|
||||
|
||||
/* choose a key at random */
|
||||
if (test_case->key_length_octets > MAX_KEY_LEN) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_cant_check;
|
||||
}
|
||||
status = srtp_cipher_rand(key, test_case->key_length_octets);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* chose a random initialization vector */
|
||||
status = srtp_cipher_rand(iv, MAX_KEY_LEN);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* initialize cipher */
|
||||
status = srtp_cipher_init(c, key);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* set initialization vector */
|
||||
status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx,
|
||||
srtp_direction_encrypt);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
if (c->algorithm == SRTP_AES_GCM_128 ||
|
||||
c->algorithm == SRTP_AES_GCM_256) {
|
||||
/*
|
||||
* Set the AAD
|
||||
*/
|
||||
status = srtp_cipher_set_aad(c, test_case->aad,
|
||||
test_case->aad_length_octets);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
debug_print(srtp_mod_cipher, "AAD: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->aad, test_case->aad_length_octets));
|
||||
}
|
||||
|
||||
/* encrypt buffer with cipher */
|
||||
plaintext_len = length;
|
||||
status = srtp_cipher_encrypt(c, buffer, &length);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
if (c->algorithm == SRTP_AES_GCM_128 ||
|
||||
c->algorithm == SRTP_AES_GCM_256) {
|
||||
/*
|
||||
* Get the GCM tag
|
||||
*/
|
||||
status = srtp_cipher_get_tag(c, buffer + length, &tag_len);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
length += tag_len;
|
||||
}
|
||||
debug_print(srtp_mod_cipher, "ciphertext: %s",
|
||||
srtp_octet_string_hex_string(buffer, length));
|
||||
|
||||
/*
|
||||
* re-initialize cipher for decryption, re-set the iv, then
|
||||
* decrypt the ciphertext
|
||||
*/
|
||||
status = srtp_cipher_init(c, key);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
status = srtp_cipher_set_iv(c, (uint8_t *)test_case->idx,
|
||||
srtp_direction_decrypt);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
if (c->algorithm == SRTP_AES_GCM_128 ||
|
||||
c->algorithm == SRTP_AES_GCM_256) {
|
||||
/*
|
||||
* Set the AAD
|
||||
*/
|
||||
status = srtp_cipher_set_aad(c, test_case->aad,
|
||||
test_case->aad_length_octets);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
debug_print(srtp_mod_cipher, "AAD: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->aad, test_case->aad_length_octets));
|
||||
}
|
||||
status = srtp_cipher_decrypt(c, buffer, &length);
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return status;
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_cipher, "plaintext[2]: %s",
|
||||
srtp_octet_string_hex_string(buffer, length));
|
||||
|
||||
/* compare the resulting plaintext with the original one */
|
||||
if (length != plaintext_len) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
status = srtp_err_status_ok;
|
||||
for (k = 0; k < plaintext_len; k++) {
|
||||
if (buffer[k] != buffer2[k]) {
|
||||
status = srtp_err_status_algo_fail;
|
||||
debug_print(srtp_mod_cipher, "random test case %d failed",
|
||||
case_num);
|
||||
debug_print(srtp_mod_cipher, "(failure at byte %u)", k);
|
||||
}
|
||||
}
|
||||
if (status) {
|
||||
srtp_cipher_dealloc(c);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
}
|
||||
|
||||
status = srtp_cipher_dealloc(c);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_cipher_type_self_test(ct) performs srtp_cipher_type_test on ct's
|
||||
* internal list of test data.
|
||||
*/
|
||||
srtp_err_status_t srtp_cipher_type_self_test(const srtp_cipher_type_t *ct)
|
||||
{
|
||||
return srtp_cipher_type_test(ct, ct->test_data);
|
||||
}
|
||||
|
||||
/*
|
||||
* cipher_bits_per_second(c, l, t) computes (an estimate of) the
|
||||
* number of bits that a cipher implementation can encrypt in a second
|
||||
*
|
||||
* c is a cipher (which MUST be allocated and initialized already), l
|
||||
* is the length in octets of the test data to be encrypted, and t is
|
||||
* the number of trials
|
||||
*
|
||||
* if an error is encountered, the value 0 is returned
|
||||
*/
|
||||
uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c,
|
||||
int octets_in_buffer,
|
||||
int num_trials)
|
||||
{
|
||||
int i;
|
||||
v128_t nonce;
|
||||
clock_t timer;
|
||||
unsigned char *enc_buf;
|
||||
unsigned int len = octets_in_buffer;
|
||||
|
||||
enc_buf = (unsigned char *)srtp_crypto_alloc(octets_in_buffer);
|
||||
if (enc_buf == NULL) {
|
||||
return 0; /* indicate bad parameters by returning null */
|
||||
}
|
||||
/* time repeated trials */
|
||||
v128_set_to_zero(&nonce);
|
||||
timer = clock();
|
||||
for (i = 0; i < num_trials; i++, nonce.v32[3] = i) {
|
||||
if (srtp_cipher_set_iv(c, (uint8_t *)&nonce, srtp_direction_encrypt) !=
|
||||
srtp_err_status_ok) {
|
||||
srtp_crypto_free(enc_buf);
|
||||
return 0;
|
||||
}
|
||||
if (srtp_cipher_encrypt(c, enc_buf, &len) != srtp_err_status_ok) {
|
||||
srtp_crypto_free(enc_buf);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
timer = clock() - timer;
|
||||
|
||||
srtp_crypto_free(enc_buf);
|
||||
|
||||
if (timer == 0) {
|
||||
/* Too fast! */
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint64_t)CLOCKS_PER_SEC * num_trials * 8 * octets_in_buffer / timer;
|
||||
}
|
||||
151
TMessagesProj/jni/third_party/libsrtp/crypto/cipher/null_cipher.c
vendored
Normal file
151
TMessagesProj/jni/third_party/libsrtp/crypto/cipher/null_cipher.c
vendored
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
* null_cipher.c
|
||||
*
|
||||
* A null cipher implementation. This cipher leaves the plaintext
|
||||
* unchanged.
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "datatypes.h"
|
||||
#include "null_cipher.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "alloc.h"
|
||||
#include "cipher_types.h"
|
||||
|
||||
static srtp_err_status_t srtp_null_cipher_alloc(srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen)
|
||||
{
|
||||
extern const srtp_cipher_type_t srtp_null_cipher;
|
||||
|
||||
debug_print(srtp_mod_cipher, "allocating cipher with key length %d",
|
||||
key_len);
|
||||
|
||||
/* allocate memory a cipher of type null_cipher */
|
||||
*c = (srtp_cipher_t *)srtp_crypto_alloc(sizeof(srtp_cipher_t));
|
||||
if (*c == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* set pointers */
|
||||
(*c)->algorithm = SRTP_NULL_CIPHER;
|
||||
(*c)->type = &srtp_null_cipher;
|
||||
(*c)->state = (void *)0x1; /* The null cipher does not maintain state */
|
||||
|
||||
/* set key size */
|
||||
(*c)->key_len = key_len;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_cipher_dealloc(srtp_cipher_t *c)
|
||||
{
|
||||
extern const srtp_cipher_type_t srtp_null_cipher;
|
||||
|
||||
/* zeroize entire state*/
|
||||
octet_string_set_to_zero(c, sizeof(srtp_cipher_t));
|
||||
|
||||
/* free memory of type null_cipher */
|
||||
srtp_crypto_free(c);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_cipher_init(void *cv, const uint8_t *key)
|
||||
{
|
||||
/* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */
|
||||
|
||||
debug_print(srtp_mod_cipher, "initializing null cipher", NULL);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_cipher_set_iv(void *cv,
|
||||
uint8_t *iv,
|
||||
srtp_cipher_direction_t dir)
|
||||
{
|
||||
/* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_cipher_encrypt(void *cv,
|
||||
unsigned char *buf,
|
||||
unsigned int *bytes_to_encr)
|
||||
{
|
||||
/* srtp_null_cipher_ctx_t *c = (srtp_null_cipher_ctx_t *)cv; */
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static const char srtp_null_cipher_description[] = "null cipher";
|
||||
|
||||
static const srtp_cipher_test_case_t srtp_null_cipher_test_0 = {
|
||||
0, /* octets in key */
|
||||
NULL, /* key */
|
||||
0, /* packet index */
|
||||
0, /* octets in plaintext */
|
||||
NULL, /* plaintext */
|
||||
0, /* octets in plaintext */
|
||||
NULL, /* ciphertext */
|
||||
0, /* */
|
||||
NULL, /* */
|
||||
0, /* */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/*
|
||||
* note: the decrypt function is idential to the encrypt function
|
||||
*/
|
||||
|
||||
const srtp_cipher_type_t srtp_null_cipher = {
|
||||
srtp_null_cipher_alloc, /* */
|
||||
srtp_null_cipher_dealloc, /* */
|
||||
srtp_null_cipher_init, /* */
|
||||
0, /* set_aad */
|
||||
srtp_null_cipher_encrypt, /* */
|
||||
srtp_null_cipher_encrypt, /* */
|
||||
srtp_null_cipher_set_iv, /* */
|
||||
0, /* get_tag */
|
||||
srtp_null_cipher_description, /* */
|
||||
&srtp_null_cipher_test_0, /* */
|
||||
SRTP_NULL_CIPHER /* */
|
||||
};
|
||||
185
TMessagesProj/jni/third_party/libsrtp/crypto/hash/auth.c
vendored
Normal file
185
TMessagesProj/jni/third_party/libsrtp/crypto/hash/auth.c
vendored
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
* auth.c
|
||||
*
|
||||
* some bookkeeping functions for authentication functions
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "auth.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "datatypes.h" /* for octet_string */
|
||||
|
||||
/* the debug module for authentiation */
|
||||
|
||||
srtp_debug_module_t srtp_mod_auth = {
|
||||
0, /* debugging is off by default */
|
||||
"auth func" /* printable name for module */
|
||||
};
|
||||
|
||||
int srtp_auth_get_key_length(const srtp_auth_t *a)
|
||||
{
|
||||
return a->key_len;
|
||||
}
|
||||
|
||||
int srtp_auth_get_tag_length(const srtp_auth_t *a)
|
||||
{
|
||||
return a->out_len;
|
||||
}
|
||||
|
||||
int srtp_auth_get_prefix_length(const srtp_auth_t *a)
|
||||
{
|
||||
return a->prefix_len;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_auth_type_test() tests an auth function of type ct against
|
||||
* test cases provided in a list test_data of values of key, data, and tag
|
||||
* that is known to be good
|
||||
*/
|
||||
|
||||
/* should be big enough for most occasions */
|
||||
#define SELF_TEST_TAG_BUF_OCTETS 32
|
||||
|
||||
srtp_err_status_t srtp_auth_type_test(const srtp_auth_type_t *at,
|
||||
const srtp_auth_test_case_t *test_data)
|
||||
{
|
||||
const srtp_auth_test_case_t *test_case = test_data;
|
||||
srtp_auth_t *a;
|
||||
srtp_err_status_t status;
|
||||
uint8_t tag[SELF_TEST_TAG_BUF_OCTETS];
|
||||
int i, case_num = 0;
|
||||
|
||||
debug_print(srtp_mod_auth, "running self-test for auth function %s",
|
||||
at->description);
|
||||
|
||||
/*
|
||||
* check to make sure that we have at least one test case, and
|
||||
* return an error if we don't - we need to be paranoid here
|
||||
*/
|
||||
if (test_case == NULL) {
|
||||
return srtp_err_status_cant_check;
|
||||
}
|
||||
|
||||
/* loop over all test cases */
|
||||
while (test_case != NULL) {
|
||||
/* check test case parameters */
|
||||
if (test_case->tag_length_octets > SELF_TEST_TAG_BUF_OCTETS) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* allocate auth */
|
||||
status = srtp_auth_type_alloc(at, &a, test_case->key_length_octets,
|
||||
test_case->tag_length_octets);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* initialize auth */
|
||||
status = srtp_auth_init(a, test_case->key);
|
||||
if (status) {
|
||||
srtp_auth_dealloc(a);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* zeroize tag then compute */
|
||||
octet_string_set_to_zero(tag, test_case->tag_length_octets);
|
||||
status = srtp_auth_compute(a, test_case->data,
|
||||
test_case->data_length_octets, tag);
|
||||
if (status) {
|
||||
srtp_auth_dealloc(a);
|
||||
return status;
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_auth, "key: %s",
|
||||
srtp_octet_string_hex_string(test_case->key,
|
||||
test_case->key_length_octets));
|
||||
debug_print(srtp_mod_auth, "data: %s",
|
||||
srtp_octet_string_hex_string(
|
||||
test_case->data, test_case->data_length_octets));
|
||||
debug_print(
|
||||
srtp_mod_auth, "tag computed: %s",
|
||||
srtp_octet_string_hex_string(tag, test_case->tag_length_octets));
|
||||
debug_print(srtp_mod_auth, "tag expected: %s",
|
||||
srtp_octet_string_hex_string(test_case->tag,
|
||||
test_case->tag_length_octets));
|
||||
|
||||
/* check the result */
|
||||
status = srtp_err_status_ok;
|
||||
for (i = 0; i < test_case->tag_length_octets; i++) {
|
||||
if (tag[i] != test_case->tag[i]) {
|
||||
status = srtp_err_status_algo_fail;
|
||||
debug_print(srtp_mod_auth, "test case %d failed", case_num);
|
||||
debug_print(srtp_mod_auth, " (mismatch at octet %d)", i);
|
||||
}
|
||||
}
|
||||
if (status) {
|
||||
srtp_auth_dealloc(a);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
|
||||
/* deallocate the auth function */
|
||||
status = srtp_auth_dealloc(a);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* the auth function passed the test case, so move on to the next test
|
||||
* case in the list; if NULL, we'll quit and return an OK
|
||||
*/
|
||||
test_case = test_case->next_test_case;
|
||||
++case_num;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_auth_type_self_test(at) performs srtp_auth_type_test on at's internal
|
||||
* list of test data.
|
||||
*/
|
||||
|
||||
srtp_err_status_t srtp_auth_type_self_test(const srtp_auth_type_t *at)
|
||||
{
|
||||
return srtp_auth_type_test(at, at->test_data);
|
||||
}
|
||||
271
TMessagesProj/jni/third_party/libsrtp/crypto/hash/hmac_ossl.c
vendored
Normal file
271
TMessagesProj/jni/third_party/libsrtp/crypto/hash/hmac_ossl.c
vendored
Normal file
|
|
@ -0,0 +1,271 @@
|
|||
/*
|
||||
* hmac_ossl.c
|
||||
*
|
||||
* Implementation of hmac srtp_auth_type_t that leverages OpenSSL
|
||||
*
|
||||
* John A. Foley
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "auth.h"
|
||||
#include "alloc.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/hmac.h>
|
||||
|
||||
#define SHA1_DIGEST_SIZE 20
|
||||
|
||||
/* the debug module for authentiation */
|
||||
|
||||
srtp_debug_module_t srtp_mod_hmac = {
|
||||
0, /* debugging is off by default */
|
||||
"hmac sha-1 openssl" /* printable name for module */
|
||||
};
|
||||
|
||||
static srtp_err_status_t srtp_hmac_alloc(srtp_auth_t **a,
|
||||
int key_len,
|
||||
int out_len)
|
||||
{
|
||||
extern const srtp_auth_type_t srtp_hmac;
|
||||
|
||||
debug_print(srtp_mod_hmac, "allocating auth func with key length %d",
|
||||
key_len);
|
||||
debug_print(srtp_mod_hmac, " tag length %d",
|
||||
out_len);
|
||||
|
||||
/* check output length - should be less than 20 bytes */
|
||||
if (out_len > SHA1_DIGEST_SIZE) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* OpenSSL 1.1.0 made HMAC_CTX an opaque structure, which must be allocated
|
||||
using HMAC_CTX_new. But this function doesn't exist in OpenSSL 1.0.x. */
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L || LIBRESSL_VERSION_NUMBER
|
||||
{
|
||||
/* allocate memory for auth and HMAC_CTX structures */
|
||||
uint8_t *pointer;
|
||||
HMAC_CTX *new_hmac_ctx;
|
||||
pointer = (uint8_t *)srtp_crypto_alloc(sizeof(HMAC_CTX) +
|
||||
sizeof(srtp_auth_t));
|
||||
if (pointer == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
*a = (srtp_auth_t *)pointer;
|
||||
(*a)->state = pointer + sizeof(srtp_auth_t);
|
||||
new_hmac_ctx = (HMAC_CTX *)((*a)->state);
|
||||
|
||||
HMAC_CTX_init(new_hmac_ctx);
|
||||
}
|
||||
|
||||
#else
|
||||
*a = (srtp_auth_t *)srtp_crypto_alloc(sizeof(srtp_auth_t));
|
||||
if (*a == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
(*a)->state = HMAC_CTX_new();
|
||||
if ((*a)->state == NULL) {
|
||||
srtp_crypto_free(*a);
|
||||
*a = NULL;
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* set pointers */
|
||||
(*a)->type = &srtp_hmac;
|
||||
(*a)->out_len = out_len;
|
||||
(*a)->key_len = key_len;
|
||||
(*a)->prefix_len = 0;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_dealloc(srtp_auth_t *a)
|
||||
{
|
||||
HMAC_CTX *hmac_ctx;
|
||||
|
||||
hmac_ctx = (HMAC_CTX *)a->state;
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x10100000L || LIBRESSL_VERSION_NUMBER
|
||||
HMAC_CTX_cleanup(hmac_ctx);
|
||||
|
||||
/* zeroize entire state*/
|
||||
octet_string_set_to_zero(a, sizeof(HMAC_CTX) + sizeof(srtp_auth_t));
|
||||
|
||||
#else
|
||||
HMAC_CTX_free(hmac_ctx);
|
||||
|
||||
/* zeroize entire state*/
|
||||
octet_string_set_to_zero(a, sizeof(srtp_auth_t));
|
||||
#endif
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(a);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_start(void *statev)
|
||||
{
|
||||
HMAC_CTX *state = (HMAC_CTX *)statev;
|
||||
|
||||
if (HMAC_Init_ex(state, NULL, 0, NULL, NULL) == 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_init(void *statev,
|
||||
const uint8_t *key,
|
||||
int key_len)
|
||||
{
|
||||
HMAC_CTX *state = (HMAC_CTX *)statev;
|
||||
|
||||
if (HMAC_Init_ex(state, key, key_len, EVP_sha1(), NULL) == 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_update(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets)
|
||||
{
|
||||
HMAC_CTX *state = (HMAC_CTX *)statev;
|
||||
|
||||
debug_print(srtp_mod_hmac, "input: %s",
|
||||
srtp_octet_string_hex_string(message, msg_octets));
|
||||
|
||||
if (HMAC_Update(state, message, msg_octets) == 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_hmac_compute(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets,
|
||||
int tag_len,
|
||||
uint8_t *result)
|
||||
{
|
||||
HMAC_CTX *state = (HMAC_CTX *)statev;
|
||||
uint8_t hash_value[SHA1_DIGEST_SIZE];
|
||||
int i;
|
||||
unsigned int len;
|
||||
|
||||
/* check tag length, return error if we can't provide the value expected */
|
||||
if (tag_len > SHA1_DIGEST_SIZE) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* hash message, copy output into H */
|
||||
if (HMAC_Update(state, message, msg_octets) == 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
if (HMAC_Final(state, hash_value, &len) == 0)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
if (len < tag_len)
|
||||
return srtp_err_status_auth_fail;
|
||||
|
||||
/* copy hash_value to *result */
|
||||
for (i = 0; i < tag_len; i++) {
|
||||
result[i] = hash_value[i];
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_hmac, "output: %s",
|
||||
srtp_octet_string_hex_string(hash_value, tag_len));
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/* begin test case 0 */
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_hmac_test_case_0_key[SHA1_DIGEST_SIZE] = {
|
||||
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
||||
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
||||
0x0b, 0x0b, 0x0b, 0x0b
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_hmac_test_case_0_data[8] = {
|
||||
0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65 /* "Hi There" */
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
/* clang-format off */
|
||||
static const uint8_t srtp_hmac_test_case_0_tag[SHA1_DIGEST_SIZE] = {
|
||||
0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64,
|
||||
0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e,
|
||||
0xf1, 0x46, 0xbe, 0x00
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static const srtp_auth_test_case_t srtp_hmac_test_case_0 = {
|
||||
sizeof(srtp_hmac_test_case_0_key), /* octets in key */
|
||||
srtp_hmac_test_case_0_key, /* key */
|
||||
sizeof(srtp_hmac_test_case_0_data), /* octets in data */
|
||||
srtp_hmac_test_case_0_data, /* data */
|
||||
sizeof(srtp_hmac_test_case_0_tag), /* octets in tag */
|
||||
srtp_hmac_test_case_0_tag, /* tag */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/* end test case 0 */
|
||||
|
||||
static const char srtp_hmac_description[] =
|
||||
"hmac sha-1 authentication function";
|
||||
|
||||
/*
|
||||
* srtp_auth_type_t hmac is the hmac metaobject
|
||||
*/
|
||||
|
||||
const srtp_auth_type_t srtp_hmac = {
|
||||
srtp_hmac_alloc, /* */
|
||||
srtp_hmac_dealloc, /* */
|
||||
srtp_hmac_init, /* */
|
||||
srtp_hmac_compute, /* */
|
||||
srtp_hmac_update, /* */
|
||||
srtp_hmac_start, /* */
|
||||
srtp_hmac_description, /* */
|
||||
&srtp_hmac_test_case_0, /* */
|
||||
SRTP_HMAC_SHA1 /* */
|
||||
};
|
||||
166
TMessagesProj/jni/third_party/libsrtp/crypto/hash/null_auth.c
vendored
Normal file
166
TMessagesProj/jni/third_party/libsrtp/crypto/hash/null_auth.c
vendored
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* null_auth.c
|
||||
*
|
||||
* implements the do-nothing auth algorithm
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "null_auth.h"
|
||||
#include "err.h" /* for srtp_debug */
|
||||
#include "alloc.h"
|
||||
#include "cipher_types.h"
|
||||
|
||||
static srtp_err_status_t srtp_null_auth_alloc(srtp_auth_t **a,
|
||||
int key_len,
|
||||
int out_len)
|
||||
{
|
||||
extern const srtp_auth_type_t srtp_null_auth;
|
||||
uint8_t *pointer;
|
||||
|
||||
debug_print(srtp_mod_auth, "allocating auth func with key length %d",
|
||||
key_len);
|
||||
debug_print(srtp_mod_auth, " tag length %d",
|
||||
out_len);
|
||||
|
||||
/* allocate memory for auth and srtp_null_auth_ctx_t structures */
|
||||
pointer = (uint8_t *)srtp_crypto_alloc(sizeof(srtp_null_auth_ctx_t) +
|
||||
sizeof(srtp_auth_t));
|
||||
if (pointer == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* set pointers */
|
||||
*a = (srtp_auth_t *)pointer;
|
||||
(*a)->type = &srtp_null_auth;
|
||||
(*a)->state = pointer + sizeof(srtp_auth_t);
|
||||
(*a)->out_len = out_len;
|
||||
(*a)->prefix_len = out_len;
|
||||
(*a)->key_len = key_len;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_auth_dealloc(srtp_auth_t *a)
|
||||
{
|
||||
extern const srtp_auth_type_t srtp_null_auth;
|
||||
|
||||
/* zeroize entire state*/
|
||||
octet_string_set_to_zero(a, sizeof(srtp_null_auth_ctx_t) +
|
||||
sizeof(srtp_auth_t));
|
||||
|
||||
/* free memory */
|
||||
srtp_crypto_free(a);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_auth_init(void *statev,
|
||||
const uint8_t *key,
|
||||
int key_len)
|
||||
{
|
||||
/* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
|
||||
/* accept any length of key, and do nothing */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_auth_compute(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets,
|
||||
int tag_len,
|
||||
uint8_t *result)
|
||||
{
|
||||
/* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_auth_update(void *statev,
|
||||
const uint8_t *message,
|
||||
int msg_octets)
|
||||
{
|
||||
/* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_status_t srtp_null_auth_start(void *statev)
|
||||
{
|
||||
/* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_auth_type_t - defines description, test case, and null_auth
|
||||
* metaobject
|
||||
*/
|
||||
|
||||
/* begin test case 0 */
|
||||
|
||||
static const srtp_auth_test_case_t srtp_null_auth_test_case_0 = {
|
||||
0, /* octets in key */
|
||||
NULL, /* key */
|
||||
0, /* octets in data */
|
||||
NULL, /* data */
|
||||
0, /* octets in tag */
|
||||
NULL, /* tag */
|
||||
NULL /* pointer to next testcase */
|
||||
};
|
||||
|
||||
/* end test case 0 */
|
||||
|
||||
static const char srtp_null_auth_description[] = "null authentication function";
|
||||
|
||||
const srtp_auth_type_t srtp_null_auth = {
|
||||
srtp_null_auth_alloc, /* */
|
||||
srtp_null_auth_dealloc, /* */
|
||||
srtp_null_auth_init, /* */
|
||||
srtp_null_auth_compute, /* */
|
||||
srtp_null_auth_update, /* */
|
||||
srtp_null_auth_start, /* */
|
||||
srtp_null_auth_description, /* */
|
||||
&srtp_null_auth_test_case_0, /* */
|
||||
SRTP_NULL_AUTH /* */
|
||||
};
|
||||
83
TMessagesProj/jni/third_party/libsrtp/crypto/include/aes.h
vendored
Normal file
83
TMessagesProj/jni/third_party/libsrtp/crypto/include/aes.h
vendored
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* aes.h
|
||||
*
|
||||
* header file for the AES block cipher
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AES_H
|
||||
#define AES_H
|
||||
|
||||
#include "datatypes.h"
|
||||
#include "err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* aes internals */
|
||||
|
||||
typedef struct {
|
||||
v128_t round[15];
|
||||
int num_rounds;
|
||||
} srtp_aes_expanded_key_t;
|
||||
|
||||
srtp_err_status_t srtp_aes_expand_encryption_key(
|
||||
const uint8_t *key,
|
||||
int key_len,
|
||||
srtp_aes_expanded_key_t *expanded_key);
|
||||
|
||||
srtp_err_status_t srtp_aes_expand_decryption_key(
|
||||
const uint8_t *key,
|
||||
int key_len,
|
||||
srtp_aes_expanded_key_t *expanded_key);
|
||||
|
||||
void srtp_aes_encrypt(v128_t *plaintext,
|
||||
const srtp_aes_expanded_key_t *exp_key);
|
||||
|
||||
void srtp_aes_decrypt(v128_t *plaintext,
|
||||
const srtp_aes_expanded_key_t *exp_key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AES_H */
|
||||
62
TMessagesProj/jni/third_party/libsrtp/crypto/include/aes_gcm_ossl.h
vendored
Normal file
62
TMessagesProj/jni/third_party/libsrtp/crypto/include/aes_gcm_ossl.h
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* aes_gcm_ossl.h
|
||||
*
|
||||
* Header for AES Galois Counter Mode.
|
||||
*
|
||||
* John A. Foley
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2013-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AES_GCM_OSSL_H
|
||||
#define AES_GCM_OSSL_H
|
||||
|
||||
#include "cipher.h"
|
||||
#include "srtp.h"
|
||||
#include "datatypes.h"
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/aes.h>
|
||||
|
||||
typedef struct {
|
||||
int key_size;
|
||||
int tag_len;
|
||||
EVP_CIPHER_CTX *ctx;
|
||||
srtp_cipher_direction_t dir;
|
||||
} srtp_aes_gcm_ctx_t;
|
||||
|
||||
#endif /* AES_GCM_OSSL_H */
|
||||
62
TMessagesProj/jni/third_party/libsrtp/crypto/include/aes_icm.h
vendored
Normal file
62
TMessagesProj/jni/third_party/libsrtp/crypto/include/aes_icm.h
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* aes_icm.h
|
||||
*
|
||||
* Header for AES Integer Counter Mode.
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AES_ICM_H
|
||||
#define AES_ICM_H
|
||||
|
||||
#include "aes.h"
|
||||
#include "cipher.h"
|
||||
|
||||
typedef struct {
|
||||
v128_t counter; /* holds the counter value */
|
||||
v128_t offset; /* initial offset value */
|
||||
v128_t keystream_buffer; /* buffers bytes of keystream */
|
||||
srtp_aes_expanded_key_t expanded_key; /* the cipher key */
|
||||
int bytes_in_buffer; /* number of unused bytes in buffer */
|
||||
int key_size; /* AES key size + 14 byte SALT */
|
||||
} srtp_aes_icm_ctx_t;
|
||||
|
||||
#endif /* AES_ICM_H */
|
||||
61
TMessagesProj/jni/third_party/libsrtp/crypto/include/aes_icm_ossl.h
vendored
Normal file
61
TMessagesProj/jni/third_party/libsrtp/crypto/include/aes_icm_ossl.h
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* aes_icm.h
|
||||
*
|
||||
* Header for AES Integer Counter Mode.
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AES_ICM_H
|
||||
#define AES_ICM_H
|
||||
|
||||
#include "cipher.h"
|
||||
#include "datatypes.h"
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/aes.h>
|
||||
|
||||
typedef struct {
|
||||
v128_t counter; /* holds the counter value */
|
||||
v128_t offset; /* initial offset value */
|
||||
int key_size;
|
||||
EVP_CIPHER_CTX *ctx;
|
||||
} srtp_aes_icm_ctx_t;
|
||||
|
||||
#endif /* AES_ICM_H */
|
||||
76
TMessagesProj/jni/third_party/libsrtp/crypto/include/alloc.h
vendored
Normal file
76
TMessagesProj/jni/third_party/libsrtp/crypto/include/alloc.h
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* alloc.h
|
||||
*
|
||||
* interface to memory allocation and deallocation, with optional debugging
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_ALLOC_H
|
||||
#define CRYPTO_ALLOC_H
|
||||
|
||||
#include "datatypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* srtp_crypto_alloc
|
||||
*
|
||||
* Allocates a block of memory of given size. The memory will be
|
||||
* initialized to zero's. Free the memory with a call to srtp_crypto_free.
|
||||
*
|
||||
* returns pointer to memory on success or else NULL
|
||||
*/
|
||||
void *srtp_crypto_alloc(size_t size);
|
||||
|
||||
/*
|
||||
* srtp_crypto_free
|
||||
*
|
||||
* Frees the block of memory ptr previously allocated with
|
||||
* srtp_crypto_alloc
|
||||
*/
|
||||
void srtp_crypto_free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CRYPTO_ALLOC_H */
|
||||
173
TMessagesProj/jni/third_party/libsrtp/crypto/include/auth.h
vendored
Normal file
173
TMessagesProj/jni/third_party/libsrtp/crypto/include/auth.h
vendored
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* auth.h
|
||||
*
|
||||
* common interface to authentication functions
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRTP_AUTH_H
|
||||
#define SRTP_AUTH_H
|
||||
|
||||
#include "srtp.h"
|
||||
#include "crypto_types.h" /* for values of auth_type_id_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef const struct srtp_auth_type_t *srtp_auth_type_pointer;
|
||||
typedef struct srtp_auth_t *srtp_auth_pointer_t;
|
||||
|
||||
typedef srtp_err_status_t (*srtp_auth_alloc_func)(srtp_auth_pointer_t *ap,
|
||||
int key_len,
|
||||
int out_len);
|
||||
|
||||
typedef srtp_err_status_t (*srtp_auth_init_func)(void *state,
|
||||
const uint8_t *key,
|
||||
int key_len);
|
||||
|
||||
typedef srtp_err_status_t (*srtp_auth_dealloc_func)(srtp_auth_pointer_t ap);
|
||||
|
||||
typedef srtp_err_status_t (*srtp_auth_compute_func)(void *state,
|
||||
const uint8_t *buffer,
|
||||
int octets_to_auth,
|
||||
int tag_len,
|
||||
uint8_t *tag);
|
||||
|
||||
typedef srtp_err_status_t (*srtp_auth_update_func)(void *state,
|
||||
const uint8_t *buffer,
|
||||
int octets_to_auth);
|
||||
|
||||
typedef srtp_err_status_t (*srtp_auth_start_func)(void *state);
|
||||
|
||||
/* some syntactic sugar on these function types */
|
||||
#define srtp_auth_type_alloc(at, a, klen, outlen) \
|
||||
((at)->alloc((a), (klen), (outlen)))
|
||||
|
||||
#define srtp_auth_init(a, key) \
|
||||
(((a)->type)->init((a)->state, (key), ((a)->key_len)))
|
||||
|
||||
#define srtp_auth_compute(a, buf, len, res) \
|
||||
(((a)->type)->compute((a)->state, (buf), (len), (a)->out_len, (res)))
|
||||
|
||||
#define srtp_auth_update(a, buf, len) \
|
||||
(((a)->type)->update((a)->state, (buf), (len)))
|
||||
|
||||
#define srtp_auth_start(a) (((a)->type)->start((a)->state))
|
||||
|
||||
#define srtp_auth_dealloc(c) (((c)->type)->dealloc(c))
|
||||
|
||||
/* functions to get information about a particular auth_t */
|
||||
int srtp_auth_get_key_length(const struct srtp_auth_t *a);
|
||||
|
||||
int srtp_auth_get_tag_length(const struct srtp_auth_t *a);
|
||||
|
||||
int srtp_auth_get_prefix_length(const struct srtp_auth_t *a);
|
||||
|
||||
/*
|
||||
* srtp_auth_test_case_t is a (list of) key/message/tag values that are
|
||||
* known to be correct for a particular cipher. this data can be used
|
||||
* to test an implementation in an on-the-fly self test of the
|
||||
* correctness of the implementation. (see the srtp_auth_type_self_test()
|
||||
* function below)
|
||||
*/
|
||||
typedef struct srtp_auth_test_case_t {
|
||||
int key_length_octets; /* octets in key */
|
||||
const uint8_t *key; /* key */
|
||||
int data_length_octets; /* octets in data */
|
||||
const uint8_t *data; /* data */
|
||||
int tag_length_octets; /* octets in tag */
|
||||
const uint8_t *tag; /* tag */
|
||||
const struct srtp_auth_test_case_t
|
||||
*next_test_case; /* pointer to next testcase */
|
||||
} srtp_auth_test_case_t;
|
||||
|
||||
/* srtp_auth_type_t */
|
||||
typedef struct srtp_auth_type_t {
|
||||
srtp_auth_alloc_func alloc;
|
||||
srtp_auth_dealloc_func dealloc;
|
||||
srtp_auth_init_func init;
|
||||
srtp_auth_compute_func compute;
|
||||
srtp_auth_update_func update;
|
||||
srtp_auth_start_func start;
|
||||
const char *description;
|
||||
const srtp_auth_test_case_t *test_data;
|
||||
srtp_auth_type_id_t id;
|
||||
} srtp_auth_type_t;
|
||||
|
||||
typedef struct srtp_auth_t {
|
||||
const srtp_auth_type_t *type;
|
||||
void *state;
|
||||
int out_len; /* length of output tag in octets */
|
||||
int key_len; /* length of key in octets */
|
||||
int prefix_len; /* length of keystream prefix */
|
||||
} srtp_auth_t;
|
||||
|
||||
/*
|
||||
* srtp_auth_type_self_test() tests an auth_type against test cases
|
||||
* provided in an array of values of key/message/tag that is known to
|
||||
* be good
|
||||
*/
|
||||
srtp_err_status_t srtp_auth_type_self_test(const srtp_auth_type_t *at);
|
||||
|
||||
/*
|
||||
* srtp_auth_type_test() tests an auth_type against external test cases
|
||||
* provided in an array of values of key/message/tag that is known to
|
||||
* be good
|
||||
*/
|
||||
srtp_err_status_t srtp_auth_type_test(const srtp_auth_type_t *at,
|
||||
const srtp_auth_test_case_t *test_data);
|
||||
|
||||
/*
|
||||
* srtp_replace_auth_type(ct, id)
|
||||
*
|
||||
* replaces srtp's kernel's auth type implementation for the auth_type id
|
||||
* with a new one passed in externally. The new auth type must pass all the
|
||||
* existing auth_type's self tests as well as its own.
|
||||
*/
|
||||
srtp_err_status_t srtp_replace_auth_type(const srtp_auth_type_t *ct,
|
||||
srtp_auth_type_id_t id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SRTP_AUTH_H */
|
||||
248
TMessagesProj/jni/third_party/libsrtp/crypto/include/cipher.h
vendored
Normal file
248
TMessagesProj/jni/third_party/libsrtp/crypto/include/cipher.h
vendored
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
/*
|
||||
* cipher.h
|
||||
*
|
||||
* common interface to ciphers
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRTP_CIPHER_H
|
||||
#define SRTP_CIPHER_H
|
||||
|
||||
#include "srtp.h"
|
||||
#include "crypto_types.h" /* for values of cipher_type_id_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* srtp_cipher_direction_t defines a particular cipher operation.
|
||||
*
|
||||
* A srtp_cipher_direction_t is an enum that describes a particular cipher
|
||||
* operation, i.e. encryption or decryption. For some ciphers, this
|
||||
* distinction does not matter, but for others, it is essential.
|
||||
*/
|
||||
typedef enum {
|
||||
srtp_direction_encrypt, /**< encryption (convert plaintext to ciphertext) */
|
||||
srtp_direction_decrypt, /**< decryption (convert ciphertext to plaintext) */
|
||||
srtp_direction_any /**< encryption or decryption */
|
||||
} srtp_cipher_direction_t;
|
||||
|
||||
/*
|
||||
* the srtp_cipher_pointer_t definition is needed
|
||||
* as srtp_cipher_t is not yet defined
|
||||
*/
|
||||
typedef struct srtp_cipher_t *srtp_cipher_pointer_t;
|
||||
|
||||
/*
|
||||
* a srtp_cipher_alloc_func_t allocates (but does not initialize) a
|
||||
* srtp_cipher_t
|
||||
*/
|
||||
typedef srtp_err_status_t (*srtp_cipher_alloc_func_t)(srtp_cipher_pointer_t *cp,
|
||||
int key_len,
|
||||
int tag_len);
|
||||
|
||||
/*
|
||||
* a srtp_cipher_init_func_t [re-]initializes a cipher_t with a given key
|
||||
*/
|
||||
typedef srtp_err_status_t (*srtp_cipher_init_func_t)(void *state,
|
||||
const uint8_t *key);
|
||||
|
||||
/* a srtp_cipher_dealloc_func_t de-allocates a cipher_t */
|
||||
typedef srtp_err_status_t (*srtp_cipher_dealloc_func_t)(
|
||||
srtp_cipher_pointer_t cp);
|
||||
|
||||
/*
|
||||
* a srtp_cipher_set_aad_func_t processes the AAD data for AEAD ciphers
|
||||
*/
|
||||
typedef srtp_err_status_t (*srtp_cipher_set_aad_func_t)(void *state,
|
||||
const uint8_t *aad,
|
||||
uint32_t aad_len);
|
||||
|
||||
/* a srtp_cipher_encrypt_func_t encrypts data in-place */
|
||||
typedef srtp_err_status_t (*srtp_cipher_encrypt_func_t)(
|
||||
void *state,
|
||||
uint8_t *buffer,
|
||||
unsigned int *octets_to_encrypt);
|
||||
|
||||
/* a srtp_cipher_decrypt_func_t decrypts data in-place */
|
||||
typedef srtp_err_status_t (*srtp_cipher_decrypt_func_t)(
|
||||
void *state,
|
||||
uint8_t *buffer,
|
||||
unsigned int *octets_to_decrypt);
|
||||
|
||||
/*
|
||||
* a srtp_cipher_set_iv_func_t function sets the current initialization vector
|
||||
*/
|
||||
typedef srtp_err_status_t (*srtp_cipher_set_iv_func_t)(
|
||||
void *state,
|
||||
uint8_t *iv,
|
||||
srtp_cipher_direction_t direction);
|
||||
|
||||
/*
|
||||
* a cipher_get_tag_func_t function is used to get the authentication
|
||||
* tag that was calculated by an AEAD cipher.
|
||||
*/
|
||||
typedef srtp_err_status_t (*srtp_cipher_get_tag_func_t)(void *state,
|
||||
uint8_t *tag,
|
||||
uint32_t *len);
|
||||
|
||||
/*
|
||||
* srtp_cipher_test_case_t is a (list of) key, salt, plaintext, ciphertext,
|
||||
* and aad values that are known to be correct for a
|
||||
* particular cipher. this data can be used to test an implementation
|
||||
* in an on-the-fly self test of the correctness of the implementation.
|
||||
* (see the srtp_cipher_type_self_test() function below)
|
||||
*/
|
||||
typedef struct srtp_cipher_test_case_t {
|
||||
int key_length_octets; /* octets in key */
|
||||
const uint8_t *key; /* key */
|
||||
uint8_t *idx; /* packet index */
|
||||
unsigned int plaintext_length_octets; /* octets in plaintext */
|
||||
const uint8_t *plaintext; /* plaintext */
|
||||
unsigned int ciphertext_length_octets; /* octets in plaintext */
|
||||
const uint8_t *ciphertext; /* ciphertext */
|
||||
int aad_length_octets; /* octets in AAD */
|
||||
const uint8_t *aad; /* AAD */
|
||||
int tag_length_octets; /* Length of AEAD tag */
|
||||
const struct srtp_cipher_test_case_t
|
||||
*next_test_case; /* pointer to next testcase */
|
||||
} srtp_cipher_test_case_t;
|
||||
|
||||
/* srtp_cipher_type_t defines the 'metadata' for a particular cipher type */
|
||||
typedef struct srtp_cipher_type_t {
|
||||
srtp_cipher_alloc_func_t alloc;
|
||||
srtp_cipher_dealloc_func_t dealloc;
|
||||
srtp_cipher_init_func_t init;
|
||||
srtp_cipher_set_aad_func_t set_aad;
|
||||
srtp_cipher_encrypt_func_t encrypt;
|
||||
srtp_cipher_encrypt_func_t decrypt;
|
||||
srtp_cipher_set_iv_func_t set_iv;
|
||||
srtp_cipher_get_tag_func_t get_tag;
|
||||
const char *description;
|
||||
const srtp_cipher_test_case_t *test_data;
|
||||
srtp_cipher_type_id_t id;
|
||||
} srtp_cipher_type_t;
|
||||
|
||||
/*
|
||||
* srtp_cipher_t defines an instantiation of a particular cipher, with fixed
|
||||
* key length, key and salt values
|
||||
*/
|
||||
typedef struct srtp_cipher_t {
|
||||
const srtp_cipher_type_t *type;
|
||||
void *state;
|
||||
int key_len;
|
||||
int algorithm;
|
||||
} srtp_cipher_t;
|
||||
|
||||
/* some bookkeeping functions */
|
||||
int srtp_cipher_get_key_length(const srtp_cipher_t *c);
|
||||
|
||||
/*
|
||||
* srtp_cipher_type_self_test() tests a cipher against test cases provided in
|
||||
* an array of values of key/srtp_xtd_seq_num_t/plaintext/ciphertext
|
||||
* that is known to be good
|
||||
*/
|
||||
srtp_err_status_t srtp_cipher_type_self_test(const srtp_cipher_type_t *ct);
|
||||
|
||||
/*
|
||||
* srtp_cipher_type_test() tests a cipher against external test cases provided
|
||||
* in
|
||||
* an array of values of key/srtp_xtd_seq_num_t/plaintext/ciphertext
|
||||
* that is known to be good
|
||||
*/
|
||||
srtp_err_status_t srtp_cipher_type_test(
|
||||
const srtp_cipher_type_t *ct,
|
||||
const srtp_cipher_test_case_t *test_data);
|
||||
|
||||
/*
|
||||
* srtp_cipher_bits_per_second(c, l, t) computes (an estimate of) the
|
||||
* number of bits that a cipher implementation can encrypt in a second
|
||||
*
|
||||
* c is a cipher (which MUST be allocated and initialized already), l
|
||||
* is the length in octets of the test data to be encrypted, and t is
|
||||
* the number of trials
|
||||
*
|
||||
* if an error is encountered, then the value 0 is returned
|
||||
*/
|
||||
uint64_t srtp_cipher_bits_per_second(srtp_cipher_t *c,
|
||||
int octets_in_buffer,
|
||||
int num_trials);
|
||||
|
||||
srtp_err_status_t srtp_cipher_type_alloc(const srtp_cipher_type_t *ct,
|
||||
srtp_cipher_t **c,
|
||||
int key_len,
|
||||
int tlen);
|
||||
srtp_err_status_t srtp_cipher_dealloc(srtp_cipher_t *c);
|
||||
srtp_err_status_t srtp_cipher_init(srtp_cipher_t *c, const uint8_t *key);
|
||||
srtp_err_status_t srtp_cipher_set_iv(srtp_cipher_t *c,
|
||||
uint8_t *iv,
|
||||
int direction);
|
||||
srtp_err_status_t srtp_cipher_output(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *num_octets_to_output);
|
||||
srtp_err_status_t srtp_cipher_encrypt(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *num_octets_to_output);
|
||||
srtp_err_status_t srtp_cipher_decrypt(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *num_octets_to_output);
|
||||
srtp_err_status_t srtp_cipher_get_tag(srtp_cipher_t *c,
|
||||
uint8_t *buffer,
|
||||
uint32_t *tag_len);
|
||||
srtp_err_status_t srtp_cipher_set_aad(srtp_cipher_t *c,
|
||||
const uint8_t *aad,
|
||||
uint32_t aad_len);
|
||||
|
||||
/*
|
||||
* srtp_replace_cipher_type(ct, id)
|
||||
*
|
||||
* replaces srtp's existing cipher implementation for the cipher_type id
|
||||
* with a new one passed in externally. The new cipher must pass all the
|
||||
* existing cipher_type's self tests as well as its own.
|
||||
*/
|
||||
srtp_err_status_t srtp_replace_cipher_type(const srtp_cipher_type_t *ct,
|
||||
srtp_cipher_type_id_t id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SRTP_CIPHER_H */
|
||||
81
TMessagesProj/jni/third_party/libsrtp/crypto/include/cipher_types.h
vendored
Normal file
81
TMessagesProj/jni/third_party/libsrtp/crypto/include/cipher_types.h
vendored
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CIHPER_TYPES_H
|
||||
#define CIHPER_TYPES_H
|
||||
|
||||
#include "cipher.h"
|
||||
#include "auth.h"
|
||||
|
||||
/*
|
||||
* cipher types that can be included in the kernel
|
||||
*/
|
||||
|
||||
extern const srtp_cipher_type_t srtp_null_cipher;
|
||||
extern const srtp_cipher_type_t srtp_aes_icm_128;
|
||||
extern const srtp_cipher_type_t srtp_aes_icm_256;
|
||||
#ifdef OPENSSL
|
||||
extern const srtp_cipher_type_t srtp_aes_icm_192;
|
||||
extern const srtp_cipher_type_t srtp_aes_gcm_128_openssl;
|
||||
extern const srtp_cipher_type_t srtp_aes_gcm_256_openssl;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* auth func types that can be included in the kernel
|
||||
*/
|
||||
|
||||
extern const srtp_auth_type_t srtp_null_auth;
|
||||
extern const srtp_auth_type_t srtp_hmac;
|
||||
|
||||
/*
|
||||
* other generic debug modules that can be included in the kernel
|
||||
*/
|
||||
|
||||
extern srtp_debug_module_t srtp_mod_auth;
|
||||
extern srtp_debug_module_t srtp_mod_cipher;
|
||||
extern srtp_debug_module_t srtp_mod_stat;
|
||||
extern srtp_debug_module_t srtp_mod_alloc;
|
||||
|
||||
/* debug modules for cipher types */
|
||||
extern srtp_debug_module_t srtp_mod_aes_icm;
|
||||
#ifdef OPENSSL
|
||||
extern srtp_debug_module_t srtp_mod_aes_gcm;
|
||||
#endif
|
||||
|
||||
/* debug modules for auth types */
|
||||
extern srtp_debug_module_t srtp_mod_hmac;
|
||||
|
||||
#endif
|
||||
30
TMessagesProj/jni/third_party/libsrtp/crypto/include/config.h
vendored
Normal file
30
TMessagesProj/jni/third_party/libsrtp/crypto/include/config.h
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2016 The Chromium Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This space intentionally left blank.
|
||||
*
|
||||
* All of the #defines have been moved to BUILD.gn. The libsrtp headers
|
||||
* equate "building as a library" with HAS_CONFIG_H, so we need to leave that
|
||||
* defined and this file needs to be here.
|
||||
*/
|
||||
|
||||
#define HAVE_CONFIG_H
|
||||
#define OPENSSL
|
||||
#define HAVE_STDLIB_H
|
||||
#define HAVE_STRING_H
|
||||
#define HAVE_STDINT_H
|
||||
#define HAVE_INTTYPES_H
|
||||
#define HAVE_INT16_T
|
||||
#define HAVE_INT32_T
|
||||
#define HAVE_INT8_T
|
||||
#define HAVE_UINT16_T
|
||||
#define HAVE_UINT32_T
|
||||
#define HAVE_UINT64_T
|
||||
#define HAVE_UINT8_T
|
||||
#define HAVE_ARPA_INET_H
|
||||
#define HAVE_SYS_TYPES_H
|
||||
#define HAVE_UNISTD_H
|
||||
215
TMessagesProj/jni/third_party/libsrtp/crypto/include/crypto_kernel.h
vendored
Normal file
215
TMessagesProj/jni/third_party/libsrtp/crypto/include/crypto_kernel.h
vendored
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
/*
|
||||
* crypto_kernel.h
|
||||
*
|
||||
* header for the cryptographic kernel
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CRYPTO_KERNEL
|
||||
#define CRYPTO_KERNEL
|
||||
|
||||
#include "cipher.h"
|
||||
#include "auth.h"
|
||||
#include "err.h"
|
||||
#include "crypto_types.h"
|
||||
#include "key.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* crypto_kernel_state_t defines the possible states:
|
||||
*
|
||||
* insecure - not yet initialized
|
||||
* secure - initialized and passed self-tests
|
||||
*/
|
||||
typedef enum {
|
||||
srtp_crypto_kernel_state_insecure,
|
||||
srtp_crypto_kernel_state_secure
|
||||
} srtp_crypto_kernel_state_t;
|
||||
|
||||
/*
|
||||
* linked list of cipher types
|
||||
*/
|
||||
typedef struct srtp_kernel_cipher_type {
|
||||
srtp_cipher_type_id_t id;
|
||||
const srtp_cipher_type_t *cipher_type;
|
||||
struct srtp_kernel_cipher_type *next;
|
||||
} srtp_kernel_cipher_type_t;
|
||||
|
||||
/*
|
||||
* linked list of auth types
|
||||
*/
|
||||
typedef struct srtp_kernel_auth_type {
|
||||
srtp_auth_type_id_t id;
|
||||
const srtp_auth_type_t *auth_type;
|
||||
struct srtp_kernel_auth_type *next;
|
||||
} srtp_kernel_auth_type_t;
|
||||
|
||||
/*
|
||||
* linked list of debug modules
|
||||
*/
|
||||
typedef struct srtp_kernel_debug_module {
|
||||
srtp_debug_module_t *mod;
|
||||
struct srtp_kernel_debug_module *next;
|
||||
} srtp_kernel_debug_module_t;
|
||||
|
||||
/*
|
||||
* crypto_kernel_t is the data structure for the crypto kernel
|
||||
*
|
||||
* note that there is *exactly one* instance of this data type,
|
||||
* a global variable defined in crypto_kernel.c
|
||||
*/
|
||||
typedef struct {
|
||||
srtp_crypto_kernel_state_t state; /* current state of kernel */
|
||||
srtp_kernel_cipher_type_t *cipher_type_list; /* list of all cipher types */
|
||||
srtp_kernel_auth_type_t *auth_type_list; /* list of all auth func types */
|
||||
srtp_kernel_debug_module_t
|
||||
*debug_module_list; /* list of all debug modules */
|
||||
} srtp_crypto_kernel_t;
|
||||
|
||||
/*
|
||||
* srtp_crypto_kernel_t external api
|
||||
*/
|
||||
|
||||
/*
|
||||
* The function srtp_crypto_kernel_init() initialized the crypto kernel and
|
||||
* runs the self-test operations on the random number generators and
|
||||
* crypto algorithms. Possible return values are:
|
||||
*
|
||||
* srtp_err_status_ok initialization successful
|
||||
* <other> init failure
|
||||
*
|
||||
* If any value other than srtp_err_status_ok is returned, the
|
||||
* crypto_kernel MUST NOT be used.
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_init(void);
|
||||
|
||||
/*
|
||||
* The function srtp_crypto_kernel_shutdown() de-initializes the
|
||||
* crypto_kernel, zeroizes keys and other cryptographic material, and
|
||||
* deallocates any dynamically allocated memory. Possible return
|
||||
* values are:
|
||||
*
|
||||
* srtp_err_status_ok shutdown successful
|
||||
* <other> shutdown failure
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_shutdown(void);
|
||||
|
||||
/*
|
||||
* The function srtp_crypto_kernel_stats() checks the the crypto_kernel,
|
||||
* running tests on the ciphers, auth funcs, and rng, and prints out a
|
||||
* status report. Possible return values are:
|
||||
*
|
||||
* srtp_err_status_ok all tests were passed
|
||||
* <other> a test failed
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_status(void);
|
||||
|
||||
/*
|
||||
* srtp_crypto_kernel_list_debug_modules() outputs a list of debugging modules
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_list_debug_modules(void);
|
||||
|
||||
/*
|
||||
* srtp_crypto_kernel_load_cipher_type()
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_load_cipher_type(
|
||||
const srtp_cipher_type_t *ct,
|
||||
srtp_cipher_type_id_t id);
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_load_auth_type(const srtp_auth_type_t *ct,
|
||||
srtp_auth_type_id_t id);
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_load_debug_module(
|
||||
srtp_debug_module_t *new_dm);
|
||||
|
||||
/*
|
||||
* srtp_crypto_kernel_alloc_cipher(id, cp, key_len);
|
||||
*
|
||||
* allocates a cipher of type id at location *cp, with key length
|
||||
* key_len octets. Return values are:
|
||||
*
|
||||
* srtp_err_status_ok no problems
|
||||
* srtp_err_status_alloc_fail an allocation failure occured
|
||||
* srtp_err_status_fail couldn't find cipher with identifier 'id'
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_alloc_cipher(srtp_cipher_type_id_t id,
|
||||
srtp_cipher_pointer_t *cp,
|
||||
int key_len,
|
||||
int tag_len);
|
||||
|
||||
/*
|
||||
* srtp_crypto_kernel_alloc_auth(id, ap, key_len, tag_len);
|
||||
*
|
||||
* allocates an auth function of type id at location *ap, with key
|
||||
* length key_len octets and output tag length of tag_len. Return
|
||||
* values are:
|
||||
*
|
||||
* srtp_err_status_ok no problems
|
||||
* srtp_err_status_alloc_fail an allocation failure occured
|
||||
* srtp_err_status_fail couldn't find auth with identifier 'id'
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_alloc_auth(srtp_auth_type_id_t id,
|
||||
srtp_auth_pointer_t *ap,
|
||||
int key_len,
|
||||
int tag_len);
|
||||
|
||||
/*
|
||||
* srtp_crypto_kernel_set_debug_module(mod_name, v)
|
||||
*
|
||||
* sets dynamic debugging to the value v (0 for off, 1 for on) for the
|
||||
* debug module with the name mod_name
|
||||
*
|
||||
* returns srtp_err_status_ok on success, srtp_err_status_fail otherwise
|
||||
*/
|
||||
srtp_err_status_t srtp_crypto_kernel_set_debug_module(const char *mod_name,
|
||||
int v);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CRYPTO_KERNEL */
|
||||
116
TMessagesProj/jni/third_party/libsrtp/crypto/include/crypto_types.h
vendored
Normal file
116
TMessagesProj/jni/third_party/libsrtp/crypto/include/crypto_types.h
vendored
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* crypto_types.h
|
||||
*
|
||||
* constants for cipher types and auth func types
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRTP_CRYPTO_TYPES_H
|
||||
#define SRTP_CRYPTO_TYPES_H
|
||||
|
||||
/*
|
||||
* The null cipher performs no encryption.
|
||||
*
|
||||
* The SRTP_NULL_CIPHER leaves its inputs unaltered, during both the
|
||||
* encryption and decryption operations. This cipher can be chosen
|
||||
* to indicate that no encryption is to be performed.
|
||||
*/
|
||||
#define SRTP_NULL_CIPHER 0
|
||||
|
||||
/*
|
||||
* AES-128 Integer Counter Mode (AES ICM)
|
||||
*
|
||||
* AES-128 ICM is the variant of counter mode that is used by
|
||||
* Secure RTP. This cipher uses a 16-octet key concatenated with a
|
||||
* 14-octet offset (or salt) value.
|
||||
*/
|
||||
#define SRTP_AES_ICM_128 1
|
||||
|
||||
/*
|
||||
* AES-192 Integer Counter Mode (AES ICM)
|
||||
*
|
||||
* AES-128 ICM is the variant of counter mode that is used by
|
||||
* Secure RTP. This cipher uses a 24-octet key concatenated with a
|
||||
* 14-octet offset (or salt) value.
|
||||
*/
|
||||
#define SRTP_AES_ICM_192 4
|
||||
|
||||
/*
|
||||
* AES-256 Integer Counter Mode (AES ICM)
|
||||
*
|
||||
* AES-128 ICM is the variant of counter mode that is used by
|
||||
* Secure RTP. This cipher uses a 32-octet key concatenated with a
|
||||
* 14-octet offset (or salt) value.
|
||||
*/
|
||||
#define SRTP_AES_ICM_256 5
|
||||
|
||||
/*
|
||||
* AES-128_GCM Galois Counter Mode (AES GCM)
|
||||
*
|
||||
* AES-128 GCM is the variant of galois counter mode that is used by
|
||||
* Secure RTP. This cipher uses a 16-octet key.
|
||||
*/
|
||||
#define SRTP_AES_GCM_128 6
|
||||
|
||||
/*
|
||||
* AES-256_GCM Galois Counter Mode (AES GCM)
|
||||
*
|
||||
* AES-256 GCM is the variant of galois counter mode that is used by
|
||||
* Secure RTP. This cipher uses a 32-octet key.
|
||||
*/
|
||||
#define SRTP_AES_GCM_256 7
|
||||
|
||||
/*
|
||||
* The null authentication function performs no authentication.
|
||||
*
|
||||
* The NULL_AUTH function does nothing, and can be selected to indicate
|
||||
* that authentication should not be performed.
|
||||
*/
|
||||
#define SRTP_NULL_AUTH 0
|
||||
|
||||
/*
|
||||
* HMAC-SHA1
|
||||
*
|
||||
* SRTP_HMAC_SHA1 implements the Hash-based MAC using the NIST Secure
|
||||
* Hash Algorithm version 1 (SHA1).
|
||||
*/
|
||||
#define SRTP_HMAC_SHA1 3
|
||||
|
||||
#endif /* SRTP_CRYPTO_TYPES_H */
|
||||
379
TMessagesProj/jni/third_party/libsrtp/crypto/include/datatypes.h
vendored
Normal file
379
TMessagesProj/jni/third_party/libsrtp/crypto/include/datatypes.h
vendored
Normal file
|
|
@ -0,0 +1,379 @@
|
|||
/*
|
||||
* datatypes.h
|
||||
*
|
||||
* data types for bit vectors and finite fields
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DATATYPES_H
|
||||
#define DATATYPES_H
|
||||
|
||||
#include "integers.h" /* definitions of uint32_t, et cetera */
|
||||
#include "alloc.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#elif defined HAVE_WINSOCK2_H
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#error "Platform not recognized"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* if DATATYPES_USE_MACROS is defined, then little functions are macros */
|
||||
#define DATATYPES_USE_MACROS
|
||||
|
||||
typedef union {
|
||||
uint8_t v8[2];
|
||||
uint16_t value;
|
||||
} v16_t;
|
||||
|
||||
typedef union {
|
||||
uint8_t v8[4];
|
||||
uint16_t v16[2];
|
||||
uint32_t value;
|
||||
} v32_t;
|
||||
|
||||
typedef union {
|
||||
uint8_t v8[8];
|
||||
uint16_t v16[4];
|
||||
uint32_t v32[2];
|
||||
uint64_t value;
|
||||
} v64_t;
|
||||
|
||||
typedef union {
|
||||
uint8_t v8[16];
|
||||
uint16_t v16[8];
|
||||
uint32_t v32[4];
|
||||
uint64_t v64[2];
|
||||
} v128_t;
|
||||
|
||||
typedef union {
|
||||
uint8_t v8[32];
|
||||
uint16_t v16[16];
|
||||
uint32_t v32[8];
|
||||
uint64_t v64[4];
|
||||
} v256_t;
|
||||
|
||||
/* some useful and simple math functions */
|
||||
|
||||
#define pow_2(X) ((unsigned int)1 << (X)) /* 2^X */
|
||||
|
||||
#define pow_minus_one(X) ((X) ? -1 : 1) /* (-1)^X */
|
||||
|
||||
/*
|
||||
* octet_get_weight(x) returns the hamming weight (number of bits equal to
|
||||
* one) in the octet x
|
||||
*/
|
||||
|
||||
int octet_get_weight(uint8_t octet);
|
||||
|
||||
#define MAX_PRINT_STRING_LEN 1024
|
||||
|
||||
char *srtp_octet_string_hex_string(const void *str, int length);
|
||||
|
||||
char *v128_bit_string(v128_t *x);
|
||||
|
||||
char *v128_hex_string(v128_t *x);
|
||||
|
||||
void v128_copy_octet_string(v128_t *x, const uint8_t s[16]);
|
||||
|
||||
void v128_left_shift(v128_t *x, int shift_index);
|
||||
|
||||
void v128_right_shift(v128_t *x, int shift_index);
|
||||
|
||||
/*
|
||||
* the following macros define the data manipulation functions
|
||||
*
|
||||
* If DATATYPES_USE_MACROS is defined, then these macros are used
|
||||
* directly (and function call overhead is avoided). Otherwise,
|
||||
* the macros are used through the functions defined in datatypes.c
|
||||
* (and the compiler provides better warnings).
|
||||
*/
|
||||
|
||||
#define _v128_set_to_zero(x) \
|
||||
((x)->v32[0] = 0, (x)->v32[1] = 0, (x)->v32[2] = 0, (x)->v32[3] = 0)
|
||||
|
||||
#define _v128_copy(x, y) \
|
||||
((x)->v32[0] = (y)->v32[0], (x)->v32[1] = (y)->v32[1], \
|
||||
(x)->v32[2] = (y)->v32[2], (x)->v32[3] = (y)->v32[3])
|
||||
|
||||
#define _v128_xor(z, x, y) \
|
||||
((z)->v32[0] = (x)->v32[0] ^ (y)->v32[0], \
|
||||
(z)->v32[1] = (x)->v32[1] ^ (y)->v32[1], \
|
||||
(z)->v32[2] = (x)->v32[2] ^ (y)->v32[2], \
|
||||
(z)->v32[3] = (x)->v32[3] ^ (y)->v32[3])
|
||||
|
||||
#define _v128_and(z, x, y) \
|
||||
((z)->v32[0] = (x)->v32[0] & (y)->v32[0], \
|
||||
(z)->v32[1] = (x)->v32[1] & (y)->v32[1], \
|
||||
(z)->v32[2] = (x)->v32[2] & (y)->v32[2], \
|
||||
(z)->v32[3] = (x)->v32[3] & (y)->v32[3])
|
||||
|
||||
#define _v128_or(z, x, y) \
|
||||
((z)->v32[0] = (x)->v32[0] | (y)->v32[0], \
|
||||
(z)->v32[1] = (x)->v32[1] | (y)->v32[1], \
|
||||
(z)->v32[2] = (x)->v32[2] | (y)->v32[2], \
|
||||
(z)->v32[3] = (x)->v32[3] | (y)->v32[3])
|
||||
|
||||
#define _v128_complement(x) \
|
||||
((x)->v32[0] = ~(x)->v32[0], (x)->v32[1] = ~(x)->v32[1], \
|
||||
(x)->v32[2] = ~(x)->v32[2], (x)->v32[3] = ~(x)->v32[3])
|
||||
|
||||
/* ok for NO_64BIT_MATH if it can compare uint64_t's (even as structures) */
|
||||
#define _v128_is_eq(x, y) \
|
||||
(((x)->v64[0] == (y)->v64[0]) && ((x)->v64[1] == (y)->v64[1]))
|
||||
|
||||
#ifdef NO_64BIT_MATH
|
||||
#define _v128_xor_eq(z, x) \
|
||||
((z)->v32[0] ^= (x)->v32[0], (z)->v32[1] ^= (x)->v32[1], \
|
||||
(z)->v32[2] ^= (x)->v32[2], (z)->v32[3] ^= (x)->v32[3])
|
||||
#else
|
||||
#define _v128_xor_eq(z, x) \
|
||||
((z)->v64[0] ^= (x)->v64[0], (z)->v64[1] ^= (x)->v64[1])
|
||||
#endif
|
||||
|
||||
/* NOTE! This assumes an odd ordering! */
|
||||
/* This will not be compatible directly with math on some processors */
|
||||
/* bit 0 is first 32-bit word, low order bit. in little-endian, that's
|
||||
the first byte of the first 32-bit word. In big-endian, that's
|
||||
the 3rd byte of the first 32-bit word */
|
||||
/* The get/set bit code is used by the replay code ONLY, and it doesn't
|
||||
really care which bit is which. AES does care which bit is which, but
|
||||
doesn't use the 128-bit get/set or 128-bit shifts */
|
||||
|
||||
#define _v128_get_bit(x, bit) (((((x)->v32[(bit) >> 5]) >> ((bit)&31)) & 1))
|
||||
|
||||
#define _v128_set_bit(x, bit) \
|
||||
((((x)->v32[(bit) >> 5]) |= ((uint32_t)1 << ((bit)&31))))
|
||||
|
||||
#define _v128_clear_bit(x, bit) \
|
||||
((((x)->v32[(bit) >> 5]) &= ~((uint32_t)1 << ((bit)&31))))
|
||||
|
||||
#define _v128_set_bit_to(x, bit, value) \
|
||||
((value) ? _v128_set_bit(x, bit) : _v128_clear_bit(x, bit))
|
||||
|
||||
#ifdef DATATYPES_USE_MACROS /* little functions are really macros */
|
||||
|
||||
#define v128_set_to_zero(z) _v128_set_to_zero(z)
|
||||
#define v128_copy(z, x) _v128_copy(z, x)
|
||||
#define v128_xor(z, x, y) _v128_xor(z, x, y)
|
||||
#define v128_and(z, x, y) _v128_and(z, x, y)
|
||||
#define v128_or(z, x, y) _v128_or(z, x, y)
|
||||
#define v128_complement(x) _v128_complement(x)
|
||||
#define v128_is_eq(x, y) _v128_is_eq(x, y)
|
||||
#define v128_xor_eq(x, y) _v128_xor_eq(x, y)
|
||||
#define v128_get_bit(x, i) _v128_get_bit(x, i)
|
||||
#define v128_set_bit(x, i) _v128_set_bit(x, i)
|
||||
#define v128_clear_bit(x, i) _v128_clear_bit(x, i)
|
||||
#define v128_set_bit_to(x, i, y) _v128_set_bit_to(x, i, y)
|
||||
|
||||
#else
|
||||
|
||||
void v128_set_to_zero(v128_t *x);
|
||||
|
||||
int v128_is_eq(const v128_t *x, const v128_t *y);
|
||||
|
||||
void v128_copy(v128_t *x, const v128_t *y);
|
||||
|
||||
void v128_xor(v128_t *z, v128_t *x, v128_t *y);
|
||||
|
||||
void v128_and(v128_t *z, v128_t *x, v128_t *y);
|
||||
|
||||
void v128_or(v128_t *z, v128_t *x, v128_t *y);
|
||||
|
||||
void v128_complement(v128_t *x);
|
||||
|
||||
int v128_get_bit(const v128_t *x, int i);
|
||||
|
||||
void v128_set_bit(v128_t *x, int i);
|
||||
|
||||
void v128_clear_bit(v128_t *x, int i);
|
||||
|
||||
void v128_set_bit_to(v128_t *x, int i, int y);
|
||||
|
||||
#endif /* DATATYPES_USE_MACROS */
|
||||
|
||||
/*
|
||||
* octet_string_is_eq(a, b, len) returns 1 if the length len strings a
|
||||
* and b are not equal. It returns 0 otherwise. The running time of the
|
||||
* comparison depends only on len, making this safe to use for (e.g.)
|
||||
* verifying authentication tags.
|
||||
*/
|
||||
|
||||
int octet_string_is_eq(uint8_t *a, uint8_t *b, int len);
|
||||
|
||||
/*
|
||||
* A portable way to zero out memory as recommended by
|
||||
* https://cryptocoding.net/index.php/Coding_rules#Clean_memory_of_secret_data
|
||||
* This is used to zero memory when OPENSSL_cleanse() is not available.
|
||||
*/
|
||||
void srtp_cleanse(void *s, size_t len);
|
||||
|
||||
/*
|
||||
* Functions as a wrapper that delegates to either srtp_cleanse() or
|
||||
* OPENSSL_cleanse() if available to zero memory.
|
||||
*/
|
||||
void octet_string_set_to_zero(void *s, size_t len);
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
|
||||
/*
|
||||
* Convert big endian integers to CPU byte order.
|
||||
*/
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
/* Nothing to do. */
|
||||
#define be32_to_cpu(x) (x)
|
||||
#define be64_to_cpu(x) (x)
|
||||
#elif defined(HAVE_BYTESWAP_H)
|
||||
/* We have (hopefully) optimized versions in byteswap.h */
|
||||
#include <byteswap.h>
|
||||
#define be32_to_cpu(x) bswap_32((x))
|
||||
#define be64_to_cpu(x) bswap_64((x))
|
||||
#else /* WORDS_BIGENDIAN */
|
||||
|
||||
#if defined(__GNUC__) && defined(HAVE_X86)
|
||||
/* Fall back. */
|
||||
static inline uint32_t be32_to_cpu(uint32_t v)
|
||||
{
|
||||
/* optimized for x86. */
|
||||
asm("bswap %0" : "=r"(v) : "0"(v));
|
||||
return v;
|
||||
}
|
||||
#else /* HAVE_X86 */
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#elif defined HAVE_WINSOCK2_H
|
||||
#include <winsock2.h>
|
||||
#endif /* HAVE_NETINET_IN_H */
|
||||
#define be32_to_cpu(x) ntohl((x))
|
||||
#endif /* HAVE_X86 */
|
||||
|
||||
static inline uint64_t be64_to_cpu(uint64_t v)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
/* use the make64 functions to do 64-bit math */
|
||||
v = make64(htonl(low32(v)), htonl(high32(v)));
|
||||
#else /* NO_64BIT_MATH */
|
||||
/* use the native 64-bit math */
|
||||
v = (uint64_t)((be32_to_cpu((uint32_t)(v >> 32))) |
|
||||
(((uint64_t)be32_to_cpu((uint32_t)v)) << 32));
|
||||
#endif /* NO_64BIT_MATH */
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif /* WORDS_BIGENDIAN */
|
||||
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
/*
|
||||
* functions manipulating bitvector_t
|
||||
*
|
||||
* A bitvector_t consists of an array of words and an integer
|
||||
* representing the number of significant bits stored in the array.
|
||||
* The bits are packed as follows: the least significant bit is that
|
||||
* of word[0], while the most significant bit is the nth most
|
||||
* significant bit of word[m], where length = bits_per_word * m + n.
|
||||
*
|
||||
*/
|
||||
|
||||
#define bits_per_word 32
|
||||
#define bytes_per_word 4
|
||||
|
||||
typedef struct {
|
||||
uint32_t length;
|
||||
uint32_t *word;
|
||||
} bitvector_t;
|
||||
|
||||
#define _bitvector_get_bit(v, bit_index) \
|
||||
(((((v)->word[((bit_index) >> 5)]) >> ((bit_index)&31)) & 1))
|
||||
|
||||
#define _bitvector_set_bit(v, bit_index) \
|
||||
((((v)->word[((bit_index) >> 5)] |= ((uint32_t)1 << ((bit_index)&31)))))
|
||||
|
||||
#define _bitvector_clear_bit(v, bit_index) \
|
||||
((((v)->word[((bit_index) >> 5)] &= ~((uint32_t)1 << ((bit_index)&31)))))
|
||||
|
||||
#define _bitvector_get_length(v) (((v)->length))
|
||||
|
||||
#ifdef DATATYPES_USE_MACROS /* little functions are really macros */
|
||||
|
||||
#define bitvector_get_bit(v, bit_index) _bitvector_get_bit(v, bit_index)
|
||||
#define bitvector_set_bit(v, bit_index) _bitvector_set_bit(v, bit_index)
|
||||
#define bitvector_clear_bit(v, bit_index) _bitvector_clear_bit(v, bit_index)
|
||||
#define bitvector_get_length(v) _bitvector_get_length(v)
|
||||
|
||||
#else
|
||||
|
||||
int bitvector_get_bit(const bitvector_t *v, int bit_index);
|
||||
|
||||
void bitvector_set_bit(bitvector_t *v, int bit_index);
|
||||
|
||||
void bitvector_clear_bit(bitvector_t *v, int bit_index);
|
||||
|
||||
unsigned long bitvector_get_length(const bitvector_t *v);
|
||||
|
||||
#endif
|
||||
|
||||
int bitvector_alloc(bitvector_t *v, unsigned long length);
|
||||
|
||||
void bitvector_dealloc(bitvector_t *v);
|
||||
|
||||
void bitvector_set_to_zero(bitvector_t *x);
|
||||
|
||||
void bitvector_left_shift(bitvector_t *x, int index);
|
||||
|
||||
char *bitvector_bit_string(bitvector_t *x, char *buf, int len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DATATYPES_H */
|
||||
134
TMessagesProj/jni/third_party/libsrtp/crypto/include/err.h
vendored
Normal file
134
TMessagesProj/jni/third_party/libsrtp/crypto/include/err.h
vendored
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* err.h
|
||||
*
|
||||
* error status codes
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ERR_H
|
||||
#define ERR_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "srtp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @defgroup Error Error Codes
|
||||
*
|
||||
* Error status codes are represented by the enumeration srtp_err_status_t.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
srtp_err_level_error,
|
||||
srtp_err_level_warning,
|
||||
srtp_err_level_info,
|
||||
srtp_err_level_debug
|
||||
} srtp_err_reporting_level_t;
|
||||
|
||||
/*
|
||||
* err_reporting_init prepares the error system. If
|
||||
* ERR_REPORTING_STDOUT is defined, it will log to stdout.
|
||||
*
|
||||
*/
|
||||
|
||||
srtp_err_status_t srtp_err_reporting_init(void);
|
||||
|
||||
typedef void(srtp_err_report_handler_func_t)(srtp_err_reporting_level_t level,
|
||||
const char *msg);
|
||||
|
||||
srtp_err_status_t srtp_install_err_report_handler(
|
||||
srtp_err_report_handler_func_t func);
|
||||
|
||||
/*
|
||||
* srtp_err_report reports a 'printf' formatted error
|
||||
* string, followed by a an arg list. The level argument
|
||||
* is one of srtp_err_reporting_level_t.
|
||||
*
|
||||
* Errors will be reported to stdout, if ERR_REPORTING_STDOUT
|
||||
* is defined.
|
||||
*
|
||||
*/
|
||||
|
||||
void srtp_err_report(srtp_err_reporting_level_t level, const char *format, ...);
|
||||
|
||||
/*
|
||||
* debug_module_t defines a debug module
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
int on; /* 1 if debugging is on, 0 if it is off */
|
||||
const char *name; /* printable name for debug module */
|
||||
} srtp_debug_module_t;
|
||||
|
||||
#ifdef ENABLE_DEBUG_LOGGING
|
||||
|
||||
#define debug_print(mod, format, arg) \
|
||||
srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg)
|
||||
#define debug_print2(mod, format, arg1, arg2) \
|
||||
srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, \
|
||||
arg1, arg2)
|
||||
|
||||
#else
|
||||
|
||||
#define debug_print(mod, format, arg) \
|
||||
if (mod.on) \
|
||||
srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, arg)
|
||||
#define debug_print2(mod, format, arg1, arg2) \
|
||||
if (mod.on) \
|
||||
srtp_err_report(srtp_err_level_debug, ("%s: " format "\n"), mod.name, \
|
||||
arg1, arg2)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ERR_H */
|
||||
146
TMessagesProj/jni/third_party/libsrtp/crypto/include/integers.h
vendored
Normal file
146
TMessagesProj/jni/third_party/libsrtp/crypto/include/integers.h
vendored
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* integers.h
|
||||
*
|
||||
* defines integer types (or refers to their definitions)
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef INTEGERS_H
|
||||
#define INTEGERS_H
|
||||
|
||||
/* use standard integer definitions, if they're available */
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_INT_TYPES_H
|
||||
#include <sys/int_types.h> /* this exists on Sun OS */
|
||||
#endif
|
||||
#ifdef HAVE_MACHINE_TYPES_H
|
||||
#include <machine/types.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Can we do 64 bit integers? */
|
||||
#if !defined(HAVE_UINT64_T)
|
||||
#if SIZEOF_UNSIGNED_LONG == 8
|
||||
typedef unsigned long uint64_t;
|
||||
#elif SIZEOF_UNSIGNED_LONG_LONG == 8
|
||||
typedef unsigned long long uint64_t;
|
||||
#else
|
||||
#define NO_64BIT_MATH 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Reasonable defaults for 32 bit machines - you may need to
|
||||
* edit these definitions for your own machine. */
|
||||
#ifndef HAVE_UINT8_T
|
||||
typedef unsigned char uint8_t;
|
||||
#endif
|
||||
#ifndef HAVE_UINT16_T
|
||||
typedef unsigned short int uint16_t;
|
||||
#endif
|
||||
#ifndef HAVE_UINT32_T
|
||||
typedef unsigned int uint32_t;
|
||||
#endif
|
||||
#ifndef HAVE_INT32_T
|
||||
typedef int int32_t;
|
||||
#endif
|
||||
|
||||
#if defined(NO_64BIT_MATH) && defined(HAVE_CONFIG_H)
|
||||
typedef double uint64_t;
|
||||
/* assert that sizeof(double) == 8 */
|
||||
extern uint64_t make64(uint32_t high, uint32_t low);
|
||||
extern uint32_t high32(uint64_t value);
|
||||
extern uint32_t low32(uint64_t value);
|
||||
#endif
|
||||
|
||||
/* These macros are to load and store 32-bit values from un-aligned
|
||||
addresses. This is required for processors that do not allow unaligned
|
||||
loads. */
|
||||
#ifdef ALIGNMENT_32BIT_REQUIRED
|
||||
/* Note that if it's in a variable, you can memcpy it */
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define PUT_32(addr, value) \
|
||||
{ \
|
||||
((unsigned char *)(addr))[0] = (value >> 24); \
|
||||
((unsigned char *)(addr))[1] = (value >> 16) & 0xff; \
|
||||
((unsigned char *)(addr))[2] = (value >> 8) & 0xff; \
|
||||
((unsigned char *)(addr))[3] = (value)&0xff; \
|
||||
}
|
||||
#define GET_32(addr) \
|
||||
((((unsigned char *)(addr))[0] << 24) | \
|
||||
(((unsigned char *)(addr))[1] << 16) | \
|
||||
(((unsigned char *)(addr))[2] << 8) | (((unsigned char *)(addr))[3]))
|
||||
#else
|
||||
#define PUT_32(addr, value) \
|
||||
{ \
|
||||
((unsigned char *)(addr))[3] = (value >> 24); \
|
||||
((unsigned char *)(addr))[2] = (value >> 16) & 0xff; \
|
||||
((unsigned char *)(addr))[1] = (value >> 8) & 0xff; \
|
||||
((unsigned char *)(addr))[0] = (value)&0xff; \
|
||||
}
|
||||
#define GET_32(addr) \
|
||||
((((unsigned char *)(addr))[3] << 24) | \
|
||||
(((unsigned char *)(addr))[2] << 16) | \
|
||||
(((unsigned char *)(addr))[1] << 8) | (((unsigned char *)(addr))[0]))
|
||||
#endif // WORDS_BIGENDIAN
|
||||
#else
|
||||
#define PUT_32(addr, value) *(((uint32_t *) (addr)) = (value)
|
||||
#define GET_32(addr) (*(((uint32_t *) (addr)))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* INTEGERS_H */
|
||||
88
TMessagesProj/jni/third_party/libsrtp/crypto/include/key.h
vendored
Normal file
88
TMessagesProj/jni/third_party/libsrtp/crypto/include/key.h
vendored
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* key.h
|
||||
*
|
||||
* key usage limits enforcement
|
||||
*
|
||||
* David A. Mcgrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef KEY_H
|
||||
#define KEY_H
|
||||
|
||||
#include "rdbx.h" /* for srtp_xtd_seq_num_t */
|
||||
#include "err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct srtp_key_limit_ctx_t *srtp_key_limit_t;
|
||||
|
||||
typedef enum {
|
||||
srtp_key_event_normal,
|
||||
srtp_key_event_soft_limit,
|
||||
srtp_key_event_hard_limit
|
||||
} srtp_key_event_t;
|
||||
|
||||
srtp_err_status_t srtp_key_limit_set(srtp_key_limit_t key,
|
||||
const srtp_xtd_seq_num_t s);
|
||||
|
||||
srtp_err_status_t srtp_key_limit_clone(srtp_key_limit_t original,
|
||||
srtp_key_limit_t *new_key);
|
||||
|
||||
srtp_err_status_t srtp_key_limit_check(const srtp_key_limit_t key);
|
||||
|
||||
srtp_key_event_t srtp_key_limit_update(srtp_key_limit_t key);
|
||||
|
||||
typedef enum {
|
||||
srtp_key_state_normal,
|
||||
srtp_key_state_past_soft_limit,
|
||||
srtp_key_state_expired
|
||||
} srtp_key_state_t;
|
||||
|
||||
typedef struct srtp_key_limit_ctx_t {
|
||||
srtp_xtd_seq_num_t num_left;
|
||||
srtp_key_state_t state;
|
||||
} srtp_key_limit_ctx_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* KEY_H */
|
||||
73
TMessagesProj/jni/third_party/libsrtp/crypto/include/null_auth.h
vendored
Normal file
73
TMessagesProj/jni/third_party/libsrtp/crypto/include/null_auth.h
vendored
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* null-auth.h
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NULL_AUTH_H
|
||||
#define NULL_AUTH_H
|
||||
|
||||
#include "auth.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char foo;
|
||||
} srtp_null_auth_ctx_t;
|
||||
|
||||
#if 0
|
||||
srtp_err_status_t srtp_null_auth_alloc(srtp_auth_t **a, int key_len, int out_len);
|
||||
|
||||
srtp_err_status_t srtp_null_auth_dealloc(srtp_auth_t *a);
|
||||
|
||||
srtp_err_status_t srtp_null_auth_init(srtp_null_auth_ctx_t *state, const uint8_t *key, int key_len);
|
||||
|
||||
srtp_err_status_t srtp_null_auth_compute(srtp_null_auth_ctx_t *state, uint8_t *message, int msg_octets, int tag_len, uint8_t *result);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NULL_AUTH_H */
|
||||
57
TMessagesProj/jni/third_party/libsrtp/crypto/include/null_cipher.h
vendored
Normal file
57
TMessagesProj/jni/third_party/libsrtp/crypto/include/null_cipher.h
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* null-cipher.h
|
||||
*
|
||||
* header file for the null cipher
|
||||
*
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NULL_CIPHER_H
|
||||
#define NULL_CIPHER_H
|
||||
|
||||
#include "datatypes.h"
|
||||
#include "cipher.h"
|
||||
|
||||
typedef struct {
|
||||
char foo; /* empty, for now */
|
||||
} srtp_null_cipher_ctx_t;
|
||||
|
||||
#endif /* NULL_CIPHER_H */
|
||||
125
TMessagesProj/jni/third_party/libsrtp/crypto/include/rdb.h
vendored
Normal file
125
TMessagesProj/jni/third_party/libsrtp/crypto/include/rdb.h
vendored
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* replay-database.h
|
||||
*
|
||||
* interface for a replay database for packet security
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef REPLAY_DB_H
|
||||
#define REPLAY_DB_H
|
||||
|
||||
#include "integers.h" /* for uint32_t */
|
||||
#include "datatypes.h" /* for v128_t */
|
||||
#include "err.h" /* for srtp_err_status_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* if the ith least significant bit is one, then the packet index
|
||||
* window_end-i is in the database
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
uint32_t window_start; /* packet index of the first bit in bitmask */
|
||||
v128_t bitmask;
|
||||
} srtp_rdb_t;
|
||||
|
||||
#define rdb_bits_in_bitmask (8 * sizeof(v128_t))
|
||||
|
||||
/*
|
||||
* srtp_rdb_init
|
||||
*
|
||||
* initalizes rdb
|
||||
*
|
||||
* returns srtp_err_status_ok on success, srtp_err_status_t_fail otherwise
|
||||
*/
|
||||
srtp_err_status_t srtp_rdb_init(srtp_rdb_t *rdb);
|
||||
|
||||
/*
|
||||
* srtp_rdb_check
|
||||
*
|
||||
* checks to see if index appears in rdb
|
||||
*
|
||||
* returns srtp_err_status_fail if the index already appears in rdb,
|
||||
* returns srtp_err_status_ok otherwise
|
||||
*/
|
||||
srtp_err_status_t srtp_rdb_check(const srtp_rdb_t *rdb, uint32_t rdb_index);
|
||||
|
||||
/*
|
||||
* srtp_rdb_add_index
|
||||
*
|
||||
* adds index to srtp_rdb_t (and does *not* check if index appears in db)
|
||||
*
|
||||
* returns srtp_err_status_ok on success, srtp_err_status_fail otherwise
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_rdb_add_index(srtp_rdb_t *rdb, uint32_t rdb_index);
|
||||
|
||||
/*
|
||||
* the functions srtp_rdb_increment() and srtp_rdb_get_value() are for use by
|
||||
* senders, not receivers - DO NOT use these functions on the same
|
||||
* srtp_rdb_t upon which srtp_rdb_add_index is used!
|
||||
*/
|
||||
|
||||
/*
|
||||
* srtp_rdb_increment(db) increments the sequence number in db, if it is
|
||||
* not too high
|
||||
*
|
||||
* return values:
|
||||
*
|
||||
* srtp_err_status_ok no problem
|
||||
* srtp_err_status_key_expired sequence number too high
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_rdb_increment(srtp_rdb_t *rdb);
|
||||
|
||||
/*
|
||||
* srtp_rdb_get_value(db) returns the current sequence number of db
|
||||
*/
|
||||
uint32_t srtp_rdb_get_value(const srtp_rdb_t *rdb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* REPLAY_DB_H */
|
||||
209
TMessagesProj/jni/third_party/libsrtp/crypto/include/rdbx.h
vendored
Normal file
209
TMessagesProj/jni/third_party/libsrtp/crypto/include/rdbx.h
vendored
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
/*
|
||||
* rdbx.h
|
||||
*
|
||||
* replay database with extended packet indices, using a rollover counter
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RDBX_H
|
||||
#define RDBX_H
|
||||
|
||||
#include "datatypes.h"
|
||||
#include "err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* #define ROC_TEST */
|
||||
|
||||
#ifndef ROC_TEST
|
||||
|
||||
typedef uint16_t srtp_sequence_number_t; /* 16 bit sequence number */
|
||||
typedef uint32_t srtp_rollover_counter_t; /* 32 bit rollover counter */
|
||||
|
||||
#else /* use small seq_num and roc datatypes for testing purposes */
|
||||
|
||||
typedef unsigned char srtp_sequence_number_t; /* 8 bit sequence number */
|
||||
typedef uint16_t srtp_rollover_counter_t; /* 16 bit rollover counter */
|
||||
|
||||
#endif
|
||||
|
||||
#define seq_num_median (1 << (8 * sizeof(srtp_sequence_number_t) - 1))
|
||||
#define seq_num_max (1 << (8 * sizeof(srtp_sequence_number_t)))
|
||||
|
||||
/*
|
||||
* An rtp_xtd_seq_num_t is a 64-bit unsigned integer used as an 'extended'
|
||||
* sequence number.
|
||||
*/
|
||||
typedef uint64_t srtp_xtd_seq_num_t;
|
||||
|
||||
/*
|
||||
* An srtp_rdbx_t is a replay database with extended range; it uses an
|
||||
* xtd_seq_num_t and a bitmask of recently received indices.
|
||||
*/
|
||||
typedef struct {
|
||||
srtp_xtd_seq_num_t index;
|
||||
bitvector_t bitmask;
|
||||
} srtp_rdbx_t;
|
||||
|
||||
/*
|
||||
* srtp_rdbx_init(rdbx_ptr, ws)
|
||||
*
|
||||
* initializes the rdbx pointed to by its argument with the window size ws,
|
||||
* setting the rollover counter and sequence number to zero
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_init(srtp_rdbx_t *rdbx, unsigned long ws);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_dealloc(rdbx_ptr)
|
||||
*
|
||||
* frees memory associated with the rdbx
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_dealloc(srtp_rdbx_t *rdbx);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_estimate_index(rdbx, guess, s)
|
||||
*
|
||||
* given an rdbx and a sequence number s (from a newly arrived packet),
|
||||
* sets the contents of *guess to contain the best guess of the packet
|
||||
* index to which s corresponds, and returns the difference between
|
||||
* *guess and the locally stored synch info
|
||||
*/
|
||||
int32_t srtp_rdbx_estimate_index(const srtp_rdbx_t *rdbx,
|
||||
srtp_xtd_seq_num_t *guess,
|
||||
srtp_sequence_number_t s);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_check(rdbx, delta);
|
||||
*
|
||||
* srtp_rdbx_check(&r, delta) checks to see if the xtd_seq_num_t
|
||||
* which is at rdbx->window_start + delta is in the rdb
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_check(const srtp_rdbx_t *rdbx, int difference);
|
||||
|
||||
/*
|
||||
* srtp_replay_add_index(rdbx, delta)
|
||||
*
|
||||
* adds the srtp_xtd_seq_num_t at rdbx->window_start + delta to replay_db
|
||||
* (and does *not* check if that xtd_seq_num_t appears in db)
|
||||
*
|
||||
* this function should be called *only* after replay_check has
|
||||
* indicated that the index does not appear in the rdbx, and a mutex
|
||||
* should protect the rdbx between these calls if necessary.
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_add_index(srtp_rdbx_t *rdbx, int delta);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_set_roc(rdbx, roc) initalizes the srtp_rdbx_t at the location rdbx
|
||||
* to have the rollover counter value roc. If that value is less than
|
||||
* the current rollover counter value, then the function returns
|
||||
* srtp_err_status_replay_old; otherwise, srtp_err_status_ok is returned.
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_set_roc(srtp_rdbx_t *rdbx, uint32_t roc);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_get_packet_index(rdbx) returns the value of the rollover counter
|
||||
* for
|
||||
* the srtp_rdbx_t pointed to by rdbx
|
||||
*
|
||||
*/
|
||||
srtp_xtd_seq_num_t srtp_rdbx_get_packet_index(const srtp_rdbx_t *rdbx);
|
||||
|
||||
/*
|
||||
* srtp_xtd_seq_num_t functions - these are *internal* functions of rdbx, and
|
||||
* shouldn't be used to manipulate rdbx internal values. use the rdbx
|
||||
* api instead!
|
||||
*/
|
||||
|
||||
/*
|
||||
* srtp_rdbx_get_ws(rdbx_ptr)
|
||||
*
|
||||
* gets the window size which was used to initialize the rdbx
|
||||
*/
|
||||
unsigned long srtp_rdbx_get_window_size(const srtp_rdbx_t *rdbx);
|
||||
|
||||
/* index_init(&pi) initializes a packet index pi (sets it to zero) */
|
||||
void srtp_index_init(srtp_xtd_seq_num_t *pi);
|
||||
|
||||
/* index_advance(&pi, s) advances a xtd_seq_num_t forward by s */
|
||||
void srtp_index_advance(srtp_xtd_seq_num_t *pi, srtp_sequence_number_t s);
|
||||
|
||||
/*
|
||||
* srtp_index_guess(local, guess, s)
|
||||
*
|
||||
* given a srtp_xtd_seq_num_t local (which represents the highest
|
||||
* known-to-be-good index) and a sequence number s (from a newly
|
||||
* arrived packet), sets the contents of *guess to contain the best
|
||||
* guess of the packet index to which s corresponds, and returns the
|
||||
* difference between *guess and *local
|
||||
*/
|
||||
int32_t srtp_index_guess(const srtp_xtd_seq_num_t *local,
|
||||
srtp_xtd_seq_num_t *guess,
|
||||
srtp_sequence_number_t s);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_get_roc(rdbx)
|
||||
*
|
||||
* Get the current rollover counter
|
||||
*
|
||||
*/
|
||||
uint32_t srtp_rdbx_get_roc(const srtp_rdbx_t *rdbx);
|
||||
|
||||
/*
|
||||
* srtp_rdbx_set_roc_seq(rdbx, roc, seq) initalizes the srtp_rdbx_t at the
|
||||
* location rdbx to have the rollover counter value roc and packet sequence
|
||||
* number seq. If the new rollover counter value is less than the current
|
||||
* rollover counter value, then the function returns
|
||||
* srtp_err_status_replay_old, otherwise, srtp_err_status_ok is returned.
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_set_roc_seq(srtp_rdbx_t *rdbx,
|
||||
uint32_t roc,
|
||||
uint16_t seq);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RDBX_H */
|
||||
66
TMessagesProj/jni/third_party/libsrtp/crypto/include/stat.h
vendored
Normal file
66
TMessagesProj/jni/third_party/libsrtp/crypto/include/stat.h
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* stats.h
|
||||
*
|
||||
* interface to statistical test functions
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STAT_H
|
||||
#define STAT_H
|
||||
|
||||
#include "datatypes.h" /* for uint8_t */
|
||||
#include "err.h" /* for srtp_err_status_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
srtp_err_status_t stat_test_monobit(uint8_t *data);
|
||||
|
||||
srtp_err_status_t stat_test_poker(uint8_t *data);
|
||||
|
||||
srtp_err_status_t stat_test_runs(uint8_t *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* STAT_H */
|
||||
99
TMessagesProj/jni/third_party/libsrtp/crypto/kernel/alloc.c
vendored
Normal file
99
TMessagesProj/jni/third_party/libsrtp/crypto/kernel/alloc.c
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* alloc.c
|
||||
*
|
||||
* memory allocation and deallocation
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "alloc.h"
|
||||
#include "crypto_kernel.h"
|
||||
|
||||
/* the debug module for memory allocation */
|
||||
|
||||
srtp_debug_module_t srtp_mod_alloc = {
|
||||
0, /* debugging is off by default */
|
||||
"alloc" /* printable name for module */
|
||||
};
|
||||
|
||||
/*
|
||||
* Nota bene: the debugging statements for srtp_crypto_alloc() and
|
||||
* srtp_crypto_free() have identical prefixes, which include the addresses
|
||||
* of the memory locations on which they are operating. This fact can
|
||||
* be used to locate memory leaks, by turning on memory debugging,
|
||||
* grepping for 'alloc', then matching alloc and free calls by
|
||||
* address.
|
||||
*/
|
||||
|
||||
#if defined(HAVE_STDLIB_H)
|
||||
|
||||
void *srtp_crypto_alloc(size_t size)
|
||||
{
|
||||
void *ptr;
|
||||
|
||||
if (!size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr = calloc(1, size);
|
||||
|
||||
if (ptr) {
|
||||
debug_print(srtp_mod_alloc, "(location: %p) allocated", ptr);
|
||||
} else {
|
||||
debug_print(srtp_mod_alloc, "allocation failed (asked for %d bytes)\n",
|
||||
size);
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void srtp_crypto_free(void *ptr)
|
||||
{
|
||||
debug_print(srtp_mod_alloc, "(location: %p) freed", ptr);
|
||||
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
#else /* we need to define our own memory allocation routines */
|
||||
|
||||
#error no memory allocation defined yet
|
||||
|
||||
#endif
|
||||
559
TMessagesProj/jni/third_party/libsrtp/crypto/kernel/crypto_kernel.c
vendored
Normal file
559
TMessagesProj/jni/third_party/libsrtp/crypto/kernel/crypto_kernel.c
vendored
Normal file
|
|
@ -0,0 +1,559 @@
|
|||
/*
|
||||
* crypto_kernel.c
|
||||
*
|
||||
* header for the cryptographic kernel
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "alloc.h"
|
||||
|
||||
#include "crypto_kernel.h"
|
||||
#include "cipher_types.h"
|
||||
|
||||
/* the debug module for the crypto_kernel */
|
||||
|
||||
srtp_debug_module_t srtp_mod_crypto_kernel = {
|
||||
0, /* debugging is off by default */
|
||||
"crypto kernel" /* printable name for module */
|
||||
};
|
||||
|
||||
/* crypto_kernel is a global variable, the only one of its datatype */
|
||||
|
||||
srtp_crypto_kernel_t crypto_kernel = {
|
||||
srtp_crypto_kernel_state_insecure, /* start off in insecure state */
|
||||
NULL, /* no cipher types yet */
|
||||
NULL, /* no auth types yet */
|
||||
NULL /* no debug modules yet */
|
||||
};
|
||||
|
||||
#define MAX_RNG_TRIALS 25
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_init()
|
||||
{
|
||||
srtp_err_status_t status;
|
||||
|
||||
/* check the security state */
|
||||
if (crypto_kernel.state == srtp_crypto_kernel_state_secure) {
|
||||
/*
|
||||
* we're already in the secure state, but we've been asked to
|
||||
* re-initialize, so we just re-run the self-tests and then return
|
||||
*/
|
||||
return srtp_crypto_kernel_status();
|
||||
}
|
||||
|
||||
/* initialize error reporting system */
|
||||
status = srtp_err_reporting_init();
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* load debug modules */
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_crypto_kernel);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_auth);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_cipher);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_stat);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_alloc);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* load cipher types */
|
||||
status = srtp_crypto_kernel_load_cipher_type(&srtp_null_cipher,
|
||||
SRTP_NULL_CIPHER);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_cipher_type(&srtp_aes_icm_128,
|
||||
SRTP_AES_ICM_128);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_cipher_type(&srtp_aes_icm_256,
|
||||
SRTP_AES_ICM_256);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_aes_icm);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
#ifdef OPENSSL
|
||||
status = srtp_crypto_kernel_load_cipher_type(&srtp_aes_icm_192,
|
||||
SRTP_AES_ICM_192);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_cipher_type(&srtp_aes_gcm_128_openssl,
|
||||
SRTP_AES_GCM_128);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_cipher_type(&srtp_aes_gcm_256_openssl,
|
||||
SRTP_AES_GCM_256);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_aes_gcm);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* load auth func types */
|
||||
status = srtp_crypto_kernel_load_auth_type(&srtp_null_auth, SRTP_NULL_AUTH);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_auth_type(&srtp_hmac, SRTP_HMAC_SHA1);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = srtp_crypto_kernel_load_debug_module(&srtp_mod_hmac);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* change state to secure */
|
||||
crypto_kernel.state = srtp_crypto_kernel_state_secure;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_status()
|
||||
{
|
||||
srtp_err_status_t status;
|
||||
srtp_kernel_cipher_type_t *ctype = crypto_kernel.cipher_type_list;
|
||||
srtp_kernel_auth_type_t *atype = crypto_kernel.auth_type_list;
|
||||
|
||||
/* for each cipher type, describe and test */
|
||||
while (ctype != NULL) {
|
||||
srtp_err_report(srtp_err_level_info, "cipher: %s\n",
|
||||
ctype->cipher_type->description);
|
||||
srtp_err_report(srtp_err_level_info, " self-test: ");
|
||||
status = srtp_cipher_type_self_test(ctype->cipher_type);
|
||||
if (status) {
|
||||
srtp_err_report(srtp_err_level_error, "failed with error code %d\n",
|
||||
status);
|
||||
exit(status);
|
||||
}
|
||||
srtp_err_report(srtp_err_level_info, "passed\n");
|
||||
ctype = ctype->next;
|
||||
}
|
||||
|
||||
/* for each auth type, describe and test */
|
||||
while (atype != NULL) {
|
||||
srtp_err_report(srtp_err_level_info, "auth func: %s\n",
|
||||
atype->auth_type->description);
|
||||
srtp_err_report(srtp_err_level_info, " self-test: ");
|
||||
status = srtp_auth_type_self_test(atype->auth_type);
|
||||
if (status) {
|
||||
srtp_err_report(srtp_err_level_error, "failed with error code %d\n",
|
||||
status);
|
||||
exit(status);
|
||||
}
|
||||
srtp_err_report(srtp_err_level_info, "passed\n");
|
||||
atype = atype->next;
|
||||
}
|
||||
|
||||
srtp_crypto_kernel_list_debug_modules();
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_list_debug_modules()
|
||||
{
|
||||
srtp_kernel_debug_module_t *dm = crypto_kernel.debug_module_list;
|
||||
|
||||
/* describe each debug module */
|
||||
srtp_err_report(srtp_err_level_info, "debug modules loaded:\n");
|
||||
while (dm != NULL) {
|
||||
srtp_err_report(srtp_err_level_info, " %s ", dm->mod->name);
|
||||
if (dm->mod->on) {
|
||||
srtp_err_report(srtp_err_level_info, "(on)\n");
|
||||
} else {
|
||||
srtp_err_report(srtp_err_level_info, "(off)\n");
|
||||
}
|
||||
dm = dm->next;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_shutdown()
|
||||
{
|
||||
/*
|
||||
* free dynamic memory used in crypto_kernel at present
|
||||
*/
|
||||
|
||||
/* walk down cipher type list, freeing memory */
|
||||
while (crypto_kernel.cipher_type_list != NULL) {
|
||||
srtp_kernel_cipher_type_t *ctype = crypto_kernel.cipher_type_list;
|
||||
crypto_kernel.cipher_type_list = ctype->next;
|
||||
debug_print(srtp_mod_crypto_kernel, "freeing memory for cipher %s",
|
||||
ctype->cipher_type->description);
|
||||
srtp_crypto_free(ctype);
|
||||
}
|
||||
|
||||
/* walk down authetication module list, freeing memory */
|
||||
while (crypto_kernel.auth_type_list != NULL) {
|
||||
srtp_kernel_auth_type_t *atype = crypto_kernel.auth_type_list;
|
||||
crypto_kernel.auth_type_list = atype->next;
|
||||
debug_print(srtp_mod_crypto_kernel,
|
||||
"freeing memory for authentication %s",
|
||||
atype->auth_type->description);
|
||||
srtp_crypto_free(atype);
|
||||
}
|
||||
|
||||
/* walk down debug module list, freeing memory */
|
||||
while (crypto_kernel.debug_module_list != NULL) {
|
||||
srtp_kernel_debug_module_t *kdm = crypto_kernel.debug_module_list;
|
||||
crypto_kernel.debug_module_list = kdm->next;
|
||||
debug_print(srtp_mod_crypto_kernel,
|
||||
"freeing memory for debug module %s", kdm->mod->name);
|
||||
srtp_crypto_free(kdm);
|
||||
}
|
||||
|
||||
/* return to insecure state */
|
||||
crypto_kernel.state = srtp_crypto_kernel_state_insecure;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static inline srtp_err_status_t srtp_crypto_kernel_do_load_cipher_type(
|
||||
const srtp_cipher_type_t *new_ct,
|
||||
srtp_cipher_type_id_t id,
|
||||
int replace)
|
||||
{
|
||||
srtp_kernel_cipher_type_t *ctype, *new_ctype;
|
||||
srtp_err_status_t status;
|
||||
|
||||
/* defensive coding */
|
||||
if (new_ct == NULL) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
if (new_ct->id != id) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* check cipher type by running self-test */
|
||||
status = srtp_cipher_type_self_test(new_ct);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* walk down list, checking if this type is in the list already */
|
||||
ctype = crypto_kernel.cipher_type_list;
|
||||
while (ctype != NULL) {
|
||||
if (id == ctype->id) {
|
||||
if (!replace) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
status =
|
||||
srtp_cipher_type_test(new_ct, ctype->cipher_type->test_data);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
new_ctype = ctype;
|
||||
break;
|
||||
} else if (new_ct == ctype->cipher_type) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
ctype = ctype->next;
|
||||
}
|
||||
|
||||
/* if not found, put new_ct at the head of the list */
|
||||
if (ctype == NULL) {
|
||||
/* allocate memory */
|
||||
new_ctype = (srtp_kernel_cipher_type_t *)srtp_crypto_alloc(
|
||||
sizeof(srtp_kernel_cipher_type_t));
|
||||
if (new_ctype == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
new_ctype->next = crypto_kernel.cipher_type_list;
|
||||
|
||||
/* set head of list to new cipher type */
|
||||
crypto_kernel.cipher_type_list = new_ctype;
|
||||
}
|
||||
|
||||
/* set fields */
|
||||
new_ctype->cipher_type = new_ct;
|
||||
new_ctype->id = id;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_load_cipher_type(
|
||||
const srtp_cipher_type_t *new_ct,
|
||||
srtp_cipher_type_id_t id)
|
||||
{
|
||||
return srtp_crypto_kernel_do_load_cipher_type(new_ct, id, 0);
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_replace_cipher_type(const srtp_cipher_type_t *new_ct,
|
||||
srtp_cipher_type_id_t id)
|
||||
{
|
||||
return srtp_crypto_kernel_do_load_cipher_type(new_ct, id, 1);
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_do_load_auth_type(
|
||||
const srtp_auth_type_t *new_at,
|
||||
srtp_auth_type_id_t id,
|
||||
int replace)
|
||||
{
|
||||
srtp_kernel_auth_type_t *atype, *new_atype;
|
||||
srtp_err_status_t status;
|
||||
|
||||
/* defensive coding */
|
||||
if (new_at == NULL) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
if (new_at->id != id) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* check auth type by running self-test */
|
||||
status = srtp_auth_type_self_test(new_at);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* walk down list, checking if this type is in the list already */
|
||||
atype = crypto_kernel.auth_type_list;
|
||||
while (atype != NULL) {
|
||||
if (id == atype->id) {
|
||||
if (!replace) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
status = srtp_auth_type_test(new_at, atype->auth_type->test_data);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
new_atype = atype;
|
||||
break;
|
||||
} else if (new_at == atype->auth_type) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
atype = atype->next;
|
||||
}
|
||||
|
||||
/* if not found, put new_at at the head of the list */
|
||||
if (atype == NULL) {
|
||||
/* allocate memory */
|
||||
new_atype = (srtp_kernel_auth_type_t *)srtp_crypto_alloc(
|
||||
sizeof(srtp_kernel_auth_type_t));
|
||||
if (new_atype == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
new_atype->next = crypto_kernel.auth_type_list;
|
||||
/* set head of list to new auth type */
|
||||
crypto_kernel.auth_type_list = new_atype;
|
||||
}
|
||||
|
||||
/* set fields */
|
||||
new_atype->auth_type = new_at;
|
||||
new_atype->id = id;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_load_auth_type(
|
||||
const srtp_auth_type_t *new_at,
|
||||
srtp_auth_type_id_t id)
|
||||
{
|
||||
return srtp_crypto_kernel_do_load_auth_type(new_at, id, 0);
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_replace_auth_type(const srtp_auth_type_t *new_at,
|
||||
srtp_auth_type_id_t id)
|
||||
{
|
||||
return srtp_crypto_kernel_do_load_auth_type(new_at, id, 1);
|
||||
}
|
||||
|
||||
const srtp_cipher_type_t *srtp_crypto_kernel_get_cipher_type(
|
||||
srtp_cipher_type_id_t id)
|
||||
{
|
||||
srtp_kernel_cipher_type_t *ctype;
|
||||
|
||||
/* walk down list, looking for id */
|
||||
ctype = crypto_kernel.cipher_type_list;
|
||||
while (ctype != NULL) {
|
||||
if (id == ctype->id) {
|
||||
return ctype->cipher_type;
|
||||
}
|
||||
ctype = ctype->next;
|
||||
}
|
||||
|
||||
/* haven't found the right one, indicate failure by returning NULL */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_alloc_cipher(srtp_cipher_type_id_t id,
|
||||
srtp_cipher_pointer_t *cp,
|
||||
int key_len,
|
||||
int tag_len)
|
||||
{
|
||||
const srtp_cipher_type_t *ct;
|
||||
|
||||
/*
|
||||
* if the crypto_kernel is not yet initialized, we refuse to allocate
|
||||
* any ciphers - this is a bit extra-paranoid
|
||||
*/
|
||||
if (crypto_kernel.state != srtp_crypto_kernel_state_secure) {
|
||||
return srtp_err_status_init_fail;
|
||||
}
|
||||
|
||||
ct = srtp_crypto_kernel_get_cipher_type(id);
|
||||
if (!ct) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
return ((ct)->alloc(cp, key_len, tag_len));
|
||||
}
|
||||
|
||||
const srtp_auth_type_t *srtp_crypto_kernel_get_auth_type(srtp_auth_type_id_t id)
|
||||
{
|
||||
srtp_kernel_auth_type_t *atype;
|
||||
|
||||
/* walk down list, looking for id */
|
||||
atype = crypto_kernel.auth_type_list;
|
||||
while (atype != NULL) {
|
||||
if (id == atype->id) {
|
||||
return atype->auth_type;
|
||||
}
|
||||
atype = atype->next;
|
||||
}
|
||||
|
||||
/* haven't found the right one, indicate failure by returning NULL */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_alloc_auth(srtp_auth_type_id_t id,
|
||||
srtp_auth_pointer_t *ap,
|
||||
int key_len,
|
||||
int tag_len)
|
||||
{
|
||||
const srtp_auth_type_t *at;
|
||||
|
||||
/*
|
||||
* if the crypto_kernel is not yet initialized, we refuse to allocate
|
||||
* any auth functions - this is a bit extra-paranoid
|
||||
*/
|
||||
if (crypto_kernel.state != srtp_crypto_kernel_state_secure) {
|
||||
return srtp_err_status_init_fail;
|
||||
}
|
||||
|
||||
at = srtp_crypto_kernel_get_auth_type(id);
|
||||
if (!at) {
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
|
||||
return ((at)->alloc(ap, key_len, tag_len));
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_load_debug_module(
|
||||
srtp_debug_module_t *new_dm)
|
||||
{
|
||||
srtp_kernel_debug_module_t *kdm, *new;
|
||||
|
||||
/* defensive coding */
|
||||
if (new_dm == NULL || new_dm->name == NULL) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
/* walk down list, checking if this type is in the list already */
|
||||
kdm = crypto_kernel.debug_module_list;
|
||||
while (kdm != NULL) {
|
||||
if (strncmp(new_dm->name, kdm->mod->name, 64) == 0) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
kdm = kdm->next;
|
||||
}
|
||||
|
||||
/* put new_dm at the head of the list */
|
||||
/* allocate memory */
|
||||
new = (srtp_kernel_debug_module_t *)srtp_crypto_alloc(
|
||||
sizeof(srtp_kernel_debug_module_t));
|
||||
if (new == NULL) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* set fields */
|
||||
new->mod = new_dm;
|
||||
new->next = crypto_kernel.debug_module_list;
|
||||
|
||||
/* set head of list to new cipher type */
|
||||
crypto_kernel.debug_module_list = new;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_crypto_kernel_set_debug_module(const char *name, int on)
|
||||
{
|
||||
srtp_kernel_debug_module_t *kdm;
|
||||
|
||||
/* walk down list, checking if this type is in the list already */
|
||||
kdm = crypto_kernel.debug_module_list;
|
||||
while (kdm != NULL) {
|
||||
if (strncmp(name, kdm->mod->name, 64) == 0) {
|
||||
kdm->mod->on = on;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
kdm = kdm->next;
|
||||
}
|
||||
|
||||
return srtp_err_status_fail;
|
||||
}
|
||||
106
TMessagesProj/jni/third_party/libsrtp/crypto/kernel/err.c
vendored
Normal file
106
TMessagesProj/jni/third_party/libsrtp/crypto/kernel/err.c
vendored
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* err.c
|
||||
*
|
||||
* error status reporting functions
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "err.h"
|
||||
#include "datatypes.h"
|
||||
#include <string.h>
|
||||
|
||||
/* srtp_err_file is the FILE to which errors are reported */
|
||||
|
||||
static FILE *srtp_err_file = NULL;
|
||||
|
||||
srtp_err_status_t srtp_err_reporting_init()
|
||||
{
|
||||
#ifdef ERR_REPORTING_STDOUT
|
||||
srtp_err_file = stdout;
|
||||
#elif defined(ERR_REPORTING_FILE)
|
||||
/* open file for error reporting */
|
||||
srtp_err_file = fopen(ERR_REPORTING_FILE, "w");
|
||||
if (srtp_err_file == NULL) {
|
||||
return srtp_err_status_init_fail;
|
||||
}
|
||||
#endif
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
static srtp_err_report_handler_func_t *srtp_err_report_handler = NULL;
|
||||
|
||||
srtp_err_status_t srtp_install_err_report_handler(
|
||||
srtp_err_report_handler_func_t func)
|
||||
{
|
||||
srtp_err_report_handler = func;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
void srtp_err_report(srtp_err_reporting_level_t level, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
if (srtp_err_file != NULL) {
|
||||
va_start(args, format);
|
||||
vfprintf(srtp_err_file, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
if (srtp_err_report_handler != NULL) {
|
||||
va_start(args, format);
|
||||
char msg[512];
|
||||
if (vsnprintf(msg, sizeof(msg), format, args) > 0) {
|
||||
/* strip trailing \n, callback should not have one */
|
||||
size_t l = strlen(msg);
|
||||
if (l && msg[l - 1] == '\n') {
|
||||
msg[l - 1] = '\0';
|
||||
}
|
||||
srtp_err_report_handler(level, msg);
|
||||
/*
|
||||
* NOTE, need to be carefull, there is a potential that
|
||||
* octet_string_set_to_zero() could
|
||||
* call srtp_err_report() in the future, leading to recursion
|
||||
*/
|
||||
octet_string_set_to_zero(msg, sizeof(msg));
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
120
TMessagesProj/jni/third_party/libsrtp/crypto/kernel/key.c
vendored
Normal file
120
TMessagesProj/jni/third_party/libsrtp/crypto/kernel/key.c
vendored
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* key.c
|
||||
*
|
||||
* key usage limits enforcement
|
||||
*
|
||||
* David A. Mcgrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "key.h"
|
||||
|
||||
#define soft_limit 0x10000
|
||||
|
||||
srtp_err_status_t srtp_key_limit_set(srtp_key_limit_t key,
|
||||
const srtp_xtd_seq_num_t s)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
if (high32(s) == 0 && low32(s) < soft_limit) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
#else
|
||||
if (s < soft_limit) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
#endif
|
||||
key->num_left = s;
|
||||
key->state = srtp_key_state_normal;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_key_limit_clone(srtp_key_limit_t original,
|
||||
srtp_key_limit_t *new_key)
|
||||
{
|
||||
if (original == NULL) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
*new_key = original;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_key_limit_check(const srtp_key_limit_t key)
|
||||
{
|
||||
if (key->state == srtp_key_state_expired) {
|
||||
return srtp_err_status_key_expired;
|
||||
}
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_key_event_t srtp_key_limit_update(srtp_key_limit_t key)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
if (low32(key->num_left) == 0) {
|
||||
// carry
|
||||
key->num_left =
|
||||
make64(high32(key->num_left) - 1, low32(key->num_left) - 1);
|
||||
} else {
|
||||
// no carry
|
||||
key->num_left = make64(high32(key->num_left), low32(key->num_left) - 1);
|
||||
}
|
||||
if (high32(key->num_left) != 0 || low32(key->num_left) >= soft_limit) {
|
||||
return srtp_key_event_normal; /* we're above the soft limit */
|
||||
}
|
||||
#else
|
||||
key->num_left--;
|
||||
if (key->num_left >= soft_limit) {
|
||||
return srtp_key_event_normal; /* we're above the soft limit */
|
||||
}
|
||||
#endif
|
||||
if (key->state == srtp_key_state_normal) {
|
||||
/* we just passed the soft limit, so change the state */
|
||||
key->state = srtp_key_state_past_soft_limit;
|
||||
}
|
||||
#ifdef NO_64BIT_MATH
|
||||
if (low32(key->num_left) == 0 && high32(key->num_left == 0))
|
||||
#else
|
||||
if (key->num_left < 1)
|
||||
#endif
|
||||
{ /* we just hit the hard limit */
|
||||
key->state = srtp_key_state_expired;
|
||||
return srtp_key_event_hard_limit;
|
||||
}
|
||||
return srtp_key_event_soft_limit;
|
||||
}
|
||||
488
TMessagesProj/jni/third_party/libsrtp/crypto/math/datatypes.c
vendored
Normal file
488
TMessagesProj/jni/third_party/libsrtp/crypto/math/datatypes.c
vendored
Normal file
|
|
@ -0,0 +1,488 @@
|
|||
/*
|
||||
* datatypes.c
|
||||
*
|
||||
* data types for finite fields and functions for input, output, and
|
||||
* manipulation
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef OPENSSL
|
||||
#include <openssl/crypto.h>
|
||||
#endif
|
||||
|
||||
#include "datatypes.h"
|
||||
|
||||
static const int8_t octet_weight[256] = {
|
||||
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
|
||||
};
|
||||
|
||||
int octet_get_weight(uint8_t octet)
|
||||
{
|
||||
return (int)octet_weight[octet];
|
||||
}
|
||||
|
||||
/*
|
||||
* bit_string is a buffer that is used to hold output strings, e.g.
|
||||
* for printing.
|
||||
*/
|
||||
|
||||
/* the value MAX_PRINT_STRING_LEN is defined in datatypes.h */
|
||||
|
||||
char bit_string[MAX_PRINT_STRING_LEN];
|
||||
|
||||
uint8_t srtp_nibble_to_hex_char(uint8_t nibble)
|
||||
{
|
||||
char buf[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
return buf[nibble & 0xF];
|
||||
}
|
||||
|
||||
char *srtp_octet_string_hex_string(const void *s, int length)
|
||||
{
|
||||
const uint8_t *str = (const uint8_t *)s;
|
||||
int i;
|
||||
|
||||
/* double length, since one octet takes two hex characters */
|
||||
length *= 2;
|
||||
|
||||
/* truncate string if it would be too long */
|
||||
if (length > MAX_PRINT_STRING_LEN)
|
||||
length = MAX_PRINT_STRING_LEN - 2;
|
||||
|
||||
for (i = 0; i < length; i += 2) {
|
||||
bit_string[i] = srtp_nibble_to_hex_char(*str >> 4);
|
||||
bit_string[i + 1] = srtp_nibble_to_hex_char(*str++ & 0xF);
|
||||
}
|
||||
bit_string[i] = 0; /* null terminate string */
|
||||
return bit_string;
|
||||
}
|
||||
|
||||
char *v128_hex_string(v128_t *x)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = j = 0; i < 16; i++) {
|
||||
bit_string[j++] = srtp_nibble_to_hex_char(x->v8[i] >> 4);
|
||||
bit_string[j++] = srtp_nibble_to_hex_char(x->v8[i] & 0xF);
|
||||
}
|
||||
|
||||
bit_string[j] = 0; /* null terminate string */
|
||||
return bit_string;
|
||||
}
|
||||
|
||||
char *v128_bit_string(v128_t *x)
|
||||
{
|
||||
int j, i;
|
||||
uint32_t mask;
|
||||
|
||||
for (j = i = 0; j < 4; j++) {
|
||||
for (mask = 0x80000000; mask > 0; mask >>= 1) {
|
||||
if (x->v32[j] & mask)
|
||||
bit_string[i] = '1';
|
||||
else
|
||||
bit_string[i] = '0';
|
||||
++i;
|
||||
}
|
||||
}
|
||||
bit_string[128] = 0; /* null terminate string */
|
||||
|
||||
return bit_string;
|
||||
}
|
||||
|
||||
void v128_copy_octet_string(v128_t *x, const uint8_t s[16])
|
||||
{
|
||||
#ifdef ALIGNMENT_32BIT_REQUIRED
|
||||
if ((((uint32_t)&s[0]) & 0x3) != 0)
|
||||
#endif
|
||||
{
|
||||
x->v8[0] = s[0];
|
||||
x->v8[1] = s[1];
|
||||
x->v8[2] = s[2];
|
||||
x->v8[3] = s[3];
|
||||
x->v8[4] = s[4];
|
||||
x->v8[5] = s[5];
|
||||
x->v8[6] = s[6];
|
||||
x->v8[7] = s[7];
|
||||
x->v8[8] = s[8];
|
||||
x->v8[9] = s[9];
|
||||
x->v8[10] = s[10];
|
||||
x->v8[11] = s[11];
|
||||
x->v8[12] = s[12];
|
||||
x->v8[13] = s[13];
|
||||
x->v8[14] = s[14];
|
||||
x->v8[15] = s[15];
|
||||
}
|
||||
#ifdef ALIGNMENT_32BIT_REQUIRED
|
||||
else {
|
||||
v128_t *v = (v128_t *)&s[0];
|
||||
|
||||
v128_copy(x, v);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef DATATYPES_USE_MACROS /* little functions are not macros */
|
||||
|
||||
void v128_set_to_zero(v128_t *x)
|
||||
{
|
||||
_v128_set_to_zero(x);
|
||||
}
|
||||
|
||||
void v128_copy(v128_t *x, const v128_t *y)
|
||||
{
|
||||
_v128_copy(x, y);
|
||||
}
|
||||
|
||||
void v128_xor(v128_t *z, v128_t *x, v128_t *y)
|
||||
{
|
||||
_v128_xor(z, x, y);
|
||||
}
|
||||
|
||||
void v128_and(v128_t *z, v128_t *x, v128_t *y)
|
||||
{
|
||||
_v128_and(z, x, y);
|
||||
}
|
||||
|
||||
void v128_or(v128_t *z, v128_t *x, v128_t *y)
|
||||
{
|
||||
_v128_or(z, x, y);
|
||||
}
|
||||
|
||||
void v128_complement(v128_t *x)
|
||||
{
|
||||
_v128_complement(x);
|
||||
}
|
||||
|
||||
int v128_is_eq(const v128_t *x, const v128_t *y)
|
||||
{
|
||||
return _v128_is_eq(x, y);
|
||||
}
|
||||
|
||||
int v128_xor_eq(v128_t *x, const v128_t *y)
|
||||
{
|
||||
return _v128_xor_eq(x, y);
|
||||
}
|
||||
|
||||
int v128_get_bit(const v128_t *x, int i)
|
||||
{
|
||||
return _v128_get_bit(x, i);
|
||||
}
|
||||
|
||||
void v128_set_bit(v128_t *x, int i)
|
||||
{
|
||||
_v128_set_bit(x, i);
|
||||
}
|
||||
|
||||
void v128_clear_bit(v128_t *x, int i)
|
||||
{
|
||||
_v128_clear_bit(x, i);
|
||||
}
|
||||
|
||||
void v128_set_bit_to(v128_t *x, int i, int y)
|
||||
{
|
||||
_v128_set_bit_to(x, i, y);
|
||||
}
|
||||
|
||||
#endif /* DATATYPES_USE_MACROS */
|
||||
|
||||
void v128_right_shift(v128_t *x, int shift)
|
||||
{
|
||||
const int base_index = shift >> 5;
|
||||
const int bit_index = shift & 31;
|
||||
int i, from;
|
||||
uint32_t b;
|
||||
|
||||
if (shift > 127) {
|
||||
v128_set_to_zero(x);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bit_index == 0) {
|
||||
/* copy each word from left size to right side */
|
||||
x->v32[4 - 1] = x->v32[4 - 1 - base_index];
|
||||
for (i = 4 - 1; i > base_index; i--)
|
||||
x->v32[i - 1] = x->v32[i - 1 - base_index];
|
||||
|
||||
} else {
|
||||
/* set each word to the "or" of the two bit-shifted words */
|
||||
for (i = 4; i > base_index; i--) {
|
||||
from = i - 1 - base_index;
|
||||
b = x->v32[from] << bit_index;
|
||||
if (from > 0)
|
||||
b |= x->v32[from - 1] >> (32 - bit_index);
|
||||
x->v32[i - 1] = b;
|
||||
}
|
||||
}
|
||||
|
||||
/* now wrap up the final portion */
|
||||
for (i = 0; i < base_index; i++)
|
||||
x->v32[i] = 0;
|
||||
}
|
||||
|
||||
void v128_left_shift(v128_t *x, int shift)
|
||||
{
|
||||
int i;
|
||||
const int base_index = shift >> 5;
|
||||
const int bit_index = shift & 31;
|
||||
|
||||
if (shift > 127) {
|
||||
v128_set_to_zero(x);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bit_index == 0) {
|
||||
for (i = 0; i < 4 - base_index; i++)
|
||||
x->v32[i] = x->v32[i + base_index];
|
||||
} else {
|
||||
for (i = 0; i < 4 - base_index - 1; i++)
|
||||
x->v32[i] = (x->v32[i + base_index] >> bit_index) ^
|
||||
(x->v32[i + base_index + 1] << (32 - bit_index));
|
||||
x->v32[4 - base_index - 1] = x->v32[4 - 1] >> bit_index;
|
||||
}
|
||||
|
||||
/* now wrap up the final portion */
|
||||
for (i = 4 - base_index; i < 4; i++)
|
||||
x->v32[i] = 0;
|
||||
}
|
||||
|
||||
/* functions manipulating bitvector_t */
|
||||
|
||||
#ifndef DATATYPES_USE_MACROS /* little functions are not macros */
|
||||
|
||||
int bitvector_get_bit(const bitvector_t *v, int bit_index)
|
||||
{
|
||||
return _bitvector_get_bit(v, bit_index);
|
||||
}
|
||||
|
||||
void bitvector_set_bit(bitvector_t *v, int bit_index)
|
||||
{
|
||||
_bitvector_set_bit(v, bit_index);
|
||||
}
|
||||
|
||||
void bitvector_clear_bit(bitvector_t *v, int bit_index)
|
||||
{
|
||||
_bitvector_clear_bit(v, bit_index);
|
||||
}
|
||||
|
||||
#endif /* DATATYPES_USE_MACROS */
|
||||
|
||||
int bitvector_alloc(bitvector_t *v, unsigned long length)
|
||||
{
|
||||
unsigned long l;
|
||||
|
||||
/* Round length up to a multiple of bits_per_word */
|
||||
length =
|
||||
(length + bits_per_word - 1) & ~(unsigned long)((bits_per_word - 1));
|
||||
|
||||
l = length / bits_per_word * bytes_per_word;
|
||||
|
||||
/* allocate memory, then set parameters */
|
||||
if (l == 0) {
|
||||
v->word = NULL;
|
||||
v->length = 0;
|
||||
return -1;
|
||||
} else {
|
||||
v->word = (uint32_t *)srtp_crypto_alloc(l);
|
||||
if (v->word == NULL) {
|
||||
v->length = 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
v->length = length;
|
||||
|
||||
/* initialize bitvector to zero */
|
||||
bitvector_set_to_zero(v);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bitvector_dealloc(bitvector_t *v)
|
||||
{
|
||||
if (v->word != NULL)
|
||||
srtp_crypto_free(v->word);
|
||||
v->word = NULL;
|
||||
v->length = 0;
|
||||
}
|
||||
|
||||
void bitvector_set_to_zero(bitvector_t *x)
|
||||
{
|
||||
/* C99 guarantees that memset(0) will set the value 0 for uint32_t */
|
||||
memset(x->word, 0, x->length >> 3);
|
||||
}
|
||||
|
||||
char *bitvector_bit_string(bitvector_t *x, char *buf, int len)
|
||||
{
|
||||
int j, i;
|
||||
uint32_t mask;
|
||||
|
||||
for (j = i = 0; j < (int)(x->length >> 5) && i < len - 1; j++) {
|
||||
for (mask = 0x80000000; mask > 0; mask >>= 1) {
|
||||
if (x->word[j] & mask)
|
||||
buf[i] = '1';
|
||||
else
|
||||
buf[i] = '0';
|
||||
++i;
|
||||
if (i >= len - 1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
buf[i] = 0; /* null terminate string */
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void bitvector_left_shift(bitvector_t *x, int shift)
|
||||
{
|
||||
int i;
|
||||
const int base_index = shift >> 5;
|
||||
const int bit_index = shift & 31;
|
||||
const int word_length = x->length >> 5;
|
||||
|
||||
if (shift >= (int)x->length) {
|
||||
bitvector_set_to_zero(x);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bit_index == 0) {
|
||||
for (i = 0; i < word_length - base_index; i++)
|
||||
x->word[i] = x->word[i + base_index];
|
||||
} else {
|
||||
for (i = 0; i < word_length - base_index - 1; i++)
|
||||
x->word[i] = (x->word[i + base_index] >> bit_index) ^
|
||||
(x->word[i + base_index + 1] << (32 - bit_index));
|
||||
x->word[word_length - base_index - 1] =
|
||||
x->word[word_length - 1] >> bit_index;
|
||||
}
|
||||
|
||||
/* now wrap up the final portion */
|
||||
for (i = word_length - base_index; i < word_length; i++)
|
||||
x->word[i] = 0;
|
||||
}
|
||||
|
||||
int octet_string_is_eq(uint8_t *a, uint8_t *b, int len)
|
||||
{
|
||||
uint8_t *end = b + len;
|
||||
uint8_t accumulator = 0;
|
||||
|
||||
/*
|
||||
* We use this somewhat obscure implementation to try to ensure the running
|
||||
* time only depends on len, even accounting for compiler optimizations.
|
||||
* The accumulator ends up zero iff the strings are equal.
|
||||
*/
|
||||
while (b < end)
|
||||
accumulator |= (*a++ ^ *b++);
|
||||
|
||||
/* Return 1 if *not* equal. */
|
||||
return accumulator != 0;
|
||||
}
|
||||
|
||||
void srtp_cleanse(void *s, size_t len)
|
||||
{
|
||||
volatile unsigned char *p = (volatile unsigned char *)s;
|
||||
while (len--)
|
||||
*p++ = 0;
|
||||
}
|
||||
|
||||
void octet_string_set_to_zero(void *s, size_t len)
|
||||
{
|
||||
#ifdef OPENSSL
|
||||
OPENSSL_cleanse(s, len);
|
||||
#else
|
||||
srtp_cleanse(s, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TESTAPP_SOURCE
|
||||
|
||||
static const char b64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
static int base64_block_to_octet_triple(char *out, char *in)
|
||||
{
|
||||
unsigned char sextets[4] = { 0 };
|
||||
int j = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
char *p = strchr(b64chars, in[i]);
|
||||
if (p != NULL)
|
||||
sextets[i] = p - b64chars;
|
||||
else
|
||||
j++;
|
||||
}
|
||||
|
||||
out[0] = (sextets[0] << 2) | (sextets[1] >> 4);
|
||||
if (j < 2)
|
||||
out[1] = (sextets[1] << 4) | (sextets[2] >> 2);
|
||||
if (j < 1)
|
||||
out[2] = (sextets[2] << 6) | sextets[3];
|
||||
return j;
|
||||
}
|
||||
|
||||
int base64_string_to_octet_string(char *out, int *pad, char *in, int len)
|
||||
{
|
||||
int k = 0;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
if (len % 4 != 0)
|
||||
return 0;
|
||||
|
||||
while (i < len && j == 0) {
|
||||
j = base64_block_to_octet_triple(out + k, in + i);
|
||||
k += 3;
|
||||
i += 4;
|
||||
}
|
||||
*pad = j;
|
||||
return i;
|
||||
}
|
||||
|
||||
#endif
|
||||
211
TMessagesProj/jni/third_party/libsrtp/crypto/math/stat.c
vendored
Normal file
211
TMessagesProj/jni/third_party/libsrtp/crypto/math/stat.c
vendored
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
/*
|
||||
* stats.c
|
||||
*
|
||||
* statistical tests
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "stat.h"
|
||||
|
||||
srtp_debug_module_t srtp_mod_stat = {
|
||||
0, /* debugging is off by default */
|
||||
(char *)"stat test" /* printable module name */
|
||||
};
|
||||
|
||||
/*
|
||||
* each test assumes that 20,000 bits (2500 octets) of data is
|
||||
* provided as input
|
||||
*/
|
||||
|
||||
#define STAT_TEST_DATA_LEN 2500
|
||||
|
||||
srtp_err_status_t stat_test_monobit(uint8_t *data)
|
||||
{
|
||||
uint8_t *data_end = data + STAT_TEST_DATA_LEN;
|
||||
uint16_t ones_count;
|
||||
|
||||
ones_count = 0;
|
||||
while (data < data_end) {
|
||||
ones_count += octet_get_weight(*data);
|
||||
data++;
|
||||
}
|
||||
|
||||
debug_print(srtp_mod_stat, "bit count: %d", ones_count);
|
||||
|
||||
if ((ones_count < 9725) || (ones_count > 10275))
|
||||
return srtp_err_status_algo_fail;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t stat_test_poker(uint8_t *data)
|
||||
{
|
||||
int i;
|
||||
uint8_t *data_end = data + STAT_TEST_DATA_LEN;
|
||||
double poker;
|
||||
uint16_t f[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
while (data < data_end) {
|
||||
f[*data & 0x0f]++; /* increment freq. count for low nibble */
|
||||
f[(*data) >> 4]++; /* increment freq. count for high nibble */
|
||||
data++;
|
||||
}
|
||||
|
||||
poker = 0.0;
|
||||
for (i = 0; i < 16; i++)
|
||||
poker += (double)f[i] * f[i];
|
||||
|
||||
poker *= (16.0 / 5000.0);
|
||||
poker -= 5000.0;
|
||||
|
||||
debug_print(srtp_mod_stat, "poker test: %f\n", poker);
|
||||
|
||||
if ((poker < 2.16) || (poker > 46.17))
|
||||
return srtp_err_status_algo_fail;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* runs[i] holds the number of runs of size (i-1)
|
||||
*/
|
||||
|
||||
srtp_err_status_t stat_test_runs(uint8_t *data)
|
||||
{
|
||||
uint8_t *data_end = data + STAT_TEST_DATA_LEN;
|
||||
uint16_t runs[6] = { 0, 0, 0, 0, 0, 0 };
|
||||
uint16_t gaps[6] = { 0, 0, 0, 0, 0, 0 };
|
||||
uint16_t lo_value[6] = { 2315, 1114, 527, 240, 103, 103 };
|
||||
uint16_t hi_value[6] = { 2685, 1386, 723, 384, 209, 209 };
|
||||
int state = 0;
|
||||
uint16_t mask;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* the state variable holds the number of bits in the
|
||||
* current run (or gap, if negative)
|
||||
*/
|
||||
|
||||
while (data < data_end) {
|
||||
/* loop over the bits of this byte */
|
||||
for (mask = 1; mask < 256; mask <<= 1) {
|
||||
if (*data & mask) {
|
||||
/* next bit is a one */
|
||||
if (state > 0) {
|
||||
/* prefix is a run, so increment the run-count */
|
||||
state++;
|
||||
|
||||
/* check for long runs */
|
||||
if (state > 25) {
|
||||
debug_print(srtp_mod_stat, ">25 runs: %d", state);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
|
||||
} else if (state < 0) {
|
||||
/* prefix is a gap */
|
||||
if (state < -25) {
|
||||
debug_print(srtp_mod_stat, ">25 gaps: %d", state);
|
||||
return srtp_err_status_algo_fail; /* long-runs test
|
||||
failed */
|
||||
}
|
||||
if (state < -6) {
|
||||
state = -6; /* group together gaps > 5 */
|
||||
}
|
||||
gaps[-1 - state]++; /* increment gap count */
|
||||
state = 1; /* set state at one set bit */
|
||||
} else {
|
||||
/* state is zero; this happens only at initialization */
|
||||
state = 1;
|
||||
}
|
||||
} else {
|
||||
/* next bit is a zero */
|
||||
if (state > 0) {
|
||||
/* prefix is a run */
|
||||
if (state > 25) {
|
||||
debug_print(srtp_mod_stat, ">25 runs (2): %d", state);
|
||||
return srtp_err_status_algo_fail; /* long-runs test
|
||||
failed */
|
||||
}
|
||||
if (state > 6) {
|
||||
state = 6; /* group together runs > 5 */
|
||||
}
|
||||
runs[state - 1]++; /* increment run count */
|
||||
state = -1; /* set state at one zero bit */
|
||||
} else if (state < 0) {
|
||||
/* prefix is a gap, so increment gap-count (decrement state)
|
||||
*/
|
||||
state--;
|
||||
|
||||
/* check for long gaps */
|
||||
if (state < -25) {
|
||||
debug_print(srtp_mod_stat, ">25 gaps (2): %d", state);
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
|
||||
} else {
|
||||
/* state is zero; this happens only at initialization */
|
||||
state = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* move along to next octet */
|
||||
data++;
|
||||
}
|
||||
|
||||
if (srtp_mod_stat.on) {
|
||||
debug_print(srtp_mod_stat, "runs test", NULL);
|
||||
for (i = 0; i < 6; i++)
|
||||
debug_print(srtp_mod_stat, " runs[]: %d", runs[i]);
|
||||
for (i = 0; i < 6; i++)
|
||||
debug_print(srtp_mod_stat, " gaps[]: %d", gaps[i]);
|
||||
}
|
||||
|
||||
/* check run and gap counts against the fixed limits */
|
||||
for (i = 0; i < 6; i++)
|
||||
if ((runs[i] < lo_value[i]) || (runs[i] > hi_value[i]) ||
|
||||
(gaps[i] < lo_value[i]) || (gaps[i] > hi_value[i]))
|
||||
return srtp_err_status_algo_fail;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
135
TMessagesProj/jni/third_party/libsrtp/crypto/replay/rdb.c
vendored
Normal file
135
TMessagesProj/jni/third_party/libsrtp/crypto/replay/rdb.c
vendored
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* rdb.c
|
||||
*
|
||||
* Implements a replay database for packet security
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "rdb.h"
|
||||
|
||||
/*
|
||||
* this implementation of a replay database works as follows:
|
||||
*
|
||||
* window_start is the index of the first packet in the window
|
||||
* bitmask a bit-buffer, containing the most recently entered
|
||||
* index as the leftmost bit
|
||||
*
|
||||
*/
|
||||
|
||||
/* srtp_rdb_init initalizes rdb */
|
||||
srtp_err_status_t srtp_rdb_init(srtp_rdb_t *rdb)
|
||||
{
|
||||
v128_set_to_zero(&rdb->bitmask);
|
||||
rdb->window_start = 0;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdb_check checks to see if index appears in rdb
|
||||
*/
|
||||
srtp_err_status_t srtp_rdb_check(const srtp_rdb_t *rdb, uint32_t p_index)
|
||||
{
|
||||
/* if the index appears after (or at very end of) the window, its good */
|
||||
if (p_index >= rdb->window_start + rdb_bits_in_bitmask) {
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/* if the index appears before the window, its bad */
|
||||
if (p_index < rdb->window_start) {
|
||||
return srtp_err_status_replay_old;
|
||||
}
|
||||
|
||||
/* otherwise, the index appears within the window, so check the bitmask */
|
||||
if (v128_get_bit(&rdb->bitmask, (p_index - rdb->window_start)) == 1) {
|
||||
return srtp_err_status_replay_fail;
|
||||
}
|
||||
|
||||
/* otherwise, the index is okay */
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdb_add_index adds index to srtp_rdb_t (and does *not* check if
|
||||
* index appears in db)
|
||||
*
|
||||
* this function should be called only after srtp_rdb_check has
|
||||
* indicated that the index does not appear in the rdb, e.g., a mutex
|
||||
* should protect the rdb between these calls
|
||||
*/
|
||||
srtp_err_status_t srtp_rdb_add_index(srtp_rdb_t *rdb, uint32_t p_index)
|
||||
{
|
||||
unsigned int delta;
|
||||
|
||||
if (p_index < rdb->window_start)
|
||||
return srtp_err_status_replay_fail;
|
||||
|
||||
delta = (p_index - rdb->window_start);
|
||||
if (delta < rdb_bits_in_bitmask) {
|
||||
/* if the p_index is within the window, set the appropriate bit */
|
||||
v128_set_bit(&rdb->bitmask, delta);
|
||||
|
||||
} else {
|
||||
delta -= rdb_bits_in_bitmask - 1;
|
||||
|
||||
/* shift the window forward by delta bits*/
|
||||
v128_left_shift(&rdb->bitmask, delta);
|
||||
v128_set_bit(&rdb->bitmask, rdb_bits_in_bitmask - 1);
|
||||
rdb->window_start += delta;
|
||||
}
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_rdb_increment(srtp_rdb_t *rdb)
|
||||
{
|
||||
if (rdb->window_start >= 0x7fffffff) {
|
||||
return srtp_err_status_key_expired;
|
||||
}
|
||||
++rdb->window_start;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
uint32_t srtp_rdb_get_value(const srtp_rdb_t *rdb)
|
||||
{
|
||||
return rdb->window_start;
|
||||
}
|
||||
384
TMessagesProj/jni/third_party/libsrtp/crypto/replay/rdbx.c
vendored
Normal file
384
TMessagesProj/jni/third_party/libsrtp/crypto/replay/rdbx.c
vendored
Normal file
|
|
@ -0,0 +1,384 @@
|
|||
/*
|
||||
* rdbx.c
|
||||
*
|
||||
* a replay database with extended range, using a rollover counter
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "rdbx.h"
|
||||
|
||||
/*
|
||||
* from RFC 3711:
|
||||
*
|
||||
* A receiver reconstructs the index i of a packet with sequence
|
||||
* number SEQ using the estimate
|
||||
*
|
||||
* i = 2^16 * v + SEQ,
|
||||
*
|
||||
* where v is chosen from the set { ROC-1, ROC, ROC+1 } such that i is
|
||||
* closest to the value 2^16 * ROC + s_l. If the value r+1 is used,
|
||||
* then the rollover counter r in the cryptographic context is
|
||||
* incremented by one (if the packet containing s is authentic).
|
||||
*/
|
||||
|
||||
/*
|
||||
* rdbx implementation notes
|
||||
*
|
||||
* A srtp_xtd_seq_num_t is essentially a sequence number for which some of
|
||||
* the data on the wire are implicit. It logically consists of a
|
||||
* rollover counter and a sequence number; the sequence number is the
|
||||
* explicit part, and the rollover counter is the implicit part.
|
||||
*
|
||||
* Upon receiving a sequence_number (e.g. in a newly received SRTP
|
||||
* packet), the complete srtp_xtd_seq_num_t can be estimated by using a
|
||||
* local srtp_xtd_seq_num_t as a basis. This is done using the function
|
||||
* srtp_index_guess(&local, &guess, seq_from_packet). This function
|
||||
* returns the difference of the guess and the local value. The local
|
||||
* srtp_xtd_seq_num_t can be moved forward to the guess using the function
|
||||
* srtp_index_advance(&guess, delta), where delta is the difference.
|
||||
*
|
||||
*
|
||||
* A srtp_rdbx_t consists of a srtp_xtd_seq_num_t and a bitmask. The index is
|
||||
* highest sequence number that has been received, and the bitmask indicates
|
||||
* which of the recent indicies have been received as well. The
|
||||
* highest bit in the bitmask corresponds to the index in the bitmask.
|
||||
*/
|
||||
|
||||
void srtp_index_init(srtp_xtd_seq_num_t *pi)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
*pi = make64(0, 0);
|
||||
#else
|
||||
*pi = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void srtp_index_advance(srtp_xtd_seq_num_t *pi, srtp_sequence_number_t s)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
/* a > ~b means a+b will generate a carry */
|
||||
/* s is uint16 here */
|
||||
*pi = make64(high32(*pi) + (s > ~low32(*pi) ? 1 : 0), low32(*pi) + s);
|
||||
#else
|
||||
*pi += s;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_index_guess(local, guess, s)
|
||||
*
|
||||
* given a srtp_xtd_seq_num_t local (which represents the last
|
||||
* known-to-be-good received srtp_xtd_seq_num_t) and a sequence number s
|
||||
* (from a newly arrived packet), sets the contents of *guess to
|
||||
* contain the best guess of the packet index to which s corresponds,
|
||||
* and returns the difference between *guess and *local
|
||||
*
|
||||
* nota bene - the output is a signed integer, DON'T cast it to a
|
||||
* unsigned integer!
|
||||
*/
|
||||
|
||||
int32_t srtp_index_guess(const srtp_xtd_seq_num_t *local,
|
||||
srtp_xtd_seq_num_t *guess,
|
||||
srtp_sequence_number_t s)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
uint32_t local_roc = ((high32(*local) << 16) | (low32(*local) >> 16));
|
||||
uint16_t local_seq = (uint16_t)(low32(*local));
|
||||
#else
|
||||
uint32_t local_roc = (uint32_t)(*local >> 16);
|
||||
uint16_t local_seq = (uint16_t)*local;
|
||||
#endif
|
||||
uint32_t guess_roc;
|
||||
uint16_t guess_seq;
|
||||
int32_t difference;
|
||||
|
||||
if (local_seq < seq_num_median) {
|
||||
if (s - local_seq > seq_num_median) {
|
||||
guess_roc = local_roc - 1;
|
||||
difference = s - local_seq - seq_num_max;
|
||||
} else {
|
||||
guess_roc = local_roc;
|
||||
difference = s - local_seq;
|
||||
}
|
||||
} else {
|
||||
if (local_seq - seq_num_median > s) {
|
||||
guess_roc = local_roc + 1;
|
||||
difference = s - local_seq + seq_num_max;
|
||||
} else {
|
||||
guess_roc = local_roc;
|
||||
difference = s - local_seq;
|
||||
}
|
||||
}
|
||||
guess_seq = s;
|
||||
|
||||
/* Note: guess_roc is 32 bits, so this generates a 48-bit result! */
|
||||
#ifdef NO_64BIT_MATH
|
||||
*guess = make64(guess_roc >> 16, (guess_roc << 16) | guess_seq);
|
||||
#else
|
||||
*guess = (((uint64_t)guess_roc) << 16) | guess_seq;
|
||||
#endif
|
||||
|
||||
return difference;
|
||||
}
|
||||
|
||||
/*
|
||||
* rdbx
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* srtp_rdbx_init(&r, ws) initializes the srtp_rdbx_t pointed to by r with
|
||||
* window size ws
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_init(srtp_rdbx_t *rdbx, unsigned long ws)
|
||||
{
|
||||
if (ws == 0) {
|
||||
return srtp_err_status_bad_param;
|
||||
}
|
||||
|
||||
if (bitvector_alloc(&rdbx->bitmask, ws) != 0) {
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
srtp_index_init(&rdbx->index);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_dealloc(&r) frees memory for the srtp_rdbx_t pointed to by r
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_dealloc(srtp_rdbx_t *rdbx)
|
||||
{
|
||||
bitvector_dealloc(&rdbx->bitmask);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_set_roc(rdbx, roc) initalizes the srtp_rdbx_t at the location rdbx
|
||||
* to have the rollover counter value roc. If that value is less than
|
||||
* the current rollover counter value, then the function returns
|
||||
* srtp_err_status_replay_old; otherwise, srtp_err_status_ok is returned.
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_set_roc(srtp_rdbx_t *rdbx, uint32_t roc)
|
||||
{
|
||||
bitvector_set_to_zero(&rdbx->bitmask);
|
||||
|
||||
#ifdef NO_64BIT_MATH
|
||||
#error not yet implemented
|
||||
#else
|
||||
|
||||
/* make sure that we're not moving backwards */
|
||||
if (roc < (rdbx->index >> 16)) {
|
||||
return srtp_err_status_replay_old;
|
||||
}
|
||||
|
||||
rdbx->index &= 0xffff; /* retain lowest 16 bits */
|
||||
rdbx->index |= ((uint64_t)roc) << 16; /* set ROC */
|
||||
#endif
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_get_packet_index(rdbx) returns the value of the packet index
|
||||
* for the srtp_rdbx_t pointed to by rdbx
|
||||
*
|
||||
*/
|
||||
srtp_xtd_seq_num_t srtp_rdbx_get_packet_index(const srtp_rdbx_t *rdbx)
|
||||
{
|
||||
return rdbx->index;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_get_window_size(rdbx) returns the value of the window size
|
||||
* for the srtp_rdbx_t pointed to by rdbx
|
||||
*
|
||||
*/
|
||||
unsigned long srtp_rdbx_get_window_size(const srtp_rdbx_t *rdbx)
|
||||
{
|
||||
return bitvector_get_length(&rdbx->bitmask);
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_check(&r, delta) checks to see if the srtp_xtd_seq_num_t
|
||||
* which is at rdbx->index + delta is in the rdb
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_check(const srtp_rdbx_t *rdbx, int delta)
|
||||
{
|
||||
if (delta > 0) { /* if delta is positive, it's good */
|
||||
return srtp_err_status_ok;
|
||||
} else if ((int)(bitvector_get_length(&rdbx->bitmask) - 1) + delta < 0) {
|
||||
/* if delta is lower than the bitmask, it's bad */
|
||||
return srtp_err_status_replay_old;
|
||||
} else if (bitvector_get_bit(
|
||||
&rdbx->bitmask,
|
||||
(int)(bitvector_get_length(&rdbx->bitmask) - 1) + delta) ==
|
||||
1) {
|
||||
/* delta is within the window, so check the bitmask */
|
||||
return srtp_err_status_replay_fail;
|
||||
}
|
||||
/* otherwise, the index is okay */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_add_index adds the srtp_xtd_seq_num_t at rdbx->window_start + d to
|
||||
* replay_db (and does *not* check if that srtp_xtd_seq_num_t appears in db)
|
||||
*
|
||||
* this function should be called only after replay_check has
|
||||
* indicated that the index does not appear in the rdbx, e.g., a mutex
|
||||
* should protect the rdbx between these calls if need be
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_add_index(srtp_rdbx_t *rdbx, int delta)
|
||||
{
|
||||
if (delta > 0) {
|
||||
/* shift forward by delta */
|
||||
srtp_index_advance(&rdbx->index, delta);
|
||||
bitvector_left_shift(&rdbx->bitmask, delta);
|
||||
bitvector_set_bit(&rdbx->bitmask,
|
||||
bitvector_get_length(&rdbx->bitmask) - 1);
|
||||
} else {
|
||||
/* delta is in window */
|
||||
bitvector_set_bit(&rdbx->bitmask,
|
||||
bitvector_get_length(&rdbx->bitmask) - 1 + delta);
|
||||
}
|
||||
|
||||
/* note that we need not consider the case that delta == 0 */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_estimate_index(rdbx, guess, s)
|
||||
*
|
||||
* given an rdbx and a sequence number s (from a newly arrived packet),
|
||||
* sets the contents of *guess to contain the best guess of the packet
|
||||
* index to which s corresponds, and returns the difference between
|
||||
* *guess and the locally stored synch info
|
||||
*/
|
||||
int32_t srtp_rdbx_estimate_index(const srtp_rdbx_t *rdbx,
|
||||
srtp_xtd_seq_num_t *guess,
|
||||
srtp_sequence_number_t s)
|
||||
{
|
||||
/*
|
||||
* if the sequence number and rollover counter in the rdbx are
|
||||
* non-zero, then use the srtp_index_guess(...) function, otherwise, just
|
||||
* set the rollover counter to zero (since the srtp_index_guess(...)
|
||||
* function might incorrectly guess that the rollover counter is
|
||||
* 0xffffffff)
|
||||
*/
|
||||
|
||||
#ifdef NO_64BIT_MATH
|
||||
/* seq_num_median = 0x8000 */
|
||||
if (high32(rdbx->index) > 0 || low32(rdbx->index) > seq_num_median)
|
||||
#else
|
||||
if (rdbx->index > seq_num_median)
|
||||
#endif
|
||||
{
|
||||
return srtp_index_guess(&rdbx->index, guess, s);
|
||||
}
|
||||
|
||||
#ifdef NO_64BIT_MATH
|
||||
*guess = make64(0, (uint32_t)s);
|
||||
#else
|
||||
*guess = s;
|
||||
#endif
|
||||
|
||||
#ifdef NO_64BIT_MATH
|
||||
return s - (uint16_t)low32(rdbx->index);
|
||||
#else
|
||||
return s - (uint16_t)rdbx->index;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_get_roc(rdbx)
|
||||
*
|
||||
* Get the current rollover counter
|
||||
*
|
||||
*/
|
||||
uint32_t srtp_rdbx_get_roc(const srtp_rdbx_t *rdbx)
|
||||
{
|
||||
uint32_t roc;
|
||||
|
||||
#ifdef NO_64BIT_MATH
|
||||
roc = ((high32(rdbx->index) << 16) | (low32(rdbx->index) >> 16));
|
||||
#else
|
||||
roc = (uint32_t)(rdbx->index >> 16);
|
||||
#endif
|
||||
|
||||
return roc;
|
||||
}
|
||||
|
||||
/*
|
||||
* srtp_rdbx_set_roc_seq(rdbx, roc, seq) initalizes the srtp_rdbx_t at the
|
||||
* location rdbx to have the rollover counter value roc and packet sequence
|
||||
* number seq. If the new rollover counter value is less than the current
|
||||
* rollover counter value, then the function returns
|
||||
* srtp_err_status_replay_old, otherwise, srtp_err_status_ok is returned.
|
||||
*/
|
||||
srtp_err_status_t srtp_rdbx_set_roc_seq(srtp_rdbx_t *rdbx,
|
||||
uint32_t roc,
|
||||
uint16_t seq)
|
||||
{
|
||||
#ifdef NO_64BIT_MATH
|
||||
#error not yet implemented
|
||||
#else
|
||||
|
||||
/* make sure that we're not moving backwards */
|
||||
if (roc < (rdbx->index >> 16)) {
|
||||
return srtp_err_status_replay_old;
|
||||
}
|
||||
|
||||
rdbx->index = seq;
|
||||
rdbx->index |= ((uint64_t)roc) << 16; /* set ROC */
|
||||
#endif
|
||||
|
||||
bitvector_set_to_zero(&rdbx->bitmask);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
101
TMessagesProj/jni/third_party/libsrtp/crypto/replay/ut_sim.c
vendored
Normal file
101
TMessagesProj/jni/third_party/libsrtp/crypto/replay/ut_sim.c
vendored
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* ut_sim.c
|
||||
*
|
||||
* an unreliable transport simulator
|
||||
* (for testing replay databases and suchlike)
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "ut_sim.h"
|
||||
|
||||
int ut_compar(const void *a, const void *b)
|
||||
{
|
||||
return rand() > (RAND_MAX / 2) ? -1 : 1;
|
||||
}
|
||||
|
||||
void ut_init(ut_connection *utc)
|
||||
{
|
||||
int i;
|
||||
utc->index = 0;
|
||||
|
||||
for (i = 0; i < UT_BUF; i++)
|
||||
utc->buffer[i] = i;
|
||||
|
||||
qsort(utc->buffer, UT_BUF, sizeof(uint32_t), ut_compar);
|
||||
|
||||
utc->index = UT_BUF - 1;
|
||||
}
|
||||
|
||||
uint32_t ut_next_index(ut_connection *utc)
|
||||
{
|
||||
uint32_t tmp;
|
||||
|
||||
tmp = utc->buffer[0];
|
||||
utc->index++;
|
||||
utc->buffer[0] = utc->index;
|
||||
|
||||
qsort(utc->buffer, UT_BUF, sizeof(uint32_t), ut_compar);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
#ifdef UT_TEST
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
uint32_t i, irecvd, idiff;
|
||||
ut_connection utc;
|
||||
|
||||
ut_init(&utc);
|
||||
|
||||
for (i = 0; i < 1000; i++) {
|
||||
irecvd = ut_next_index(&utc);
|
||||
idiff = i - irecvd;
|
||||
printf("%lu\t%lu\t%d\n", i, irecvd, idiff);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
608
TMessagesProj/jni/third_party/libsrtp/crypto/test/cipher_driver.c
vendored
Normal file
608
TMessagesProj/jni/third_party/libsrtp/crypto/test/cipher_driver.c
vendored
Normal file
|
|
@ -0,0 +1,608 @@
|
|||
/*
|
||||
* cipher_driver.c
|
||||
*
|
||||
* A driver for the generic cipher type
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h> /* for printf() */
|
||||
#include <stdlib.h> /* for rand() */
|
||||
#include "getopt_s.h"
|
||||
#include "cipher.h"
|
||||
#ifdef OPENSSL
|
||||
#include "aes_icm_ossl.h"
|
||||
#include "aes_gcm_ossl.h"
|
||||
#else
|
||||
#include "aes_icm.h"
|
||||
#endif
|
||||
|
||||
#define PRINT_DEBUG 0
|
||||
|
||||
void cipher_driver_test_throughput(srtp_cipher_t *c);
|
||||
|
||||
srtp_err_status_t cipher_driver_self_test(srtp_cipher_type_t *ct);
|
||||
|
||||
/*
|
||||
* cipher_driver_test_buffering(ct) tests the cipher's output
|
||||
* buffering for correctness by checking the consistency of succesive
|
||||
* calls
|
||||
*/
|
||||
|
||||
srtp_err_status_t cipher_driver_test_buffering(srtp_cipher_t *c);
|
||||
|
||||
/*
|
||||
* functions for testing cipher cache thrash
|
||||
*/
|
||||
srtp_err_status_t cipher_driver_test_array_throughput(srtp_cipher_type_t *ct,
|
||||
int klen,
|
||||
int num_cipher);
|
||||
|
||||
void cipher_array_test_throughput(srtp_cipher_t *ca[], int num_cipher);
|
||||
|
||||
uint64_t cipher_array_bits_per_second(srtp_cipher_t *cipher_array[],
|
||||
int num_cipher,
|
||||
unsigned octets_in_buffer,
|
||||
int num_trials);
|
||||
|
||||
srtp_err_status_t cipher_array_delete(srtp_cipher_t *cipher_array[],
|
||||
int num_cipher);
|
||||
|
||||
srtp_err_status_t cipher_array_alloc_init(srtp_cipher_t ***cipher_array,
|
||||
int num_ciphers,
|
||||
srtp_cipher_type_t *ctype,
|
||||
int klen);
|
||||
|
||||
void usage(char *prog_name)
|
||||
{
|
||||
printf("usage: %s [ -t | -v | -a ]\n", prog_name);
|
||||
exit(255);
|
||||
}
|
||||
|
||||
void check_status(srtp_err_status_t s)
|
||||
{
|
||||
if (s) {
|
||||
printf("error (code %d)\n", s);
|
||||
exit(s);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* null_cipher and srtp_aes_icm are the cipher meta-objects
|
||||
* defined in the files in crypto/cipher subdirectory. these are
|
||||
* declared external so that we can use these cipher types here
|
||||
*/
|
||||
|
||||
extern srtp_cipher_type_t srtp_null_cipher;
|
||||
extern srtp_cipher_type_t srtp_aes_icm_128;
|
||||
extern srtp_cipher_type_t srtp_aes_icm_256;
|
||||
#ifdef OPENSSL
|
||||
extern srtp_cipher_type_t srtp_aes_icm_192;
|
||||
extern srtp_cipher_type_t srtp_aes_gcm_128_openssl;
|
||||
extern srtp_cipher_type_t srtp_aes_gcm_256_openssl;
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
srtp_cipher_t *c = NULL;
|
||||
srtp_err_status_t status;
|
||||
/* clang-format off */
|
||||
unsigned char test_key[48] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
};
|
||||
/* clang-format on */
|
||||
int q;
|
||||
unsigned do_timing_test = 0;
|
||||
unsigned do_validation = 0;
|
||||
unsigned do_array_timing_test = 0;
|
||||
|
||||
/* process input arguments */
|
||||
while (1) {
|
||||
q = getopt_s(argc, argv, "tva");
|
||||
if (q == -1)
|
||||
break;
|
||||
switch (q) {
|
||||
case 't':
|
||||
do_timing_test = 1;
|
||||
break;
|
||||
case 'v':
|
||||
do_validation = 1;
|
||||
break;
|
||||
case 'a':
|
||||
do_array_timing_test = 1;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
printf("cipher test driver\n"
|
||||
"David A. McGrew\n"
|
||||
"Cisco Systems, Inc.\n");
|
||||
|
||||
if (!do_validation && !do_timing_test && !do_array_timing_test)
|
||||
usage(argv[0]);
|
||||
|
||||
/* arry timing (cache thrash) test */
|
||||
if (do_array_timing_test) {
|
||||
int max_num_cipher = 1 << 16; /* number of ciphers in cipher_array */
|
||||
int num_cipher;
|
||||
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8)
|
||||
cipher_driver_test_array_throughput(&srtp_null_cipher, 0,
|
||||
num_cipher);
|
||||
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8)
|
||||
cipher_driver_test_array_throughput(
|
||||
&srtp_aes_icm_128, SRTP_AES_ICM_128_KEY_LEN_WSALT, num_cipher);
|
||||
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8)
|
||||
cipher_driver_test_array_throughput(
|
||||
&srtp_aes_icm_256, SRTP_AES_ICM_256_KEY_LEN_WSALT, num_cipher);
|
||||
|
||||
#ifdef OPENSSL
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8)
|
||||
cipher_driver_test_array_throughput(
|
||||
&srtp_aes_icm_192, SRTP_AES_ICM_192_KEY_LEN_WSALT, num_cipher);
|
||||
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8) {
|
||||
cipher_driver_test_array_throughput(&srtp_aes_gcm_128_openssl,
|
||||
SRTP_AES_GCM_128_KEY_LEN_WSALT,
|
||||
num_cipher);
|
||||
}
|
||||
|
||||
for (num_cipher = 1; num_cipher < max_num_cipher; num_cipher *= 8) {
|
||||
cipher_driver_test_array_throughput(&srtp_aes_gcm_256_openssl,
|
||||
SRTP_AES_GCM_256_KEY_LEN_WSALT,
|
||||
num_cipher);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (do_validation) {
|
||||
cipher_driver_self_test(&srtp_null_cipher);
|
||||
cipher_driver_self_test(&srtp_aes_icm_128);
|
||||
cipher_driver_self_test(&srtp_aes_icm_256);
|
||||
#ifdef OPENSSL
|
||||
cipher_driver_self_test(&srtp_aes_icm_192);
|
||||
cipher_driver_self_test(&srtp_aes_gcm_128_openssl);
|
||||
cipher_driver_self_test(&srtp_aes_gcm_256_openssl);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* do timing and/or buffer_test on srtp_null_cipher */
|
||||
status = srtp_cipher_type_alloc(&srtp_null_cipher, &c, 0, 0);
|
||||
check_status(status);
|
||||
|
||||
status = srtp_cipher_init(c, NULL);
|
||||
check_status(status);
|
||||
|
||||
if (do_timing_test)
|
||||
cipher_driver_test_throughput(c);
|
||||
if (do_validation) {
|
||||
status = cipher_driver_test_buffering(c);
|
||||
check_status(status);
|
||||
}
|
||||
status = srtp_cipher_dealloc(c);
|
||||
check_status(status);
|
||||
|
||||
/* run the throughput test on the aes_icm cipher (128-bit key) */
|
||||
status = srtp_cipher_type_alloc(&srtp_aes_icm_128, &c,
|
||||
SRTP_AES_ICM_128_KEY_LEN_WSALT, 0);
|
||||
if (status) {
|
||||
fprintf(stderr, "error: can't allocate cipher\n");
|
||||
exit(status);
|
||||
}
|
||||
|
||||
status = srtp_cipher_init(c, test_key);
|
||||
check_status(status);
|
||||
|
||||
if (do_timing_test)
|
||||
cipher_driver_test_throughput(c);
|
||||
|
||||
if (do_validation) {
|
||||
status = cipher_driver_test_buffering(c);
|
||||
check_status(status);
|
||||
}
|
||||
|
||||
status = srtp_cipher_dealloc(c);
|
||||
check_status(status);
|
||||
|
||||
/* repeat the tests with 256-bit keys */
|
||||
status = srtp_cipher_type_alloc(&srtp_aes_icm_256, &c,
|
||||
SRTP_AES_ICM_256_KEY_LEN_WSALT, 0);
|
||||
if (status) {
|
||||
fprintf(stderr, "error: can't allocate cipher\n");
|
||||
exit(status);
|
||||
}
|
||||
|
||||
status = srtp_cipher_init(c, test_key);
|
||||
check_status(status);
|
||||
|
||||
if (do_timing_test)
|
||||
cipher_driver_test_throughput(c);
|
||||
|
||||
if (do_validation) {
|
||||
status = cipher_driver_test_buffering(c);
|
||||
check_status(status);
|
||||
}
|
||||
|
||||
status = srtp_cipher_dealloc(c);
|
||||
check_status(status);
|
||||
|
||||
#ifdef OPENSSL
|
||||
/* run the throughput test on the aes_gcm_128_openssl cipher */
|
||||
status = srtp_cipher_type_alloc(&srtp_aes_gcm_128_openssl, &c,
|
||||
SRTP_AES_GCM_128_KEY_LEN_WSALT, 8);
|
||||
if (status) {
|
||||
fprintf(stderr, "error: can't allocate GCM 128 cipher\n");
|
||||
exit(status);
|
||||
}
|
||||
status = srtp_cipher_init(c, test_key);
|
||||
check_status(status);
|
||||
if (do_timing_test) {
|
||||
cipher_driver_test_throughput(c);
|
||||
}
|
||||
|
||||
if (do_validation) {
|
||||
status = cipher_driver_test_buffering(c);
|
||||
check_status(status);
|
||||
}
|
||||
status = srtp_cipher_dealloc(c);
|
||||
check_status(status);
|
||||
|
||||
/* run the throughput test on the aes_gcm_256_openssl cipher */
|
||||
status = srtp_cipher_type_alloc(&srtp_aes_gcm_256_openssl, &c,
|
||||
SRTP_AES_GCM_256_KEY_LEN_WSALT, 16);
|
||||
if (status) {
|
||||
fprintf(stderr, "error: can't allocate GCM 256 cipher\n");
|
||||
exit(status);
|
||||
}
|
||||
status = srtp_cipher_init(c, test_key);
|
||||
check_status(status);
|
||||
if (do_timing_test) {
|
||||
cipher_driver_test_throughput(c);
|
||||
}
|
||||
|
||||
if (do_validation) {
|
||||
status = cipher_driver_test_buffering(c);
|
||||
check_status(status);
|
||||
}
|
||||
status = srtp_cipher_dealloc(c);
|
||||
check_status(status);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cipher_driver_test_throughput(srtp_cipher_t *c)
|
||||
{
|
||||
int i;
|
||||
int min_enc_len = 32;
|
||||
int max_enc_len = 2048; /* should be a power of two */
|
||||
int num_trials = 1000000;
|
||||
|
||||
printf("timing %s throughput, key length %d:\n", c->type->description,
|
||||
c->key_len);
|
||||
fflush(stdout);
|
||||
for (i = min_enc_len; i <= max_enc_len; i = i * 2)
|
||||
printf("msg len: %d\tgigabits per second: %f\n", i,
|
||||
srtp_cipher_bits_per_second(c, i, num_trials) / 1e9);
|
||||
}
|
||||
|
||||
srtp_err_status_t cipher_driver_self_test(srtp_cipher_type_t *ct)
|
||||
{
|
||||
srtp_err_status_t status;
|
||||
|
||||
printf("running cipher self-test for %s...", ct->description);
|
||||
status = srtp_cipher_type_self_test(ct);
|
||||
if (status) {
|
||||
printf("failed with error code %d\n", status);
|
||||
exit(status);
|
||||
}
|
||||
printf("passed\n");
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* cipher_driver_test_buffering(ct) tests the cipher's output
|
||||
* buffering for correctness by checking the consistency of succesive
|
||||
* calls
|
||||
*/
|
||||
|
||||
#define INITIAL_BUFLEN 1024
|
||||
srtp_err_status_t cipher_driver_test_buffering(srtp_cipher_t *c)
|
||||
{
|
||||
int i, j, num_trials = 1000;
|
||||
unsigned len, buflen = INITIAL_BUFLEN;
|
||||
uint8_t buffer0[INITIAL_BUFLEN], buffer1[INITIAL_BUFLEN], *current, *end;
|
||||
uint8_t idx[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34 };
|
||||
srtp_err_status_t status;
|
||||
|
||||
printf("testing output buffering for cipher %s...", c->type->description);
|
||||
|
||||
for (i = 0; i < num_trials; i++) {
|
||||
/* set buffers to zero */
|
||||
for (j = 0; j < (int)buflen; j++) {
|
||||
buffer0[j] = buffer1[j] = 0;
|
||||
}
|
||||
|
||||
/* initialize cipher */
|
||||
status = srtp_cipher_set_iv(c, (uint8_t *)idx, srtp_direction_encrypt);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* generate 'reference' value by encrypting all at once */
|
||||
status = srtp_cipher_encrypt(c, buffer0, &buflen);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* re-initialize cipher */
|
||||
status = srtp_cipher_set_iv(c, (uint8_t *)idx, srtp_direction_encrypt);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* now loop over short lengths until buffer1 is encrypted */
|
||||
current = buffer1;
|
||||
end = buffer1 + buflen;
|
||||
while (current < end) {
|
||||
/* choose a short length */
|
||||
len = rand() & 0x01f;
|
||||
|
||||
/* make sure that len doesn't cause us to overreach the buffer */
|
||||
if (current + len > end)
|
||||
len = end - current;
|
||||
|
||||
status = srtp_cipher_encrypt(c, current, &len);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* advance pointer into buffer1 to reflect encryption */
|
||||
current += len;
|
||||
|
||||
/* if buffer1 is all encrypted, break out of loop */
|
||||
if (current == end)
|
||||
break;
|
||||
}
|
||||
|
||||
/* compare buffers */
|
||||
for (j = 0; j < (int)buflen; j++) {
|
||||
if (buffer0[j] != buffer1[j]) {
|
||||
#if PRINT_DEBUG
|
||||
printf("test case %d failed at byte %d\n", i, j);
|
||||
printf("computed: %s\n",
|
||||
octet_string_hex_string(buffer1, buflen));
|
||||
printf("expected: %s\n",
|
||||
octet_string_hex_string(buffer0, buflen));
|
||||
#endif
|
||||
return srtp_err_status_algo_fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("passed\n");
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* The function cipher_test_throughput_array() tests the effect of CPU
|
||||
* cache thrash on cipher throughput.
|
||||
*
|
||||
* cipher_array_alloc_init(ctype, array, num_ciphers) creates an array
|
||||
* of srtp_cipher_t of type ctype
|
||||
*/
|
||||
|
||||
srtp_err_status_t cipher_array_alloc_init(srtp_cipher_t ***ca,
|
||||
int num_ciphers,
|
||||
srtp_cipher_type_t *ctype,
|
||||
int klen)
|
||||
{
|
||||
int i, j;
|
||||
srtp_err_status_t status;
|
||||
uint8_t *key;
|
||||
srtp_cipher_t **cipher_array;
|
||||
/* pad klen allocation, to handle aes_icm reading 16 bytes for the
|
||||
14-byte salt */
|
||||
int klen_pad = ((klen + 15) >> 4) << 4;
|
||||
|
||||
/* allocate array of pointers to ciphers */
|
||||
cipher_array = (srtp_cipher_t **)srtp_crypto_alloc(sizeof(srtp_cipher_t *) *
|
||||
num_ciphers);
|
||||
if (cipher_array == NULL)
|
||||
return srtp_err_status_alloc_fail;
|
||||
|
||||
/* set ca to location of cipher_array */
|
||||
*ca = cipher_array;
|
||||
|
||||
/* allocate key */
|
||||
key = srtp_crypto_alloc(klen_pad);
|
||||
if (key == NULL) {
|
||||
srtp_crypto_free(cipher_array);
|
||||
return srtp_err_status_alloc_fail;
|
||||
}
|
||||
|
||||
/* allocate and initialize an array of ciphers */
|
||||
for (i = 0; i < num_ciphers; i++) {
|
||||
/* allocate cipher */
|
||||
status = srtp_cipher_type_alloc(ctype, cipher_array, klen, 16);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* generate random key and initialize cipher */
|
||||
for (j = 0; j < klen; j++)
|
||||
key[j] = (uint8_t)rand();
|
||||
for (; j < klen_pad; j++)
|
||||
key[j] = 0;
|
||||
status = srtp_cipher_init(*cipher_array, key);
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
/* printf("%dth cipher is at %p\n", i, *cipher_array); */
|
||||
/* printf("%dth cipher description: %s\n", i, */
|
||||
/* (*cipher_array)->type->description); */
|
||||
|
||||
/* advance cipher array pointer */
|
||||
cipher_array++;
|
||||
}
|
||||
|
||||
srtp_crypto_free(key);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t cipher_array_delete(srtp_cipher_t *cipher_array[],
|
||||
int num_cipher)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_cipher; i++) {
|
||||
srtp_cipher_dealloc(cipher_array[i]);
|
||||
}
|
||||
|
||||
srtp_crypto_free(cipher_array);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* cipher_array_bits_per_second(c, l, t) computes (an estimate of) the
|
||||
* number of bits that a cipher implementation can encrypt in a second
|
||||
* when distinct keys are used to encrypt distinct messages
|
||||
*
|
||||
* c is a cipher (which MUST be allocated an initialized already), l
|
||||
* is the length in octets of the test data to be encrypted, and t is
|
||||
* the number of trials
|
||||
*
|
||||
* if an error is encountered, the value 0 is returned
|
||||
*/
|
||||
|
||||
uint64_t cipher_array_bits_per_second(srtp_cipher_t *cipher_array[],
|
||||
int num_cipher,
|
||||
unsigned octets_in_buffer,
|
||||
int num_trials)
|
||||
{
|
||||
int i;
|
||||
v128_t nonce;
|
||||
clock_t timer;
|
||||
unsigned char *enc_buf;
|
||||
int cipher_index = rand() % num_cipher;
|
||||
|
||||
/* Over-alloc, for NIST CBC padding */
|
||||
enc_buf = srtp_crypto_alloc(octets_in_buffer + 17);
|
||||
if (enc_buf == NULL)
|
||||
return 0; /* indicate bad parameters by returning null */
|
||||
|
||||
/* time repeated trials */
|
||||
v128_set_to_zero(&nonce);
|
||||
timer = clock();
|
||||
for (i = 0; i < num_trials; i++, nonce.v32[3] = i) {
|
||||
/* length parameter to srtp_cipher_encrypt is in/out -- out is total,
|
||||
* padded
|
||||
* length -- so reset it each time. */
|
||||
unsigned octets_to_encrypt = octets_in_buffer;
|
||||
|
||||
/* encrypt buffer with cipher */
|
||||
srtp_cipher_set_iv(cipher_array[cipher_index], (uint8_t *)&nonce,
|
||||
srtp_direction_encrypt);
|
||||
srtp_cipher_encrypt(cipher_array[cipher_index], enc_buf,
|
||||
&octets_to_encrypt);
|
||||
|
||||
/* choose a cipher at random from the array*/
|
||||
cipher_index = (*((uint32_t *)enc_buf)) % num_cipher;
|
||||
}
|
||||
timer = clock() - timer;
|
||||
|
||||
srtp_crypto_free(enc_buf);
|
||||
|
||||
if (timer == 0) {
|
||||
/* Too fast! */
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint64_t)CLOCKS_PER_SEC * num_trials * 8 * octets_in_buffer / timer;
|
||||
}
|
||||
|
||||
void cipher_array_test_throughput(srtp_cipher_t *ca[], int num_cipher)
|
||||
{
|
||||
int i;
|
||||
int min_enc_len = 16;
|
||||
int max_enc_len = 2048; /* should be a power of two */
|
||||
int num_trials = 1000000;
|
||||
|
||||
printf("timing %s throughput with key length %d, array size %d:\n",
|
||||
(ca[0])->type->description, (ca[0])->key_len, num_cipher);
|
||||
fflush(stdout);
|
||||
for (i = min_enc_len; i <= max_enc_len; i = i * 4)
|
||||
printf("msg len: %d\tgigabits per second: %f\n", i,
|
||||
cipher_array_bits_per_second(ca, num_cipher, i, num_trials) /
|
||||
1e9);
|
||||
}
|
||||
|
||||
srtp_err_status_t cipher_driver_test_array_throughput(srtp_cipher_type_t *ct,
|
||||
int klen,
|
||||
int num_cipher)
|
||||
{
|
||||
srtp_cipher_t **ca = NULL;
|
||||
srtp_err_status_t status;
|
||||
|
||||
status = cipher_array_alloc_init(&ca, num_cipher, ct, klen);
|
||||
if (status) {
|
||||
printf("error: cipher_array_alloc_init() failed with error code %d\n",
|
||||
status);
|
||||
return status;
|
||||
}
|
||||
|
||||
cipher_array_test_throughput(ca, num_cipher);
|
||||
|
||||
cipher_array_delete(ca, num_cipher);
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
228
TMessagesProj/jni/third_party/libsrtp/crypto/test/datatypes_driver.c
vendored
Normal file
228
TMessagesProj/jni/third_party/libsrtp/crypto/test/datatypes_driver.c
vendored
Normal file
|
|
@ -0,0 +1,228 @@
|
|||
/*
|
||||
* datatypes_driver.c
|
||||
*
|
||||
* a test driver for crypto/math datatypes
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h> /* for printf() */
|
||||
#include <string.h> /* for strlen() */
|
||||
#include "datatypes.h"
|
||||
#include "util.h"
|
||||
|
||||
void byte_order(void);
|
||||
|
||||
void test_hex_string_funcs(void);
|
||||
|
||||
void print_string(char *s);
|
||||
|
||||
void test_bswap(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/*
|
||||
* this program includes various and sundry tests for fundamental
|
||||
* datatypes. it's a grab-bag of throwaway code, retained only in
|
||||
* case of future problems
|
||||
*/
|
||||
|
||||
int i, j;
|
||||
v128_t x;
|
||||
char *r = "The Moving Finger writes; and, having writ,\n"
|
||||
"Moves on: nor all thy Piety nor Wit\n"
|
||||
"Shall lure it back to cancel half a Line,\n"
|
||||
"Nor all thy Tears wash out a Word of it.";
|
||||
char *s = "incomplet";
|
||||
|
||||
print_string(r);
|
||||
print_string(s);
|
||||
|
||||
byte_order();
|
||||
test_hex_string_funcs();
|
||||
|
||||
for (j = 0; j < 128; j++) {
|
||||
v128_set_to_zero(&x);
|
||||
/* x.v32[0] = (1 << j); */
|
||||
v128_set_bit(&x, j);
|
||||
printf("%s\n", v128_bit_string(&x));
|
||||
v128_clear_bit(&x, j);
|
||||
printf("%s\n", v128_bit_string(&x));
|
||||
}
|
||||
|
||||
printf("----------------------------------------------\n");
|
||||
v128_set_to_zero(&x);
|
||||
for (i = 0; i < 128; i++) {
|
||||
v128_set_bit(&x, i);
|
||||
}
|
||||
printf("%s\n", v128_bit_string(&x));
|
||||
|
||||
printf("----------------------------------------------\n");
|
||||
v128_set_to_zero(&x);
|
||||
v128_set_bit(&x, 0);
|
||||
for (i = 0; i < 128; i++) {
|
||||
printf("%s\n", v128_bit_string(&x));
|
||||
v128_right_shift(&x, 1);
|
||||
}
|
||||
printf("----------------------------------------------\n");
|
||||
v128_set_to_zero(&x);
|
||||
v128_set_bit(&x, 127);
|
||||
for (i = 0; i < 128; i++) {
|
||||
printf("%s\n", v128_bit_string(&x));
|
||||
v128_left_shift(&x, 1);
|
||||
}
|
||||
printf("----------------------------------------------\n");
|
||||
for (i = 0; i < 128; i++) {
|
||||
v128_set_to_zero(&x);
|
||||
v128_set_bit(&x, 127);
|
||||
v128_left_shift(&x, i);
|
||||
printf("%s\n", v128_bit_string(&x));
|
||||
}
|
||||
printf("----------------------------------------------\n");
|
||||
v128_set_to_zero(&x);
|
||||
for (i = 0; i < 128; i += 2) {
|
||||
v128_set_bit(&x, i);
|
||||
}
|
||||
printf("bit_string: { %s }\n", v128_bit_string(&x));
|
||||
printf("get_bit: { ");
|
||||
for (i = 0; i < 128; i++) {
|
||||
if (v128_get_bit(&x, i) == 1)
|
||||
printf("1");
|
||||
else
|
||||
printf("0");
|
||||
}
|
||||
printf(" } \n");
|
||||
|
||||
test_bswap();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* byte_order() prints out byte ordering of datatypes */
|
||||
|
||||
void byte_order(void)
|
||||
{
|
||||
int i;
|
||||
v128_t e;
|
||||
#if 0
|
||||
v16_t b;
|
||||
v32_t c;
|
||||
v64_t d;
|
||||
|
||||
for (i=0; i < sizeof(b); i++)
|
||||
b.octet[i] = i;
|
||||
for (i=0; i < sizeof(c); i++)
|
||||
c.octet[i] = i;
|
||||
for (i=0; i < sizeof(d); i++)
|
||||
d.octet[i] = i;
|
||||
|
||||
printf("v128_t:\t%s\n", v128_hex_string(&e));
|
||||
printf("v64_t:\t%s\n", v64_hex_string(&d));
|
||||
printf("v32_t:\t%s\n", v32_hex_string(c));
|
||||
printf("v16_t:\t%s\n", v16_hex_string(b));
|
||||
|
||||
c.value = 0x01020304;
|
||||
printf("v32_t:\t%s\n", v32_hex_string(c));
|
||||
b.value = 0x0102;
|
||||
printf("v16_t:\t%s\n", v16_hex_string(b));
|
||||
|
||||
printf("uint16_t ordering:\n");
|
||||
|
||||
c.value = 0x00010002;
|
||||
printf("v32_t:\t%x%x\n", c.v16[0], c.v16[1]);
|
||||
#endif
|
||||
|
||||
printf("byte ordering of crypto/math datatypes:\n");
|
||||
for (i = 0; i < sizeof(e); i++)
|
||||
e.v8[i] = i;
|
||||
printf("v128_t: %s\n", v128_hex_string(&e));
|
||||
}
|
||||
|
||||
void test_hex_string_funcs(void)
|
||||
{
|
||||
char hex1[] = "abadcafe";
|
||||
char hex2[] = "0123456789abcdefqqqqq";
|
||||
char raw[10];
|
||||
int len;
|
||||
|
||||
len = hex_string_to_octet_string(raw, hex1, strlen(hex1));
|
||||
printf("computed length: %d\tstring: %s\n", len,
|
||||
octet_string_hex_string(raw, len / 2));
|
||||
printf("expected length: %u\tstring: %s\n", (unsigned)strlen(hex1), hex1);
|
||||
|
||||
len = hex_string_to_octet_string(raw, hex2, strlen(hex2));
|
||||
printf("computed length: %d\tstring: %s\n", len,
|
||||
octet_string_hex_string(raw, len / 2));
|
||||
printf("expected length: %d\tstring: %s\n", 16, "0123456789abcdef");
|
||||
}
|
||||
|
||||
void print_string(char *s)
|
||||
{
|
||||
size_t i;
|
||||
printf("%s\n", s);
|
||||
printf("strlen(s) = %u\n", (unsigned)strlen(s));
|
||||
printf("{ ");
|
||||
for (i = 0; i < strlen(s); i++) {
|
||||
printf("0x%x, ", s[i]);
|
||||
if (((i + 1) % 8) == 0)
|
||||
printf("\n ");
|
||||
}
|
||||
printf("}\n");
|
||||
}
|
||||
|
||||
void test_bswap(void)
|
||||
{
|
||||
uint32_t x = 0x11223344;
|
||||
uint64_t y = 0x1122334455667788LL;
|
||||
|
||||
printf("before: %0x\nafter: %0x\n", x, (unsigned int)be32_to_cpu(x));
|
||||
printf("before: %0llx\nafter: %0llx\n", (unsigned long long)y,
|
||||
(unsigned long long)be64_to_cpu(y));
|
||||
|
||||
y = 1234;
|
||||
|
||||
printf("1234: %0llx\n", (unsigned long long)y);
|
||||
printf("as octet string: %s\n", octet_string_hex_string((uint8_t *)&y, 8));
|
||||
y = be64_to_cpu(y);
|
||||
printf("bswapped octet string: %s\n",
|
||||
octet_string_hex_string((uint8_t *)&y, 8));
|
||||
}
|
||||
125
TMessagesProj/jni/third_party/libsrtp/crypto/test/kernel_driver.c
vendored
Normal file
125
TMessagesProj/jni/third_party/libsrtp/crypto/test/kernel_driver.c
vendored
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* kernel_driver.c
|
||||
*
|
||||
* a test driver for the crypto_kernel
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright(c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h> /* for printf() */
|
||||
#include "getopt_s.h"
|
||||
#include "crypto_kernel.h"
|
||||
|
||||
void usage(char *prog_name)
|
||||
{
|
||||
printf("usage: %s [ -v ][ -d debug_module ]*\n", prog_name);
|
||||
exit(255);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int q;
|
||||
int do_validation = 0;
|
||||
srtp_err_status_t status;
|
||||
|
||||
if (argc == 1)
|
||||
usage(argv[0]);
|
||||
|
||||
/* initialize kernel - we need to do this before anything else */
|
||||
status = srtp_crypto_kernel_init();
|
||||
if (status) {
|
||||
printf("error: srtp_crypto_kernel init failed\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("srtp_crypto_kernel successfully initalized\n");
|
||||
|
||||
/* process input arguments */
|
||||
while (1) {
|
||||
q = getopt_s(argc, argv, "vd:");
|
||||
if (q == -1)
|
||||
break;
|
||||
switch (q) {
|
||||
case 'v':
|
||||
do_validation = 1;
|
||||
break;
|
||||
case 'd':
|
||||
status = srtp_crypto_kernel_set_debug_module(optarg_s, 1);
|
||||
if (status) {
|
||||
printf("error: set debug module (%s) failed\n", optarg_s);
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (do_validation) {
|
||||
printf("checking srtp_crypto_kernel status...\n");
|
||||
status = srtp_crypto_kernel_status();
|
||||
if (status) {
|
||||
printf("failed\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("srtp_crypto_kernel passed self-tests\n");
|
||||
}
|
||||
|
||||
status = srtp_crypto_kernel_shutdown();
|
||||
if (status) {
|
||||
printf("error: srtp_crypto_kernel shutdown failed\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("srtp_crypto_kernel successfully shut down\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* crypto_kernel_cipher_test() is a test of the cipher interface
|
||||
* of the crypto_kernel
|
||||
*/
|
||||
|
||||
srtp_err_status_t crypto_kernel_cipher_test(void)
|
||||
{
|
||||
/* not implemented yet! */
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
30
TMessagesProj/jni/third_party/libsrtp/include/config.h
vendored
Normal file
30
TMessagesProj/jni/third_party/libsrtp/include/config.h
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2016 The Chromium Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This space intentionally left blank.
|
||||
*
|
||||
* All of the #defines have been moved to BUILD.gn. The libsrtp headers
|
||||
* equate "building as a library" with HAS_CONFIG_H, so we need to leave that
|
||||
* defined and this file needs to be here.
|
||||
*/
|
||||
|
||||
#define HAVE_CONFIG_H
|
||||
#define OPENSSL
|
||||
#define HAVE_STDLIB_H
|
||||
#define HAVE_STRING_H
|
||||
#define HAVE_STDINT_H
|
||||
#define HAVE_INTTYPES_H
|
||||
#define HAVE_INT16_T
|
||||
#define HAVE_INT32_T
|
||||
#define HAVE_INT8_T
|
||||
#define HAVE_UINT16_T
|
||||
#define HAVE_UINT32_T
|
||||
#define HAVE_UINT64_T
|
||||
#define HAVE_UINT8_T
|
||||
#define HAVE_ARPA_INET_H
|
||||
#define HAVE_SYS_TYPES_H
|
||||
#define HAVE_UNISTD_H
|
||||
181
TMessagesProj/jni/third_party/libsrtp/include/ekt.h
vendored
Normal file
181
TMessagesProj/jni/third_party/libsrtp/include/ekt.h
vendored
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
/*
|
||||
* ekt.h
|
||||
*
|
||||
* interface to Encrypted Key Transport for SRTP
|
||||
*
|
||||
* David McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* EKT implementation strategy
|
||||
*
|
||||
* use stream_template approach
|
||||
*
|
||||
* in srtp_unprotect, when a new stream appears, check if template has
|
||||
* EKT defined, and if it does, then apply EKT processing
|
||||
*
|
||||
* question: will we want to allow key-sharing templates in addition
|
||||
* to EKT templates? could define a new ssrc_type_t that's associated
|
||||
* with an EKT, e.g. ssrc_any_ekt.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRTP_EKT_H
|
||||
#define SRTP_EKT_H
|
||||
|
||||
// left in commented out as reminder to not include private headers
|
||||
//#include "srtp_priv.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SRTP_EKT_CIPHER_DEFAULT 1
|
||||
#define SRTP_EKT_CIPHER_AES_128_ECB 1
|
||||
#define SRTP_EKT_CIPHER_AES_192_KEY_WRAP 2
|
||||
#define SRTP_EKT_CIPHER_AES_256_KEY_WRAP 3
|
||||
|
||||
typedef uint16_t srtp_ekt_spi_t;
|
||||
|
||||
unsigned srtp_ekt_octets_after_base_tag(srtp_ekt_stream_t ekt);
|
||||
|
||||
/*
|
||||
* an srtp_policy_t structure can contain a pointer to an
|
||||
* srtp_ekt_policy_t structure
|
||||
*
|
||||
* this structure holds all of the high level EKT information, and it
|
||||
* is passed into libsrtp to indicate what policy should be in effect
|
||||
*/
|
||||
|
||||
typedef struct srtp_ekt_policy_ctx_t {
|
||||
srtp_ekt_spi_t spi; /* security parameter index */
|
||||
uint8_t ekt_cipher_type;
|
||||
uint8_t *ekt_key;
|
||||
struct srtp_ekt_policy_ctx_t *next_ekt_policy;
|
||||
} srtp_ekt_policy_ctx_t;
|
||||
|
||||
/*
|
||||
* an srtp_ekt_data_t structure holds the data corresponding to an ekt key,
|
||||
* spi, and so on
|
||||
*/
|
||||
|
||||
typedef struct srtp_ekt_data_t {
|
||||
srtp_ekt_spi_t spi;
|
||||
uint8_t ekt_cipher_type;
|
||||
srtp_aes_expanded_key_t ekt_enc_key;
|
||||
srtp_aes_expanded_key_t ekt_dec_key;
|
||||
struct ekt_data_t *next_ekt_data;
|
||||
} srtp_ekt_data_t;
|
||||
|
||||
/*
|
||||
* an srtp_stream_ctx_t can contain an srtp_ekt_stream_ctx_t
|
||||
*
|
||||
* an srtp_ekt_stream_ctx_t structure holds all of the EKT information for
|
||||
* a specific SRTP stream
|
||||
*/
|
||||
|
||||
typedef struct srtp_ekt_stream_ctx_t {
|
||||
srtp_ekt_data_t *data;
|
||||
uint16_t isn; /* initial sequence number */
|
||||
uint8_t encrypted_master_key[SRTP_MAX_KEY_LEN];
|
||||
} srtp_ekt_stream_ctx_t;
|
||||
|
||||
srtp_err_status_t srtp_ekt_alloc(srtp_ekt_stream_t *stream_data,
|
||||
srtp_ekt_policy_t policy);
|
||||
|
||||
srtp_err_status_t srtp_ekt_stream_init(srtp_ekt_stream_t e,
|
||||
srtp_ekt_spi_t spi,
|
||||
void *ekt_key,
|
||||
unsigned ekt_cipher_type);
|
||||
|
||||
srtp_err_status_t srtp_ekt_stream_init_from_policy(srtp_ekt_stream_t e,
|
||||
srtp_ekt_policy_t p);
|
||||
|
||||
srtp_err_status_t srtp_stream_init_from_ekt(srtp_stream_t stream,
|
||||
const void *srtcp_hdr,
|
||||
unsigned pkt_octet_len);
|
||||
|
||||
void srtp_ekt_write_data(srtp_ekt_stream_t ekt,
|
||||
uint8_t *base_tag,
|
||||
unsigned base_tag_len,
|
||||
int *packet_len,
|
||||
srtp_xtd_seq_num_t pkt_index);
|
||||
|
||||
/*
|
||||
* We handle EKT by performing some additional steps before
|
||||
* authentication (copying the auth tag into a temporary location,
|
||||
* zeroizing the "base tag" field in the packet)
|
||||
*
|
||||
* With EKT, the tag_len parameter is actually the base tag
|
||||
* length
|
||||
*/
|
||||
srtp_err_status_t srtp_ekt_tag_verification_preproces(uint8_t *pkt_tag,
|
||||
uint8_t *pkt_tag_copy,
|
||||
unsigned tag_len);
|
||||
|
||||
srtp_err_status_t srtp_ekt_tag_verification_postproces(uint8_t *pkt_tag,
|
||||
uint8_t *pkt_tag_copy,
|
||||
unsigned tag_len);
|
||||
|
||||
/*
|
||||
* @brief EKT pre-processing for srtcp tag generation
|
||||
*
|
||||
* This function does the pre-processing of the SRTCP authentication
|
||||
* tag format. When EKT is used, it consists of writing the Encrypted
|
||||
* Master Key, the SRTP ROC, the Initial Sequence Number, and SPI
|
||||
* fields. The Base Authentication Tag field is set to the all-zero
|
||||
* value
|
||||
*
|
||||
* When EKT is not used, this function is a no-op.
|
||||
*
|
||||
*/
|
||||
srtp_err_status_t srtp_stream_srtcp_auth_tag_generation_preprocess(
|
||||
const srtp_stream_t *s,
|
||||
uint8_t *pkt_tag,
|
||||
unsigned pkt_octet_len);
|
||||
|
||||
/* it's not clear that a tag_generation_postprocess function is needed */
|
||||
srtp_err_status_t srtcp_auth_tag_generation_postprocess(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SRTP_EKT_H */
|
||||
67
TMessagesProj/jni/third_party/libsrtp/include/getopt_s.h
vendored
Normal file
67
TMessagesProj/jni/third_party/libsrtp/include/getopt_s.h
vendored
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* getopt.h
|
||||
*
|
||||
* interface to a minimal implementation of the getopt() function,
|
||||
* written so that test applications that use that function can run on
|
||||
* non-POSIX platforms
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GETOPT_S_H
|
||||
#define GETOPT_S_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* getopt_s(), optarg_s, and optind_s are small, locally defined
|
||||
* versions of the POSIX standard getopt() interface.
|
||||
*/
|
||||
|
||||
int getopt_s(int argc, char *const argv[], const char *optstring);
|
||||
|
||||
extern char *optarg_s; /* defined in getopt.c */
|
||||
|
||||
extern int optind_s; /* defined in getopt.c */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GETOPT_S_H */
|
||||
1759
TMessagesProj/jni/third_party/libsrtp/include/srtp.h
vendored
Normal file
1759
TMessagesProj/jni/third_party/libsrtp/include/srtp.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
280
TMessagesProj/jni/third_party/libsrtp/include/srtp_priv.h
vendored
Normal file
280
TMessagesProj/jni/third_party/libsrtp/include/srtp_priv.h
vendored
Normal file
|
|
@ -0,0 +1,280 @@
|
|||
/*
|
||||
* srtp_priv.h
|
||||
*
|
||||
* private internal data structures and functions for libSRTP
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRTP_PRIV_H
|
||||
#define SRTP_PRIV_H
|
||||
|
||||
// Leave this as the top level import. Ensures the existence of defines
|
||||
#include "config.h"
|
||||
|
||||
#include "srtp.h"
|
||||
#include "rdbx.h"
|
||||
#include "rdb.h"
|
||||
#include "integers.h"
|
||||
#include "cipher.h"
|
||||
#include "auth.h"
|
||||
#include "aes.h"
|
||||
#include "key.h"
|
||||
#include "crypto_kernel.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SRTP_VER_STRING "libsrtp2 2.1.0-pre"
|
||||
#define SRTP_VERSION "2.1.0-pre"
|
||||
|
||||
typedef struct srtp_stream_ctx_t_ srtp_stream_ctx_t;
|
||||
typedef srtp_stream_ctx_t *srtp_stream_t;
|
||||
|
||||
/*
|
||||
* the following declarations are libSRTP internal functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* srtp_get_stream(ssrc) returns a pointer to the stream corresponding
|
||||
* to ssrc, or NULL if no stream exists for that ssrc
|
||||
*/
|
||||
srtp_stream_t srtp_get_stream(srtp_t srtp, uint32_t ssrc);
|
||||
|
||||
/*
|
||||
* srtp_stream_init_keys(s, k) (re)initializes the srtp_stream_t s by
|
||||
* deriving all of the needed keys using the KDF and the key k.
|
||||
*/
|
||||
srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp,
|
||||
srtp_master_key_t *master_key,
|
||||
const unsigned int current_mki_index);
|
||||
|
||||
/*
|
||||
* srtp_stream_init_all_master_keys(s, k, m) (re)initializes the srtp_stream_t s
|
||||
* by deriving all of the needed keys for all the master keys using the KDF and
|
||||
* the keys from k.
|
||||
*/
|
||||
srtp_err_status_t srtp_steam_init_all_master_keys(
|
||||
srtp_stream_ctx_t *srtp,
|
||||
unsigned char *key,
|
||||
srtp_master_key_t **keys,
|
||||
const unsigned int max_master_keys);
|
||||
|
||||
/*
|
||||
* srtp_stream_init(s, p) initializes the srtp_stream_t s to
|
||||
* use the policy at the location p
|
||||
*/
|
||||
srtp_err_status_t srtp_stream_init(srtp_stream_t srtp, const srtp_policy_t *p);
|
||||
|
||||
/*
|
||||
* libsrtp internal datatypes
|
||||
*/
|
||||
typedef enum direction_t {
|
||||
dir_unknown = 0,
|
||||
dir_srtp_sender = 1,
|
||||
dir_srtp_receiver = 2
|
||||
} direction_t;
|
||||
|
||||
/*
|
||||
* srtp_session_keys_t will contain the encryption, hmac, salt keys
|
||||
* for both SRTP and SRTCP. The session keys will also contain the
|
||||
* MKI ID which is used to identify the session keys.
|
||||
*/
|
||||
typedef struct srtp_session_keys_t {
|
||||
srtp_cipher_t *rtp_cipher;
|
||||
srtp_cipher_t *rtp_xtn_hdr_cipher;
|
||||
srtp_auth_t *rtp_auth;
|
||||
srtp_cipher_t *rtcp_cipher;
|
||||
srtp_auth_t *rtcp_auth;
|
||||
uint8_t salt[SRTP_AEAD_SALT_LEN];
|
||||
uint8_t c_salt[SRTP_AEAD_SALT_LEN];
|
||||
uint8_t *mki_id;
|
||||
unsigned int mki_size;
|
||||
srtp_key_limit_ctx_t *limit;
|
||||
} srtp_session_keys_t;
|
||||
|
||||
/*
|
||||
* an srtp_stream_t has its own SSRC, encryption key, authentication
|
||||
* key, sequence number, and replay database
|
||||
*
|
||||
* note that the keys might not actually be unique, in which case the
|
||||
* srtp_cipher_t and srtp_auth_t pointers will point to the same structures
|
||||
*/
|
||||
typedef struct srtp_stream_ctx_t_ {
|
||||
uint32_t ssrc;
|
||||
srtp_session_keys_t *session_keys;
|
||||
unsigned int num_master_keys;
|
||||
srtp_rdbx_t rtp_rdbx;
|
||||
srtp_sec_serv_t rtp_services;
|
||||
srtp_rdb_t rtcp_rdb;
|
||||
srtp_sec_serv_t rtcp_services;
|
||||
direction_t direction;
|
||||
int allow_repeat_tx;
|
||||
srtp_ekt_stream_t ekt;
|
||||
int *enc_xtn_hdr;
|
||||
int enc_xtn_hdr_count;
|
||||
uint32_t pending_roc;
|
||||
struct srtp_stream_ctx_t_ *next; /* linked list of streams */
|
||||
} strp_stream_ctx_t_;
|
||||
|
||||
/*
|
||||
* an srtp_ctx_t holds a stream list and a service description
|
||||
*/
|
||||
typedef struct srtp_ctx_t_ {
|
||||
struct srtp_stream_ctx_t_ *stream_list; /* linked list of streams */
|
||||
struct srtp_stream_ctx_t_ *stream_template; /* act as template for other */
|
||||
/* streams */
|
||||
void *user_data; /* user custom data */
|
||||
} srtp_ctx_t_;
|
||||
|
||||
/*
|
||||
* srtp_hdr_t represents an RTP or SRTP header. The bit-fields in
|
||||
* this structure should be declared "unsigned int" instead of
|
||||
* "unsigned char", but doing so causes the MS compiler to not
|
||||
* fully pack the bit fields.
|
||||
*
|
||||
* In this implementation, an srtp_hdr_t is assumed to be 32-bit aligned
|
||||
*
|
||||
* (note that this definition follows that of RFC 1889 Appendix A, but
|
||||
* is not identical)
|
||||
*/
|
||||
|
||||
#ifndef WORDS_BIGENDIAN
|
||||
|
||||
typedef struct {
|
||||
unsigned char cc : 4; /* CSRC count */
|
||||
unsigned char x : 1; /* header extension flag */
|
||||
unsigned char p : 1; /* padding flag */
|
||||
unsigned char version : 2; /* protocol version */
|
||||
unsigned char pt : 7; /* payload type */
|
||||
unsigned char m : 1; /* marker bit */
|
||||
uint16_t seq; /* sequence number */
|
||||
uint32_t ts; /* timestamp */
|
||||
uint32_t ssrc; /* synchronization source */
|
||||
} srtp_hdr_t;
|
||||
|
||||
#else /* BIG_ENDIAN */
|
||||
|
||||
typedef struct {
|
||||
unsigned char version : 2; /* protocol version */
|
||||
unsigned char p : 1; /* padding flag */
|
||||
unsigned char x : 1; /* header extension flag */
|
||||
unsigned char cc : 4; /* CSRC count */
|
||||
unsigned char m : 1; /* marker bit */
|
||||
unsigned char pt : 7; /* payload type */
|
||||
uint16_t seq; /* sequence number */
|
||||
uint32_t ts; /* timestamp */
|
||||
uint32_t ssrc; /* synchronization source */
|
||||
} srtp_hdr_t;
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint16_t profile_specific; /* profile-specific info */
|
||||
uint16_t length; /* number of 32-bit words in extension */
|
||||
} srtp_hdr_xtnd_t;
|
||||
|
||||
/*
|
||||
* srtcp_hdr_t represents a secure rtcp header
|
||||
*
|
||||
* in this implementation, an srtcp header is assumed to be 32-bit
|
||||
* alinged
|
||||
*/
|
||||
|
||||
#ifndef WORDS_BIGENDIAN
|
||||
|
||||
typedef struct {
|
||||
unsigned char rc : 5; /* reception report count */
|
||||
unsigned char p : 1; /* padding flag */
|
||||
unsigned char version : 2; /* protocol version */
|
||||
unsigned char pt : 8; /* payload type */
|
||||
uint16_t len; /* length */
|
||||
uint32_t ssrc; /* synchronization source */
|
||||
} srtcp_hdr_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int index : 31; /* srtcp packet index in network order! */
|
||||
unsigned int e : 1; /* encrypted? 1=yes */
|
||||
/* optional mikey/etc go here */
|
||||
/* and then the variable-length auth tag */
|
||||
} srtcp_trailer_t;
|
||||
|
||||
#else /* BIG_ENDIAN */
|
||||
|
||||
typedef struct {
|
||||
unsigned char version : 2; /* protocol version */
|
||||
unsigned char p : 1; /* padding flag */
|
||||
unsigned char rc : 5; /* reception report count */
|
||||
unsigned char pt : 8; /* payload type */
|
||||
uint16_t len; /* length */
|
||||
uint32_t ssrc; /* synchronization source */
|
||||
} srtcp_hdr_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int e : 1; /* encrypted? 1=yes */
|
||||
unsigned int index : 31; /* srtcp packet index */
|
||||
/* optional mikey/etc go here */
|
||||
/* and then the variable-length auth tag */
|
||||
} srtcp_trailer_t;
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* srtp_handle_event(srtp, srtm, evnt) calls the event handling
|
||||
* function, if there is one.
|
||||
*
|
||||
* This macro is not included in the documentation as it is
|
||||
* an internal-only function.
|
||||
*/
|
||||
|
||||
#define srtp_handle_event(srtp, strm, evnt) \
|
||||
if (srtp_event_handler) { \
|
||||
srtp_event_data_t data; \
|
||||
data.session = srtp; \
|
||||
data.ssrc = ntohl(strm->ssrc); \
|
||||
data.event = evnt; \
|
||||
srtp_event_handler(&data); \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SRTP_PRIV_H */
|
||||
83
TMessagesProj/jni/third_party/libsrtp/include/ut_sim.h
vendored
Normal file
83
TMessagesProj/jni/third_party/libsrtp/include/ut_sim.h
vendored
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* ut-sim.h
|
||||
*
|
||||
* an unreliable transport simulator
|
||||
* (for testing replay databases and suchlike)
|
||||
*
|
||||
* David A. McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef UT_SIM_H
|
||||
#define UT_SIM_H
|
||||
|
||||
#include "integers.h" /* for uint32_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define UT_BUF 160 /* maximum amount of packet reorder */
|
||||
|
||||
typedef struct {
|
||||
uint32_t index;
|
||||
uint32_t buffer[UT_BUF];
|
||||
} ut_connection;
|
||||
|
||||
/*
|
||||
* ut_init(&u) initializes the ut_connection
|
||||
*
|
||||
* this function should always be the first one called on a new
|
||||
* ut_connection
|
||||
*/
|
||||
|
||||
void ut_init(ut_connection *utc);
|
||||
|
||||
/*
|
||||
* ut_next_index(&u) returns the next index from the simulated
|
||||
* unreliable connection
|
||||
*/
|
||||
|
||||
uint32_t ut_next_index(ut_connection *utc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* UT_SIM_H */
|
||||
281
TMessagesProj/jni/third_party/libsrtp/srtp/ekt.c
vendored
Normal file
281
TMessagesProj/jni/third_party/libsrtp/srtp/ekt.c
vendored
Normal file
|
|
@ -0,0 +1,281 @@
|
|||
/*
|
||||
* ekt.c
|
||||
*
|
||||
* Encrypted Key Transport for SRTP
|
||||
*
|
||||
* David McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2017 Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of the Cisco Systems, Inc. nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "srtp_priv.h"
|
||||
#include "err.h"
|
||||
#include "ekt.h"
|
||||
|
||||
extern srtp_debug_module_t mod_srtp;
|
||||
|
||||
/*
|
||||
* The EKT Authentication Tag format.
|
||||
*
|
||||
* 0 1 2 3
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* : Base Authentication Tag :
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* : Encrypted Master Key :
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Rollover Counter |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | Initial Sequence Number | Security Parameter Index |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*
|
||||
*/
|
||||
|
||||
#define EKT_OCTETS_AFTER_BASE_TAG 24
|
||||
#define EKT_OCTETS_AFTER_EMK 8
|
||||
#define EKT_OCTETS_AFTER_ROC 4
|
||||
#define EKT_SPI_LEN 2
|
||||
|
||||
unsigned srtp_ekt_octets_after_base_tag(srtp_ekt_stream_t ekt)
|
||||
{
|
||||
/*
|
||||
* if the pointer ekt is NULL, then EKT is not in effect, so we
|
||||
* indicate this by returning zero
|
||||
*/
|
||||
if (!ekt)
|
||||
return 0;
|
||||
|
||||
switch (ekt->data->ekt_cipher_type) {
|
||||
case SRTP_EKT_CIPHER_AES_128_ECB:
|
||||
return 16 + EKT_OCTETS_AFTER_EMK;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline srtp_ekt_spi_t srtcp_packet_get_ekt_spi(
|
||||
const uint8_t *packet_start,
|
||||
unsigned pkt_octet_len)
|
||||
{
|
||||
const uint8_t *spi_location;
|
||||
|
||||
spi_location = packet_start + (pkt_octet_len - EKT_SPI_LEN);
|
||||
|
||||
return *((const srtp_ekt_spi_t *)spi_location);
|
||||
}
|
||||
|
||||
static inline uint32_t srtcp_packet_get_ekt_roc(const uint8_t *packet_start,
|
||||
unsigned pkt_octet_len)
|
||||
{
|
||||
const uint8_t *roc_location;
|
||||
|
||||
roc_location = packet_start + (pkt_octet_len - EKT_OCTETS_AFTER_ROC);
|
||||
|
||||
return *((const uint32_t *)roc_location);
|
||||
}
|
||||
|
||||
static inline const uint8_t *srtcp_packet_get_emk_location(
|
||||
const uint8_t *packet_start,
|
||||
unsigned pkt_octet_len)
|
||||
{
|
||||
const uint8_t *location;
|
||||
|
||||
location = packet_start + (pkt_octet_len - EKT_OCTETS_AFTER_BASE_TAG);
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_ekt_alloc(srtp_ekt_stream_t *stream_data,
|
||||
srtp_ekt_policy_t policy)
|
||||
{
|
||||
/*
|
||||
* if the policy pointer is NULL, then EKT is not in use
|
||||
* so we just set the EKT stream data pointer to NULL
|
||||
*/
|
||||
if (!policy) {
|
||||
*stream_data = NULL;
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
/* TODO */
|
||||
*stream_data = NULL;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
srtp_err_status_t srtp_ekt_stream_init_from_policy(
|
||||
srtp_ekt_stream_t stream_data,
|
||||
srtp_ekt_policy_t policy)
|
||||
{
|
||||
if (!stream_data)
|
||||
return srtp_err_status_ok;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
void aes_decrypt_with_raw_key(void *ciphertext, const void *key, int key_len)
|
||||
{
|
||||
#ifndef OPENSSL
|
||||
// FIXME: need to get this working through the crypto module interface
|
||||
srtp_aes_expanded_key_t expanded_key;
|
||||
|
||||
srtp_aes_expand_decryption_key(key, key_len, &expanded_key);
|
||||
srtp_aes_decrypt(ciphertext, &expanded_key);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* The function srtp_stream_init_from_ekt() initializes a stream using
|
||||
* the EKT data from an SRTCP trailer.
|
||||
*/
|
||||
|
||||
srtp_err_status_t srtp_stream_init_from_ekt(srtp_stream_t stream,
|
||||
const void *srtcp_hdr,
|
||||
unsigned pkt_octet_len)
|
||||
{
|
||||
srtp_err_status_t err;
|
||||
const uint8_t *master_key;
|
||||
srtp_policy_t srtp_policy;
|
||||
uint32_t roc;
|
||||
|
||||
/*
|
||||
* NOTE: at present, we only support a single ekt_policy at a time.
|
||||
*/
|
||||
if (stream->ekt->data->spi !=
|
||||
srtcp_packet_get_ekt_spi(srtcp_hdr, pkt_octet_len))
|
||||
return srtp_err_status_no_ctx;
|
||||
|
||||
if (stream->ekt->data->ekt_cipher_type != SRTP_EKT_CIPHER_AES_128_ECB)
|
||||
return srtp_err_status_bad_param;
|
||||
|
||||
/* decrypt the Encrypted Master Key field */
|
||||
master_key = srtcp_packet_get_emk_location(srtcp_hdr, pkt_octet_len);
|
||||
/* FIX!? This decrypts the master key in-place, and never uses it */
|
||||
/* FIX!? It's also passing to ekt_dec_key (which is an aes_expanded_key_t)
|
||||
* to a function which expects a raw (unexpanded) key */
|
||||
aes_decrypt_with_raw_key((void *)master_key,
|
||||
&stream->ekt->data->ekt_dec_key, 16);
|
||||
|
||||
/* set the SRTP ROC */
|
||||
roc = srtcp_packet_get_ekt_roc(srtcp_hdr, pkt_octet_len);
|
||||
err = srtp_rdbx_set_roc(&stream->rtp_rdbx, roc);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = srtp_stream_init(stream, &srtp_policy);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
return srtp_err_status_ok;
|
||||
}
|
||||
|
||||
void srtp_ekt_write_data(srtp_ekt_stream_t ekt,
|
||||
uint8_t *base_tag,
|
||||
unsigned base_tag_len,
|
||||
int *packet_len,
|
||||
srtp_xtd_seq_num_t pkt_index)
|
||||
{
|
||||
uint32_t roc;
|
||||
uint16_t isn;
|
||||
unsigned emk_len;
|
||||
uint8_t *packet;
|
||||
|
||||
/* if the pointer ekt is NULL, then EKT is not in effect */
|
||||
if (!ekt) {
|
||||
debug_print(mod_srtp, "EKT not in use", NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
/* write zeros into the location of the base tag */
|
||||
octet_string_set_to_zero(base_tag, base_tag_len);
|
||||
packet = base_tag + base_tag_len;
|
||||
|
||||
/* copy encrypted master key into packet */
|
||||
emk_len = srtp_ekt_octets_after_base_tag(ekt);
|
||||
memcpy(packet, ekt->encrypted_master_key, emk_len);
|
||||
debug_print(mod_srtp, "writing EKT EMK: %s,",
|
||||
srtp_octet_string_hex_string(packet, emk_len));
|
||||
packet += emk_len;
|
||||
|
||||
/* copy ROC into packet */
|
||||
roc = (uint32_t)(pkt_index >> 16);
|
||||
*((uint32_t *)packet) = be32_to_cpu(roc);
|
||||
debug_print(mod_srtp, "writing EKT ROC: %s,",
|
||||
srtp_octet_string_hex_string(packet, sizeof(roc)));
|
||||
packet += sizeof(roc);
|
||||
|
||||
/* copy ISN into packet */
|
||||
isn = (uint16_t)pkt_index;
|
||||
*((uint16_t *)packet) = htons(isn);
|
||||
debug_print(mod_srtp, "writing EKT ISN: %s,",
|
||||
srtp_octet_string_hex_string(packet, sizeof(isn)));
|
||||
packet += sizeof(isn);
|
||||
|
||||
/* copy SPI into packet */
|
||||
*((uint16_t *)packet) = htons(ekt->data->spi);
|
||||
debug_print(mod_srtp, "writing EKT SPI: %s,",
|
||||
srtp_octet_string_hex_string(packet, sizeof(ekt->data->spi)));
|
||||
|
||||
/* increase packet length appropriately */
|
||||
*packet_len += EKT_OCTETS_AFTER_EMK + emk_len;
|
||||
}
|
||||
|
||||
/*
|
||||
* The function call srtcp_ekt_trailer(ekt, auth_len, auth_tag )
|
||||
*
|
||||
* If the pointer ekt is NULL, then the other inputs are unaffected.
|
||||
*
|
||||
* auth_tag is a pointer to the pointer to the location of the
|
||||
* authentication tag in the packet. If EKT is in effect, then the
|
||||
* auth_tag pointer is set to the location
|
||||
*/
|
||||
|
||||
void srtcp_ekt_trailer(srtp_ekt_stream_t ekt,
|
||||
unsigned *auth_len,
|
||||
void **auth_tag,
|
||||
void *tag_copy)
|
||||
{
|
||||
/*
|
||||
* if there is no EKT policy, then the other inputs are unaffected
|
||||
*/
|
||||
if (!ekt)
|
||||
return;
|
||||
|
||||
/* copy auth_tag into temporary location */
|
||||
}
|
||||
4732
TMessagesProj/jni/third_party/libsrtp/srtp/srtp.c
vendored
Normal file
4732
TMessagesProj/jni/third_party/libsrtp/srtp/srtp.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue