Add encrypted input support

This commit is contained in:
Cameron Gutman 2014-08-26 23:33:43 -07:00
parent 5d2d6cc617
commit 74f2334c2e
15 changed files with 2152 additions and 32 deletions

View File

@ -156,7 +156,9 @@ int LiStartConnection(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfig, PCONN
Limelog("Initializing input stream...");
ListenerCallbacks.stageStarting(STAGE_INPUT_STREAM_INIT);
initializeInputStream(host, &ListenerCallbacks);
initializeInputStream(host, &ListenerCallbacks,
streamConfig->remoteInputAesKey, sizeof(streamConfig->remoteInputAesKey),
streamConfig->remoteInputAesIv, sizeof(streamConfig->remoteInputAesIv));
stage++;
LC_ASSERT(stage == STAGE_INPUT_STREAM_INIT);
ListenerCallbacks.stageComplete(STAGE_INPUT_STREAM_INIT);

View File

@ -4,12 +4,18 @@
#include "LinkedBlockingQueue.h"
#include "Input.h"
#include "OpenAES\oaes_lib.h"
#include "OpenAES\oaes_common.h"
static IP_ADDRESS host;
static SOCKET inputSock = INVALID_SOCKET;
static PCONNECTION_LISTENER_CALLBACKS listenerCallbacks;
static LINKED_BLOCKING_QUEUE packetQueue;
static PLT_THREAD inputSendThread;
static OAES_CTX* oaesContext;
#define MAX_INPUT_PACKET_SIZE 128
typedef struct _PACKET_HOLDER {
int packetLength;
@ -20,10 +26,36 @@ typedef struct _PACKET_HOLDER {
} packet;
} PACKET_HOLDER, *PPACKET_HOLDER;
int initializeInputStream(IP_ADDRESS addr, PCONNECTION_LISTENER_CALLBACKS clCallbacks) {
int initializeInputStream(IP_ADDRESS addr, PCONNECTION_LISTENER_CALLBACKS clCallbacks,
char* aesKeyData, int aesKeyDataLength, char* aesIv, int aesIvLength) {
host = addr;
listenerCallbacks = clCallbacks;
if (aesIvLength != OAES_BLOCK_SIZE)
{
Limelog("AES IV is incorrect length. Should be %d\n", aesIvLength);
return -1;
}
oaesContext = oaes_alloc();
if (oaesContext == NULL)
{
Limelog("Failed to allocate OpenAES context\n");
return -1;
}
if (oaes_set_option(oaesContext, OAES_OPTION_CBC, aesIv) != OAES_RET_SUCCESS)
{
Limelog("Failed to set CBC and IV on OAES context\n");
return -1;
}
if (oaes_key_import_data(oaesContext, aesKeyData, aesKeyDataLength) != OAES_RET_SUCCESS)
{
Limelog("Failed to import AES key data\n");
return -1;
}
LbqInitializeLinkedBlockingQueue(&packetQueue, 30);
return 0;
@ -32,6 +64,11 @@ int initializeInputStream(IP_ADDRESS addr, PCONNECTION_LISTENER_CALLBACKS clCall
void destroyInputStream(void) {
PLINKED_BLOCKING_QUEUE_ENTRY entry, nextEntry;
if (oaesContext != NULL)
{
oaes_free(oaesContext);
}
entry = LbqDestroyLinkedBlockingQueue(&packetQueue);
while (entry != NULL) {
@ -45,8 +82,12 @@ void destroyInputStream(void) {
static void inputSendThreadProc(void* context) {
int err;
PPACKET_HOLDER holder;
char encryptedBuffer[MAX_INPUT_PACKET_SIZE];
size_t encryptedSize;
while (!PltIsThreadInterrupted(&inputSendThread)) {
int encryptedLengthPrefix;
err = LbqWaitForQueueElement(&packetQueue, (void**) &holder);
if (err != LBQ_SUCCESS) {
Limelog("Input thread terminating #1\n");
@ -54,16 +95,35 @@ static void inputSendThreadProc(void* context) {
return;
}
#ifdef _MSC_VER
#pragma warning(suppress: 6001)
#endif
err = send(inputSock, (const char*) &holder->packet, holder->packetLength, 0);
encryptedSize = sizeof(encryptedBuffer);
err = oaes_encrypt(oaesContext, (const char*) &holder->packet, holder->packetLength,
encryptedBuffer, &encryptedSize);
free(holder);
if (err <= 0) {
if (err != OAES_RET_SUCCESS) {
Limelog("Input thread terminating #2\n");
listenerCallbacks->connectionTerminated(err);
return;
}
// The first 32-bytes of the output are internal OAES stuff that we want to ignore
encryptedSize -= 32;
// Send the encrypted length first
encryptedLengthPrefix = htonl((unsigned long) encryptedSize);
err = send(inputSock, (const char*) &encryptedLengthPrefix, sizeof(encryptedLengthPrefix), 0);
if (err <= 0) {
Limelog("Input thread terminating #3\n");
listenerCallbacks->connectionTerminated(err);
return;
}
// Send the encrypted payload
err = send(inputSock, (const char*) &encryptedBuffer[32], encryptedSize, 0);
if (err <= 0) {
Limelog("Input thread terminating #4\n");
listenerCallbacks->connectionTerminated(err);
return;
}
}
}

View File

@ -37,7 +37,8 @@ void destroyAudioStream(void);
int startAudioStream(void);
void stopAudioStream(void);
int initializeInputStream(IP_ADDRESS addr, PCONNECTION_LISTENER_CALLBACKS clCallbacks);
int initializeInputStream(IP_ADDRESS addr, PCONNECTION_LISTENER_CALLBACKS clCallbacks,
char* aesKeyData, int aesKeyDataLength, char* aesIv, int aesIvLength);
void destroyInputStream(void);
int startInputStream(void);
int stopInputStream(void);

View File

@ -12,6 +12,8 @@ typedef struct _STREAM_CONFIGURATION {
int fps;
int bitrate;
int packetSize;
char remoteInputAesKey[16];
char remoteInputAesIv[16];
} STREAM_CONFIGURATION, *PSTREAM_CONFIGURATION;
typedef struct _LENTRY {

View File

@ -0,0 +1,27 @@
---------------------------------------------------------------------------
OpenAES Licence
---------------------------------------------------------------------------
Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com
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.
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 HOLDER 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.
---------------------------------------------------------------------------

View File

@ -0,0 +1,85 @@
---------------------------------------------------------------------------
OpenAES-0.9.0
Nabil S. Al Ramli
www.nalramli.com
---------------------------------------------------------------------------
License Terms
-------------
---------------------------------------------------------------------------
OpenAES Licence
---------------------------------------------------------------------------
Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com
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.
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 HOLDER 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.
---------------------------------------------------------------------------
Introduction
------------
OpenAES is an open source implementation of the Advanced Encryption
Standard. It is distributed as a portable, lightweight C library that can
be easily integrated into applications.
Compiling
---------
OpenAES has been tested with the GCC as well as VC compilers. It is
necessary to compile the source files located in ./src, and to add ./inc to
the include paths.
If you are building with OAES_HAVE_ISAAC defined (true by default), then
you also need to link in the source files under ./src/isaac and also add
./src/isaac to the include paths.
You may edit ./inc/oaes_config.h to modify build options.
CMake 2.8.0 can be used to build the test programs on different platforms.
In a Linux command line terminal type:
cmake .
make
In Windows, in a Visual Studio command line window type:
cmake . -G "NMake Makefiles"
nmake
Usage
-----
oaes_lib usage is described in the header file ./inc/oaes_lib.h.
The oaes command line application help manual can be obtained by using the
--help command line options.
The oaes_setup Windows installer integrates with the Windows shell. It can be
used by right clicking a file in Windows Explorer and then selecting a
subcommand from the OpenAES menu.
Samples
-------
Samples applications are provided in the /test folder.

View File

@ -0,0 +1 @@
OpenAES-0.9.0

View File

@ -0,0 +1,173 @@
/*
* ---------------------------------------------------------------------------
* OpenAES License
* ---------------------------------------------------------------------------
* Copyright (c) 2013, Nabil S. Al Ramli, www.nalramli.com
* 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.
*
* 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 HOLDER 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.
* ---------------------------------------------------------------------------
*/
static const char _NR[] = {
0x4e,0x61,0x62,0x69,0x6c,0x20,0x53,0x2e,0x20,
0x41,0x6c,0x20,0x52,0x61,0x6d,0x6c,0x69,0x00 };
#include <stdlib.h>
#include <string.h>
#include "oaes_config.h"
#include "oaes_base64.h"
static const char _oaes_base64_table[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
OAES_RET oaes_base64_encode(
const uint8_t *in, size_t in_len, char *out, size_t *out_len)
{
size_t _i = 0, _j = 0;
unsigned char _buf1[3];
unsigned char _buf2[4];
size_t _out_len_req = 4 * ( in_len / 3 + ( in_len % 3 ? 1 : 0 ) ) + 1;
if( NULL == in || 0 == in_len || NULL == out_len )
return OAES_RET_ERROR;
if( NULL == out )
{
*out_len = _out_len_req;
return OAES_RET_SUCCESS;
}
if( _out_len_req > *out_len )
return OAES_RET_ERROR;
memset(out, 0, *out_len);
*out_len = 0;
while( in_len-- )
{
_buf1[_i++] = *(in++);
if( _i == 3 )
{
_buf2[0] = (_buf1[0] & 0xfc) >> 2;
_buf2[1] = ((_buf1[0] & 0x03) << 4) + ((_buf1[1] & 0xf0) >> 4);
_buf2[2] = ((_buf1[1] & 0x0f) << 2) + ((_buf1[2] & 0xc0) >> 6);
_buf2[3] = _buf1[2] & 0x3f;
for( _i = 0; _i < 4; _i++ )
{
*(out++) = _oaes_base64_table[_buf2[_i]];
(*out_len)++;
}
_i = 0;
}
}
if( _i )
{
for( _j = _i; _j < 3; _j++ )
_buf1[_j] = '\0';
_buf2[0] = (_buf1[0] & 0xfc) >> 2;
_buf2[1] = ((_buf1[0] & 0x03) << 4) + ((_buf1[1] & 0xf0) >> 4);
_buf2[2] = ((_buf1[1] & 0x0f) << 2) + ((_buf1[2] & 0xc0) >> 6);
_buf2[3] = _buf1[2] & 0x3f;
for( _j = 0; (_j < _i + 1); _j++ )
{
*(out++) = _oaes_base64_table[_buf2[_j]];
(*out_len)++;
}
while( _i++ < 3 )
{
*(out++) = '=';
(*out_len)++;
}
}
return OAES_RET_SUCCESS;
}
OAES_RET oaes_base64_decode(
const char *in, size_t in_len, uint8_t *out, size_t *out_len )
{
size_t _i = 0, _j = 0, _idx = 0;
uint8_t _buf2[4], _buf1[3];
size_t _out_len_req = 3 * ( in_len / 4 + ( in_len % 4 ? 1 : 0 ) );
if( NULL == in || 0 == in_len || NULL == out_len )
return OAES_RET_ERROR;
if( NULL == out )
{
*out_len = _out_len_req;
return OAES_RET_SUCCESS;
}
if( _out_len_req > *out_len )
return OAES_RET_ERROR;
memset(out, 0, *out_len);
*out_len = 0;
while( in_len-- && strchr(_oaes_base64_table, in[_idx++]) )
{
_buf2[_i++] = in[_idx - 1];
if( _i ==4 )
{
for (_i = 0; _i < 4; _i++)
_buf2[_i] = strchr(_oaes_base64_table, _buf2[_i]) - _oaes_base64_table;
_buf1[0] = (_buf2[0] << 2) + ((_buf2[1] & 0x30) >> 4);
_buf1[1] = ((_buf2[1] & 0xf) << 4) + ((_buf2[2] & 0x3c) >> 2);
_buf1[2] = ((_buf2[2] & 0x3) << 6) + _buf2[3];
for( _i = 0; (_i < 3); _i++ )
{
*(out++) = _buf1[_i];
(*out_len)++;
}
_i = 0;
}
}
if( _i )
{
for( _j = _i; _j <4; _j++ )
_buf2[_j] = 0;
for( _j = 0; _j <4; _j++ )
_buf2[_j] = strchr(_oaes_base64_table, _buf2[_j]) - _oaes_base64_table;
_buf1[0] = (_buf2[0] << 2) + ((_buf2[1] & 0x30) >> 4);
_buf1[1] = ((_buf2[1] & 0xf) << 4) + ((_buf2[2] & 0x3c) >> 2);
_buf1[2] = ((_buf2[2] & 0x3) << 6) + _buf2[3];
for( _j = 0; (_j < _i - 1); _j++ )
{
*(out++) = _buf1[_j];
(*out_len)++;
}
}
return OAES_RET_SUCCESS;
}

View File

@ -0,0 +1,50 @@
/*
* ---------------------------------------------------------------------------
* OpenAES License
* ---------------------------------------------------------------------------
* Copyright (c) 2013, Nabil S. Al Ramli, www.nalramli.com
* 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.
*
* 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 HOLDER 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 _OAES_BASE64_H
#define _OAES_BASE64_H
#include "oaes_common.h"
#ifdef __cplusplus
extern "C" {
#endif
OAES_API OAES_RET oaes_base64_encode(
const uint8_t *in, size_t in_len, char *out, size_t *out_len );
OAES_API OAES_RET oaes_base64_decode(
const char *in, size_t in_len, uint8_t *out, size_t *out_len );
#ifdef __cplusplus
}
#endif
#endif // _OAES_BASE64_H

View File

@ -0,0 +1,77 @@
/*
* ---------------------------------------------------------------------------
* OpenAES License
* ---------------------------------------------------------------------------
* Copyright (c) 2013, Nabil S. Al Ramli, www.nalramli.com
* 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.
*
* 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 HOLDER 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 _OAES_COMMON_H
#define _OAES_COMMON_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
# ifdef OAES_SHARED
# ifdef oaes_lib_EXPORTS
# define OAES_API __declspec(dllexport)
# else
# define OAES_API __declspec(dllimport)
# endif
# else
# define OAES_API
# endif
#else
# define OAES_API
#endif // WIN32
#define OAES_VERSION "0.9.0"
typedef enum
{
OAES_RET_FIRST = 0,
OAES_RET_SUCCESS = 0,
OAES_RET_ERROR,
OAES_RET_ARG1,
OAES_RET_ARG2,
OAES_RET_ARG3,
OAES_RET_ARG4,
OAES_RET_ARG5,
OAES_RET_NOKEY,
OAES_RET_MEM,
OAES_RET_BUF,
OAES_RET_HEADER,
OAES_RET_COUNT
} OAES_RET;
#ifdef __cplusplus
}
#endif
#endif // _OAES_COMMON_H

View File

@ -0,0 +1,42 @@
/*
* ---------------------------------------------------------------------------
* OpenAES License
* ---------------------------------------------------------------------------
* Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com
* 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.
*
* 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 HOLDER 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 _OAES_CONFIG_H
#define _OAES_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif // _OAES_CONFIG_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,168 @@
/*
* ---------------------------------------------------------------------------
* OpenAES License
* ---------------------------------------------------------------------------
* Copyright (c) 2013, Nabil S. Al Ramli, www.nalramli.com
* 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.
*
* 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 HOLDER 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 _OAES_LIB_H
#define _OAES_LIB_H
#include "oaes_common.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
# ifdef OAES_SHARED
# ifdef oaes_lib_EXPORTS
# define OAES_API __declspec(dllexport)
# else
# define OAES_API __declspec(dllimport)
# endif
# else
# define OAES_API
# endif
#else
# define OAES_API
#endif // WIN32
#define OAES_BLOCK_SIZE 16
typedef void OAES_CTX;
/*
* oaes_set_option() takes one of these values for its [option] parameter
* some options accept either an optional or a required [value] parameter
*/
// no option
#define OAES_OPTION_NONE 0
// enable ECB mode, disable CBC mode
#define OAES_OPTION_ECB 1
// enable CBC mode, disable ECB mode
// value is optional, may pass uint8_t iv[OAES_BLOCK_SIZE] to specify
// the value of the initialization vector, iv
#define OAES_OPTION_CBC 2
#ifdef OAES_DEBUG
typedef int ( * oaes_step_cb ) (
const uint8_t state[OAES_BLOCK_SIZE],
const char * step_name,
int step_count,
void * user_data );
// enable state stepping mode
// value is required, must pass oaes_step_cb to receive the state at each step
#define OAES_OPTION_STEP_ON 4
// disable state stepping mode
#define OAES_OPTION_STEP_OFF 8
#endif // OAES_DEBUG
typedef uint16_t OAES_OPTION;
/*
* // usage:
*
* OAES_CTX * ctx = oaes_alloc();
* .
* .
* .
* {
* oaes_gen_key_xxx( ctx );
* {
* oaes_key_export( ctx, _buf, &_buf_len );
* // or
* oaes_key_export_data( ctx, _buf, &_buf_len );\
* }
* }
* // or
* {
* oaes_key_import( ctx, _buf, _buf_len );
* // or
* oaes_key_import_data( ctx, _buf, _buf_len );
* }
* .
* .
* .
* oaes_encrypt( ctx, m, m_len, c, &c_len );
* .
* .
* .
* oaes_decrypt( ctx, c, c_len, m, &m_len );
* .
* .
* .
* oaes_free( &ctx );
*/
OAES_API OAES_CTX * oaes_alloc();
OAES_API OAES_RET oaes_free( OAES_CTX ** ctx );
OAES_API OAES_RET oaes_set_option( OAES_CTX * ctx,
OAES_OPTION option, const void * value );
OAES_API OAES_RET oaes_key_gen_128( OAES_CTX * ctx );
OAES_API OAES_RET oaes_key_gen_192( OAES_CTX * ctx );
OAES_API OAES_RET oaes_key_gen_256( OAES_CTX * ctx );
// export key with header information
// set data == NULL to get the required data_len
OAES_API OAES_RET oaes_key_export( OAES_CTX * ctx,
uint8_t * data, size_t * data_len );
// directly export the data from key
// set data == NULL to get the required data_len
OAES_API OAES_RET oaes_key_export_data( OAES_CTX * ctx,
uint8_t * data, size_t * data_len );
// import key with header information
OAES_API OAES_RET oaes_key_import( OAES_CTX * ctx,
const uint8_t * data, size_t data_len );
// directly import data into key
OAES_API OAES_RET oaes_key_import_data( OAES_CTX * ctx,
const uint8_t * data, size_t data_len );
// set c == NULL to get the required c_len
OAES_API OAES_RET oaes_encrypt( OAES_CTX * ctx,
const uint8_t * m, size_t m_len, uint8_t * c, size_t * c_len );
// set m == NULL to get the required m_len
OAES_API OAES_RET oaes_decrypt( OAES_CTX * ctx,
const uint8_t * c, size_t c_len, uint8_t * m, size_t * m_len );
// set buf == NULL to get the required buf_len
OAES_API OAES_RET oaes_sprintf(
char * buf, size_t * buf_len, const uint8_t * data, size_t data_len );
#ifdef __cplusplus
}
#endif
#endif // _OAES_LIB_H

View File

@ -137,6 +137,8 @@
<ClCompile Include="ControlStream.c" />
<ClCompile Include="InputStream.c" />
<ClCompile Include="LinkedBlockingQueue.c" />
<ClCompile Include="OpenAES\oaes_base64.c" />
<ClCompile Include="OpenAES\oaes_lib.c" />
<ClCompile Include="PlatformSockets.c" />
<ClCompile Include="PlatformThreads.c" />
<ClCompile Include="RtspConnection.c" />
@ -151,6 +153,10 @@
<ClInclude Include="Limelight-internal.h" />
<ClInclude Include="Limelight.h" />
<ClInclude Include="LinkedBlockingQueue.h" />
<ClInclude Include="OpenAES\oaes_base64.h" />
<ClInclude Include="OpenAES\oaes_common.h" />
<ClInclude Include="OpenAES\oaes_config.h" />
<ClInclude Include="OpenAES\oaes_lib.h" />
<ClInclude Include="Platform.h" />
<ClInclude Include="PlatformSockets.h" />
<ClInclude Include="PlatformThreads.h" />

View File

@ -13,6 +13,9 @@
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Source Files\OpenAES">
<UniqueIdentifier>{fb820029-93ae-455c-bacc-d25a094c92c1}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ByteBuffer.c">
@ -54,37 +57,55 @@
<ClCompile Include="RtspParser.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="OpenAES\oaes_base64.c">
<Filter>Source Files\OpenAES</Filter>
</ClCompile>
<ClCompile Include="OpenAES\oaes_lib.c">
<Filter>Source Files\OpenAES</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="PlatformSockets.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="Platform.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="ByteBuffer.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="PlatformThreads.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="LinkedBlockingQueue.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="Video.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="Limelight-internal.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="Limelight.h">
<Filter>Source Files</Filter>
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Input.h">
<Filter>Source Files</Filter>
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Limelight.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Limelight-internal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Platform.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PlatformThreads.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Rtsp.h">
<Filter>Source Files</Filter>
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Video.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LinkedBlockingQueue.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PlatformSockets.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="OpenAES\oaes_base64.h">
<Filter>Source Files\OpenAES</Filter>
</ClInclude>
<ClInclude Include="OpenAES\oaes_common.h">
<Filter>Source Files\OpenAES</Filter>
</ClInclude>
<ClInclude Include="OpenAES\oaes_config.h">
<Filter>Source Files\OpenAES</Filter>
</ClInclude>
<ClInclude Include="OpenAES\oaes_lib.h">
<Filter>Source Files\OpenAES</Filter>
</ClInclude>
</ItemGroup>
</Project>