Bitcoin Forum
April 26, 2024, 05:07:24 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: is this encryption any good (nullius is welcome)  (Read 260 times)
Anti-Cen (OP)
Member
**
Offline Offline

Activity: 210
Merit: 26

High fees = low BTC price


View Profile
March 09, 2018, 12:17:14 PM
 #1

Unfortunately I am being forced to re-invent the wheel because high usage of AES encryption on
a windows machine falls over, leaks memory and programs go bang and I needed something that
does not use Microsoft little black box software that is fast and can encrypt 2mb chunks of data blocks.

RSA encryption from Microsoft cannot be trusted.
Code:
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(512);  // Key bits length
rsa.PersistKeyInCsp = false;
The second line of code is needed because it use to default to true and resulted in the keys being
stored in windows certificate store and put quite simply Microsoft now steels anything it can lay it's hands on
and goes as far as to run web-dav at night to scan remote disk drives on your LAN.

Here is the function and it works by shifting byte code to the right based on the key with a bit of salt thrown
in for good measure and works with a variable length key that can be HEX or even XYZ
Code:
private static ushort[] MakeShiftKeys(string Key)
       {//Conver HEX keys to array of numbers but will also work for other letters too
           ushort[] Shifts = new ushort[Key.Length];
           for (int f = 0; f <= Key.Length - 1; f++)
               if (Key[f] >= '0' && Key[f] <= '9') Shifts[f] = ushort.Parse(Key[f].ToString()); else Shifts[f] = (ushort)(Key[f] - 55);
           return Shifts;
       }

public static byte[] EncryptFast(byte[] Text, string Key)
       {//About 10 seconds per gigabyte on I7 PC using 1mb blocks
           ushort[] ShiftKeys = MakeShiftKeys(Key.ToUpper());
           ushort Count = 0; ushort Shift = 0;
           ushort R = (ushort)(Text.Length % 8);
           if (R == 0) R = (ushort)(Text.Length % 3);
           bool Even = R == 5;
           for (uint f = 0; f <= Text.Length - 1; f++)
           {
               if (Count != R) Shift = ShiftKeys[Count];
               else if (Even) Shift = 77;
               else Shift = 66;
               if ((byte)Text[f] + Shift + R <= 255) Text[f] = (byte)(Text[f] + Shift + R);
               else Text[f] = (byte)((Text[f] + Shift + R)-256);
               Even = !Even; Count++;
               if (Count > Key.Length - 1) Count = 0;
           }
           return Text;
       }

During tests this code was found to be 40% slower than using Microsoft AES function and this is because
using C# and byte arrays you have to cast the byte to an INT32 to preform sums so maybe I can fix it using
UN-SAFE section of code if I can remember enough C++.

Previously I have played around with BigINT and MOD but this was not fast enough for big blocks of data
and I know the above is not military grade encryption but how would you rate it and what can be done to
make it better without taking too much of a performance hit.

I was thinking of compressing the data using Microsoft's GZip before using this encryption function which can be done
by using just four lines of code.

Quote
MemoryStream MS=new MemoryStream();
using (GZipStream gz = new GZipStream(MS, CompressionMode.Compress, false))
               gz.Write(Data, 0, Data.Length);
return MS.ToArray();  

But given the amount of network activity that I see coming out from my machine from millions of Dll's
running inside surrogate processes that we have no control over anymore I think I would roll my own compression
if I could do it in under a months work.






Mining is CPU-wars and Intel, AMD like it nearly as much as big oil likes miners wasting electricity. Is this what mankind has come too.
1714108044
Hero Member
*
Offline Offline

Posts: 1714108044

View Profile Personal Message (Offline)

Ignore
1714108044
Reply with quote  #2

1714108044
Report to moderator
1714108044
Hero Member
*
Offline Offline

Posts: 1714108044

View Profile Personal Message (Offline)

Ignore
1714108044
Reply with quote  #2

1714108044
Report to moderator
The Bitcoin network protocol was designed to be extremely flexible. It can be used to create timed transactions, escrow transactions, multi-signature transactions, etc. The current features of the client only hint at what will be possible in the future.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714108044
Hero Member
*
Offline Offline

Posts: 1714108044

View Profile Personal Message (Offline)

Ignore
1714108044
Reply with quote  #2

1714108044
Report to moderator
1714108044
Hero Member
*
Offline Offline

Posts: 1714108044

View Profile Personal Message (Offline)

Ignore
1714108044
Reply with quote  #2

1714108044
Report to moderator
Qoheleth
Legendary
*
Offline Offline

Activity: 960
Merit: 1028


Spurn wild goose chases. Seek that which endures.


View Profile WWW
March 12, 2018, 09:06:48 PM
Merited by ABCbits (1)
 #2

If you're worried about Windows's crypto APIs stealing your encryption keys, why not just link against OpenSSL? It's got DLLs available for Windows apps, and then you know you've got a decent algorithm at least.

