Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Coding Releases > Coding Snippets
You last visited: Today at 01:57

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C++ AES Implementation

Discussion on C++ AES Implementation within the Coding Snippets forum part of the Coding Releases category.

Reply
 
Old   #1

 
nico_w's Avatar
 
elite*gold: 0
Join Date: Aug 2008
Posts: 5,150
Received Thanks: 10,487
C++ AES Implementation

Hey,

unter dem Projekt "FoxCrypt" möchte ich verschiedene Verschlüsselungs- und Hashalgorithmen als alleinstehende C++-Klassen implementieren und veröffentlichen.
Den Anfang mache ich hier mit AES, zu dem ich leider keine wirklich alleinstehende Klasse für C++ finden konnte.
Meine AES-Klasse implementiert lediglich blockweise-Verschlüsselung, die anderen Modes (CBC, CFB, CTR, OFB etc.) folgen später. Das ganze ist natürlich noch etwas optimierungswürdig und unterstützt z.B. noch kein AES-NI, aber auch darum möchte ich mich später noch kümmern. Primärziel war hier für mich erst mal, eine übersichtliche und leicht anpassbare AES-Implementation in C++ zu haben und die möchte ich auch mit euch teilen.

FoxAES.cpp:
FoxAES.h:

GitHub Repository:

Die Verwendung ist sehr einfach, hier mal Beispielcode aus meiner Testanwendung:
Code:
FoxCrypt::AES ctx;
ctx.SetEncryptionKey(aesKey, FoxCrypt::AES_128);

for (uint32_t i = 0; i < blockCount; i++) {
	memcpy(decBlock, buffer, 16);
	ctx.EncryptBlock(decBlock, encBlock);
	memcpy(buffer, encBlock, 16);

	buffer += 16;
}

ctx.SetDecryptionKey(aesKey, FoxCrypt::AES_128);

for (uint32_t i = 0; i < blockCount; i++) {
	memcpy(encBlock, buffer, 16);
	ctx.DecryptBlock(encBlock, decBlock);
	memcpy(buffer, decBlock, 16);

	buffer += 16;
}
Gruß, Nico
nico_w is offline  
Thanks
5 Users
Old 12/14/2014, 22:06   #2

 
snow's Avatar
 
elite*gold: 724
Join Date: Mar 2011
Posts: 10,479
Received Thanks: 3,318
Arrow Coding Releases -> Coding Snippets

#moved

Schau mal noch bei Jabber rein, ist ja grauenhaft, dass du jeden Schritt da komplett hingeschrieben hast, ist das Premature Optimization oder was?
snow is offline  
Old 12/14/2014, 22:22   #3

 
nico_w's Avatar
 
elite*gold: 0
Join Date: Aug 2008
Posts: 5,150
Received Thanks: 10,487
Quote:
Originally Posted by snow View Post
#moved

Schau mal noch bei Jabber rein, ist ja grauenhaft, dass du jeden Schritt da komplett hingeschrieben hast, ist das Premature Optimization oder was?
Das hat nur den Grund, dass ich es an eine bestehende Implementation anpassen wollte (die ich leider nur als Binary hab).
Wird später alles noch ausgebessert.
nico_w is offline  
Old 12/19/2014, 21:06   #4
 
Mashkin's Avatar
 
elite*gold: 44
Join Date: May 2010
Posts: 2,053
Received Thanks: 1,747
Die Korrektheit kann ich nicht vollständig bewerten - dafür gibt es Testvektoren.

Die Runden sollten als Schleife ausgeführt werden, die einzige "Komplexität" ist hier der Erhalt der vorherigen Zustandsmatrix für den ShiftRows-Schritt.
Was mich stört ist die Verwendung von Lookup-Tabellen für MixColumn.
Die ist für eine operationssparsame Implementierung durchaus sehr angebracht (auf Kosten des höheren Speicherbedarfs), allerdings fände ich zum besseren Verständnis eine (ausgelagerte) Berechnungsvorschrift für die Tabellen sinnvoll.

Auch der Key Schedule könnte statt im Voraus bei Bedarf zwischen den Runden abgearbeitet werden - zumindest bei der Verschlüsselung.

Ich frage mich aber für welchen Anwendungsfall dein Projekt FoxCrypt Vorteile gegenüber existierenden Bibliotheken wie Crypto++ bringt.
Crypto++ im speziellen besteht zwar aus umfangreicherem Code, bietet aber bereits eine Vielzahl an Algorithmen, Hilfsfunktionen (z.B. Operationen in GF(2^8) die für AES ohne Lookup-Tabellen nötig sind) und - besonders bei AES - Hardwarebeschleunigung und funktioniert zudem plattformübergreifend.
Mashkin is offline  
Old 12/19/2014, 21:54   #5

 
snow's Avatar
 
elite*gold: 724
Join Date: Mar 2011
Posts: 10,479
Received Thanks: 3,318
Diese Version ist für einen bestimmten Zweck angepasst, deshalb sieht die auch ein wenig chaotisch aus. Zumindest war das mein letzter Stand.

Es sollte jedem natürlich klar sein, dass man keinesfalls eine eigene Implementierung eines Verschlüsselungsalgorithmus verwenden sollte, solange es keinen verdammt guten Grund dafür gibt.
snow is offline  
Thanks
2 Users
Reply


Similar Threads Similar Threads
A real AI bot implementation to SRO scene
08/19/2014 - SRO Coding Corner - 12 Replies
Hi all, I have been studying the A* algorithm for 2 weeks and finally sorted it out with practical codes that I have written. What I have been thinking about is writing a bot app with a real deal AI such as in Quake III . I know it is not an easy task but I want to do it to improve my skills and for the love of SRO. My ambition is to create bots which can pretty much act like human players specialized in jobbing. So there will be hunter , thief, trader bots. Of course they won't be...
Chi system implementation
07/28/2013 - CO2 Private Server - 6 Replies
Chi system implementation , i found this from the egy site. anyone could pin point where to put this codes? using Conquer_Online_Server.Client; using System; namespace Conquer_Online_Server.Network.GamePackets {
sms billing implementation
01/22/2013 - SRO Private Server - 1 Replies
Hey guys im working with a new sro server and we have a moneybookers and paypal set up but i wanted to set up a Fortumo or something like tht for our pinoy players and the others who dnt use playpal. I have never set up sms b4 to work with my server so i would really appreciate help figuring this out. A link to a guide or something thatll get me thru this pain in the ass siutation. You can reply here or add me to Skype if you able to help....thanks
[HELP] Problems with new map implementation
09/09/2012 - Metin2 Private Server - 0 Replies
Hy, I'm having some problems in implementing new maps. Everything is done right but i can only warp to the new map with one character. Each time I try to warp with a different character I am warped to map1/village. And I get the following error in syserr: SYSERR: Sep 9 18:21:04 :: Entergame: !GetMovablePosition (name TestWarp 1243200x1243300 map 195 changed to 1273200x1274000) I don't think that it is an implementation error because there is 1 character i can warp there. But I made 10...



All times are GMT +2. The time now is 01:57.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.