Skip to content

Commit

Permalink
Merge pull request #16 from ymaktepi/arm64
Browse files Browse the repository at this point in the history
Add arm64 compilation support
  • Loading branch information
Minege authored Aug 5, 2019
2 parents c2125de + 8ec5b7c commit 1224658
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 135 deletions.
206 changes: 103 additions & 103 deletions _eSSP/lib/ITLSSPProc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#include "ITLSSPProc.h"
#include <stdlib.h>
#include "Random.h"
#include "Encryption.h"
#include "../inc/ssp_defines.h"
#include <unistd.h>
#include "Encryption.h"
#include "../inc/ssp_defines.h"
#include <unistd.h>
#include <stdio.h>

#include <pthread.h>
extern unsigned char download_in_progress;

#include <pthread.h>
extern unsigned char download_in_progress;


#define VER_MAJ 1 // not > 255
#define VER_MIN 1 // not > 255
Expand Down Expand Up @@ -118,7 +118,7 @@ int CreateSSPHostEncryptionKey(SSP_KEYS* keyArray)

for(i = 0; i < *lengthIn; i++)
tmpData[i + 5] = dataIn[i];



/* add random packing data */
for(i = 0; i < packLength; i++)
Expand Down Expand Up @@ -173,99 +173,99 @@ int CreateHostInterKey(SSP_KEYS * keyArray)
}




void __attribute__ ((constructor)) my_init(void)
{
int i;
for(i = 0; i < MAX_SSP_PORT; i++){
encPktCount[i] = 0;
sspSeq[i] = 0x80;
}
srand((int)GetRTSC());
download_in_progress = 0;
}
void __attribute__ ((destructor)) my_fini(void)
{
if (download_in_progress)
{
printf("Waiting for download to complete...\n");
while (download_in_progress)
sleep(1);
}
}

/*
Name: NegotiateSSPEncryption
Inputs:
SSP_PORT The port handle (returned from OpenSSPPort) of the port to use
char ssp_address: The ssp_address to negotiate on
SSP_FULL_KEY * key: The ssp encryption key to be used
Return:
1 on success
0 on failure
Notes:
Only the EncryptKey iin SSP_FULL_KEY will be set. The FixedKey needs to be set by the user
*/
int NegotiateSSPEncryption(SSP_PORT port, const char ssp_address, SSP_FULL_KEY * key)
{
SSP_KEYS temp_keys;
SSP_COMMAND sspc;
unsigned char i;
//setup the intial host keys
if (InitiateSSPHostKeys(&temp_keys,ssp_address) == 0)
return 0;
sspc.EncryptionStatus = 0;
sspc.RetryLevel = 2;
sspc.Timeout = 1000;
sspc.SSPAddress = ssp_address;

//make sure we can talk to the unit
sspc.CommandDataLength = 1;
sspc.CommandData[0] = SSP_CMD_SYNC;
SSPSendCommand(port,&sspc);
if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
return 0;

//setup the generator
sspc.CommandDataLength = 9;
sspc.CommandData[0] = SSP_CMD_SET_GENERATOR;
for (i = 0; i < 8 ; ++i)
sspc.CommandData[1+i] = (unsigned char)(temp_keys.Generator >> (i*8));
//send the command
SSPSendCommand(port,&sspc);
if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
return 0;

//setup the modulus
sspc.CommandDataLength = 9;
sspc.CommandData[0] = SSP_CMD_SET_MODULUS;
for (i = 0; i < 8 ; ++i)
sspc.CommandData[1+i] = (unsigned char)(temp_keys.Modulus >> (i*8));
//send the command
SSPSendCommand(port,&sspc);
if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
return 0;

//swap keys
sspc.CommandDataLength = 9;
sspc.CommandData[0] = SSP_CMD_REQ_KEY_EXCHANGE;
for (i = 0; i < 8 ; ++i)
sspc.CommandData[1+i] = (unsigned char)(temp_keys.HostInter >> (i*8));
//send the command
SSPSendCommand(port,&sspc);
if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
return 0;

//read the slave key
temp_keys.SlaveInterKey = 0;
for (i = 0; i < 8 ; ++i)
temp_keys.SlaveInterKey += ((long long)(sspc.ResponseData[1+i])) << (8*i);


if (CreateSSPHostEncryptionKey(&temp_keys) == 0)
return 0;
key->EncryptKey = temp_keys.KeyHost;
return 1;
}



void __attribute__ ((constructor)) my_init(void)
{
int i;
for(i = 0; i < MAX_SSP_PORT; i++){
encPktCount[i] = 0;
sspSeq[i] = 0x80;
}
srand((int)GetSeed());
download_in_progress = 0;
}
void __attribute__ ((destructor)) my_fini(void)
{
if (download_in_progress)
{
printf("Waiting for download to complete...\n");
while (download_in_progress)
sleep(1);
}
}