If there is something that will make Bitcoin succeed, it is growth of utility - greater quantity and variety of goods and services offered for BTC. If there is something that will make Bitcoin fail, it is the prevalence of users convinced that BTC is a magic box that will turn them into millionaires, and of the con-artists who have followed them here to devour them.
pebwindkraft
Sr. Member
****
Offline Offline

Activity: 257
Merit: 343


View Profile
March 13, 2018, 08:24:05 AM
 #3

When dealing with large data, wouldn’t you use symmetric encryption / stream cyphers? Maybe triple-DES and similar? With asymmetric encryption, you loose a lot of time. Encryption with asymmetric keys is awfully slow, and only used for short chunks of data. If you definitely need asymmetric keys, think about exchanging a key between both parties to transfer a key, which is then used for symmetric encryption of large data blocks.
HeRetiK
Legendary
*
Offline Offline

Activity: 2912
Merit: 2080


Cashback 15%


View Profile
March 13, 2018, 12:09:01 PM
Merited by ABCbits (1)
 #4

Never roll your own crypto, especially not your own algorithm. Merely shifting the bytes around, even with this odd / even conditional going on, is unlikely to beat the statistical analysis of a ciphertext, especially if you assume the algorithm to be known.

I'd follow Qoheleth's recommendation of simply using OpenSSL instead.


When dealing with large data, wouldn’t you use symmetric encryption / stream cyphers? Maybe triple-DES and similar? With asymmetric encryption, you loose a lot of time. Encryption with asymmetric keys is awfully slow, and only used for short chunks of data. If you definitely need asymmetric keys, think about exchanging a key between both parties to transfer a key, which is then used for symmetric encryption of large data blocks.

Triple-DES is deprecated with AES being the successor. Both are using a symmetric cipher, so in this case AES would be preferable. OP's cipher is also symmetric, so it doesn't look like asymmetric encryption is needed for their use case. Good point about asymmetric encryption such as RSA generally being much slower than symmetric encryption though.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
Anti-Cen (OP)
Member
**
Offline Offline

Activity: 210
Merit: 26

High fees = low BTC price


View Profile
March 13, 2018, 09:04:29 PM
 #5

If you're worried about Windows's crypto APIs stealing your encryption keys, why not just link against OpenSSL? It's got DLLs available for Windows apps, and then you know you've got a decent algorithm at least.
Distributing apps with Dll's is a pain in the bum and I like just a single .exe these days.

Bit of a pain programming this way in visual studio but i just use project folders these days to separate the sections of the project.

Mining is CPU-wars and Intel, AMD like it nearly as much as big oil likes miners wasting electricity. Is this what mankind has come too.
Anti-Cen (OP)
Member
**
Offline Offline

Activity: 210
Merit: 26

High fees = low BTC price


View Profile
March 13, 2018, 09:09:36 PM
 #6

When dealing with large data, wouldn’t you use symmetric encryption / stream cyphers? Maybe triple-DES and similar? With asymmetric encryption, you loose a lot of time. Encryption with asymmetric keys is awfully slow, and only used for short chunks of data. If you definitely need asymmetric keys, think about exchanging a key between both parties to transfer a key, which is then used for symmetric encryption of large data blocks.

I didn't think it was that slow and the bottleneck is going to be sending the data across the wire so I use Gzip on the data first, encrypt and then send it out or write to file
however i did play around with pointers and unsafe/unchecked code in C# but it didn't speed it up really so i dumped that plan.

Mining is CPU-wars and Intel, AMD like it nearly as much as big oil likes miners wasting electricity. Is this what mankind has come too.
Anti-Cen (OP)
Member
**
Offline Offline

Activity: 210
Merit: 26

High fees = low BTC price


View Profile
March 13, 2018, 09:49:41 PM
 #7

Never roll your own crypto, especially not your own algorithm. Merely shifting the bytes around, even with this odd / even conditional going on, is unlikely to beat the statistical analysis of a ciphertext, especially if you assume the algorithm to be known.

I'd follow Qoheleth's recommendation of simply using OpenSSL instead.

Yes I hear this and I admit that I am no crypto mathematics expert 

Key exchange is using Secp256k1 which i like, don't want nothing that is black-boxed, dills or anything from Microsoft because they might not be able to
crack Secp256k1 but then sending the exchanged keys to back-door bills ms-spyware kind of defeats the whole point but that's just what the code is doing
that I nicked the Secp256k1 code from does and it's a big red flag too me.

From the little bit I know I think I could do something much more secure using BigINT's but that's going to be slow on 2mb data blocks
that i intend mainly to be used for file transfer and sending large node lists.

I am keeping the sockets open (Not REST) so I can spice it up using injection in bi-directional bound sockets because clients also become servers in
what I am trying to build but instead of working as IP/Port like the internet works its going to be more like Secp256k1 public-key/service with possible
relays in the middle so that no node knows who is really requesting the data and the code is using keys from that key exchange and is not primary.

