Advanced Encryption Standard AES - Rijndael - Assembler optimiert
Zum Code
In diesem Projekt habe ich meine eigene Implementierung von AES (Rijndael) verwirklicht. AES ist der Nachfolger vom alten Verschlüsselungsstandard DES (bzw. später Triple-DES). Wer mehr über AES erfahren möchte, kann sich bei Wikipedia informieren: http://de.wikipedia.org/wiki/AES

Die korrekte Ausführung des Algorithmus wird mittels einem einfachem Testmodul überprüft. Dennoch kann ich keine Fehlerlosigkeit garantieren, korrigiere aber gerne jeden Fehler den jemand findet. Für eine weitergehende sicherheitsrelevante Anwendung ist die Implementierung nicht ausreichend abgeschirmt, da weder Variablen gelöscht werden noch sonstige Daten abgeschirmt sind. Zusätzlich zum Testmodul existiert ein Speedtest-Modul, mit welchem die Ausführungszeit für einen Durchlauf gemessen werden kann. Hieraus wird zudem der theoretische Datendurchsatz errechnet.

Die Referenzimplementierung ist in reinem VB abgehandelt und kommentiert. Die Kommentare setzen allerdings Kenntnis von der Materie voraus. Theoretisch dürfte der Referenzcode mit allen vorgesehenen Bitlängen (128/196/256 Bit sowohl für Blöcke als auch Schlüssel) zurecht kommen. Zwecks verbesserter Performanz habe ich die Verschlüsselungsroutine ebenfalls in Assembler zur Verfügung gestellt. Diese Variante ist jedoch auf 128 Bit für die Blöcke und die Schlüssel begrenzt. Der beiliegende Assemblercode ist für MASM vorgesehen. Auf meinem Athlon XP2200+ erreicht die optimierte Variante einen theoretischen Datendurchsatz von ~72 Mb/s.

History
24.09.2004 Hinzugefügt
16.10.2004 Entschlüsselung nun auch in Assembler vorhanden

Autor: Dominik Auras <Dominik_auf_vbInside.de>

Code aus Hilfsfunktionen.bas
Option Explicit

Public Declare Function API_CallWindowProc Lib "user32" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As _
Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As _
Long) As Long

Public Function shr(x As Long, n As Long) As Long
Static asm(4) As Long

If asm(0) = 0 Then
asm(0) = &H33EC8B55: asm(1) = &H8BC88BC0
asm(2) = &H4D8A0845: asm(3) = &H5DE8D30C
asm(4) = &H10C2
End If

shr = API_CallWindowProc(VarPtr(asm(0)), x, n, 0&, 0&)
End Function

Public Function shl(x As Long, n As Long) As Long
Static asm(4) As Long

If asm(0) = 0 Then
asm(0) = &H33EC8B55: asm(1) = &H8BC88BC0
asm(2) = &H4D8A0845: asm(3) = &H5DE0D30C
asm(4) = &H10C2
End If

shl = API_CallWindowProc(VarPtr(asm(0)), x, n, 0&, 0&)
End Function

Public Sub SetLongArray_Row(a() As Long, Row1 As Long, Row2 As _
Long, ParamArray t())
Dim i As Long

For i = 0 To UBound(a, 1)
a(i, Row1, Row2) = t(i)
Next i
End Sub

Public Function Min(x As Long, y As Long) As Long
If x < y Then
Min = x
Else
Min = y
End If
End Function

Public Sub PrintBlock(block() As Byte)
Dim i As Long, j As Long, tmp As String

For j = 0 To UBound(block, 2)
For i = 0 To UBound(block, 1)
tmp = Hex(block(i, j))
If Len(tmp) < 2 Then
Log_NCR "0"
End If
Log_NCR tmp & " "
Next i
Log_NCR vbCrLf
Next j
Log_NCR vbCrLf
End Sub

Public Sub StringToBlock(inp As String, block() As Byte, blockbits _
As Long)
Dim i As Long, bInp() As Byte

ReDim block(blockbits / 32 - 1, 3)

bInp = StrConv(inp, vbFromUnicode)

For i = 0 To UBound(block, 1)
block(i, 0) = bInp(i * 4)
block(i, 1) = bInp(i * 4 + 1)
block(i, 2) = bInp(i * 4 + 2)
block(i, 3) = bInp(i * 4 + 3)
Next i
End Sub

Public Sub Log(x As String)
TestForm.Text1.Text = TestForm.Text1.Text & x & vbCrLf
TestForm.Text1.SelStart = Len(TestForm.Text1.Text)
DoEvents
End Sub

Public Sub Log_NCR(x As String)
TestForm.Text1.Text = TestForm.Text1.Text & x & vbCrLf
TestForm.Text1.SelStart = Len(TestForm.Text1.Text)
DoEvents
End Sub