/*
Name: NegotiateSSPEncryption
Inputs:
SSP_PORT The port handle (returned from OpenSSPPort) of the port to use
char ssp_address: The ssp_address to negotiate on
SSP_FULL_KEY * key: The ssp encryption key to be used
Return:
1 on success
0 on failure
Notes:
Only the EncryptKey iin SSP_FULL_KEY will be set. The FixedKey needs to be set by the user
*/
int NegotiateSSPEncryption(SSP_PORT port, const char ssp_address, SSP_FULL_KEY * key)
{
SSP_KEYS temp_keys;
SSP_COMMAND sspc;
unsigned char i;
//setup the intial host keys
if (InitiateSSPHostKeys(&temp_keys,ssp_address) == 0)
return 0;
sspc.EncryptionStatus = 0;
sspc.RetryLevel = 2;
sspc.Timeout = 1000;
sspc.SSPAddress = ssp_address;

//make sure we can talk to the unit
sspc.CommandDataLength = 1;
sspc.CommandData[0] = SSP_CMD_SYNC;
SSPSendCommand(port,&sspc);
if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
return 0;

//setup the generator
sspc.CommandDataLength = 9;
sspc.CommandData[0] = SSP_CMD_SET_GENERATOR;
for (i = 0; i < 8 ; ++i)
sspc.CommandData[1+i] = (unsigned char)(temp_keys.Generator >> (i*8));
//send the command
SSPSendCommand(port,&sspc);
if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
return 0;

//setup the modulus
sspc.CommandDataLength = 9;
sspc.CommandData[0] = SSP_CMD_SET_MODULUS;
for (i = 0; i < 8 ; ++i)
sspc.CommandData[1+i] = (unsigned char)(temp_keys.Modulus >> (i*8));
//send the command
SSPSendCommand(port,&sspc);
if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
return 0;

//swap keys
sspc.CommandDataLength = 9;
sspc.CommandData[0] = SSP_CMD_REQ_KEY_EXCHANGE;
for (i = 0; i < 8 ; ++i)
sspc.CommandData[1+i] = (unsigned char)(temp_keys.HostInter >> (i*8));
//send the command
SSPSendCommand(port,&sspc);
if (sspc.ResponseData[0] != SSP_RESPONSE_OK)
return 0;

//read the slave key
temp_keys.SlaveInterKey = 0;
for (i = 0; i < 8 ; ++i)
temp_keys.SlaveInterKey += ((long long)(sspc.ResponseData[1+i])) << (8*i);


if (CreateSSPHostEncryptionKey(&temp_keys) == 0)
return 0;
key->EncryptKey = temp_keys.KeyHost;
return 1;
}
48 changes: 20 additions & 28 deletions _eSSP/lib/Random.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

//#include "stdafx.h"
//#include "stdafx.h"
#include "../inc/itl_types.h"
#include <stdlib.h>
#include <stdio.h>
#include "Random.h"

#include <sys/time.h>


/* Generates a large prime number by
Expand Down Expand Up @@ -80,7 +81,7 @@ long long XpowYmodN(long long x, long long y, long long N)
long long result = 1;

const long long oneShift63 = (( long long) 1) << 63;


if (y==1) return (x % N);

for (i = 0; i < 64; y <<= 1, i++){
Expand Down Expand Up @@ -108,43 +109,34 @@ unsigned long long GenerateRandomNumber(void)

LFSR(x);

n = GetRTSC();
n = GetSeed();

rnd ^= n^x;

ROT(rnd,7);

ret = (unsigned long long)GetRTSC() + (unsigned long long)rnd;
ret = (unsigned long long)GetSeed() + (unsigned long long)rnd;

return ret;
}







/* Returns the Read Time Stamp Counter of the CPU
| The instruction returns in registers EDX:EAX the count of ticks from processor reset.
| Added in Pentium. Opcode: 0F 31. */

long long GetRTSC( void )
{
/*int tmp1 = 0;
int tmp2 = 0;
__asm
{
RDTSC; //Clock cycles since CPU started
mov tmp1, eax;
mov tmp2, edx;
}
return ((long long)tmp1 * (long long)tmp2);*/
long long result;
asm ("RDTSC" : "=A" (result));
return result;

long long GetSeed( void )
{
// arm32 or arm64 architectures
#if defined __arm__ || defined __aarch64__
struct timeval currentTime;
gettimeofday(&currentTime, NULL);
long microsecond_time = (currentTime.tv_sec * (int)1e6 + currentTime.tv_usec) % __LONG_MAX__;
long long seed = microsecond_time*getpid() % __LONG_LONG_MAX__;
return seed;
#else
long long result;
asm ("RDTSC" : "=A" (result));
return result;
#endif
}

2 changes: 1 addition & 1 deletion _eSSP/lib/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ unsigned char MillerRabin (long long n, long long trials);
unsigned char IsItPrime (long long n, long long a);
long long XpowYmodN(long long x, long long y, long long N);
unsigned long long GenerateRandomNumber(void);
long long GetRTSC( void );
long long GetSeed( void ); //NIX dependant



Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class ESSPBuild(build):
def run(self):
# run original build code
build.run(self)

cmd = [
'make',
]
Expand Down Expand Up @@ -45,11 +44,11 @@ def run(self):


setup(name="eSSP6",
version="1.0.8",
version="1.0.9",
description="Encrypted Smiley Secure Protocol Python 3 Implementation",
long_description="Description is avaible in the github repository",
author="Loan & Innovative Technology (Some of the C code)",
author_email="minege@protonmail.com",
author_email="minege02@gmail.com",
platforms=["cygwin","osx"],
license="MIT",
url="https://github.com/Minege/eSSP",
Expand Down

0 comments on commit 1224658

Please sign in to comment.