Really it's just the backbone network I am building that I intend to have as secure as possible so apps can be built on top of it
with all the encryption and node discovery work already done for the apps.

Mining is CPU-wars and Intel, AMD like it nearly as much as big oil likes miners wasting electricity. Is this what mankind has come too.
Qoheleth
Legendary
*
Offline Offline

Activity: 960
Merit: 1028


Spurn wild goose chases. Seek that which endures.


View Profile WWW
March 15, 2018, 04:45:50 PM
 #8

Distributing apps with Dll's is a pain in the bum and I like just a single .exe these days.

Bit of a pain programming this way in visual studio but i just use project folders these days to separate the sections of the project.
If you want everything to be packaged in a single executable file, you can use the .lib OpenSSL binaries instead of .dlls. Or https://stackoverflow.com/questions/18486243/how-do-i-build-openssl-statically-linked-against-windows-runtimecompile them from OpenSSL source yourself, if you don't trust whoever posted these.

If there is something that will make Bitcoin succeed, it is growth of utility - greater quantity and variety of goods and services offered for BTC. If there is something that will make Bitcoin fail, it is the prevalence of users convinced that BTC is a magic box that will turn them into millionaires, and of the con-artists who have followed them here to devour them.
Anti-Cen (OP)
Member
**
Offline Offline

Activity: 210
Merit: 26

High fees = low BTC price


View Profile
March 15, 2018, 05:26:40 PM
Last edit: March 15, 2018, 07:54:09 PM by Anti-Cen
 #9

If you want everything to be packaged in a single executable file, you can use the .lib OpenSSL binaries instead of .dlls. Or https://stackoverflow.com/questions/18486243/how-do-i-build-openssl-statically-linked-against-windows-runtimecompile them from OpenSSL source yourself, if you don't trust whoever posted these.

Yes and thanks for the link so I will see if it's not too bloated and run some bench marks on the speed and will report back
with my findings.

Quote
The script assumes you are on Windows.
The script assumes you have Visual Studio 2010, 2013 or 2015 installed in all the usual places. Important: If you have a different installation folder, your mileage may vary
The script assumes you have downloaded an OpenSSL tarball, like this one.
The script assumes you have Python (2.7 or 3.x) installed and on your PATH
The script assumes you have 7-zip installed (doesn't need to be on your PATH)
You need Perl. For Windows, ActivePerl is probably the best choice.
You need Nasm.
Choose the script you want to use and edit it. For example, let's take a look at the top of rebuild_openssl_vs2015.cmd:

Me is not going to these lengths, I know nothing about Perl and was expecting a VS C# project to play with so maybe I will
have a quick search around and see whats going.

The download from David-Reguera went over 200mb and it contains hundreds of HTML files in the
vs-2010 folder but no solution file or project folder which is sort of a basic requirement for VS projects that
contains fifty C++ Header files alone.

I want something that's KISS but gets the job done

Back again.

Stackoverflow.com are mouth peaces for Microsoft, defenders of the faith like we have here with bitcoins and they won't hear a world said against
it's MS pay masters and reading a few posts on SO you get the impression that they discourage any encryption that does not fall back
on Microsoft's (un-trusted) black box code so I am not really finding what I am looking for but they are not alone, "The code project" is just as bad too.

Come on someone must have a bit of code written for windows that does encryption based on a Key and uses less than a hundred lines of
code that's fast enough for the job I want or has it all been scrubbed from the net making my theory quite plausible.

This code I wrote offers better security but it's too slow for 2mb blocks
Code:
public static byte[] Encryption(Privateaddress Keys, byte[] data,bool UsePublicKey)
        {
            BigInteger encData = 0;
            if (data == null) throw new ArgumentNullException("data");
            int maxDataLength = (Keys.KeySize / 8) - 6;
            if (data.Length > maxDataLength)throw new ArgumentOutOfRangeException("data", string.Format("Maximum data length for the current key size ({0} bits) is {1} bytes (current length: {2} bytes)",Keys.KeySize, maxDataLength, data.Length));
            BigInteger numData = GetBig(AddPadding(data));//Add 4 byte padding to the data, and convert to BigInteger struct
            BigInteger Exponent = StringToBig(Keys.Exponent);
            BigInteger Modulus = StringToBig(Keys.PublicAddress);
            BigInteger D = StringToBig(Keys.PrivateAddress);
            if (UsePublicKey)
                encData = BigInteger.ModPow(numData, D, Modulus);
            else
                encData = BigInteger.ModPow(numData, Exponent, Modulus);
            return encData.ToByteArray();
        }

Where is that rijndael dude when you want him  Cheesy


Mining is CPU-wars and Intel, AMD like it nearly as much as big oil likes miners wasting electricity. Is this what mankind has come too.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!