Access violation if GCM mode is set after cipher is initialized
@MHumm arbeitet bereits daran.
Seit 08.5.2024.
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
To Reproduce
- Open demo project Cipher_Console
- Change Cipher.Mode to cmGCM
- Run the code. You receive EAccessViolation
Usually, if you change the cipher mode after the cipher has been initialized, then TDECCipher.SetMode should call Done on the cipher and re-initialize it.
GCM Encode requires that TGCM.Init is called and has set FEncryptionMethod := EncryptionMethod. However, if Ciper.Mode is set after the cipher has been initialized, then TGCM is created but TGCM.Init has not been called.
procedure TDECCipherModes.InitMode;
begin
if FMode = TCipherMode.cmGCM then
begin
if Context.BlockSize = 16 then
FGCM := TGCM.Create
else
// GCM requires a cipher with 128 bit block size
raise EDECCipherException.CreateResFmt(@sInvalidBlockSize,
[128, GetEnumName(TypeInfo(TCipherMode),
Integer(FMode))]);
end
else
if Assigned(FGCM) then
FreeAndNil(FGCM);
end;
The program flow if Mode has been set before init:
- TDECCipher.Init()
- TDECCipher.Init()
- TDECCipherModes.OnAfterInitVectorInitialized ( calls
FGCM.Init(self.DoEncode, OriginalInitVector)) - TGCM.Init
The program flow if Mode has been set after init:
- TDECCipher.SetMode
- TDECCipherModes.InitMode
- TGCM.Create, but not TGCM.Init ( I am not sure where I get
OriginalInitVectorfrom )
So... what do we do? We probably need to preserve the InitVector, so we can call TGCM.Init with the correct parameters.
The other solution is to forbid to change the mode after the cipher has been initialized. But this is a code breaking change.
- Vorherrschende Sprache
- HTML
- Sterne
- 286
- Forks
- 78
- Ø Merge
- 1 T. 4 Std.
- Gemergte PRs (30 T.)
- 4
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus MHumm/DelphiEncryptionCompendium
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
CRC64 - PKI AdditionEvtl. wieder frei @MHumm hat das vor 149 Tagen übernommen, und es ist kein Pull Request offen. Offenenhancement help wanted
MHumm/DelphiEncryptionCompendium#93 · 1 Kommentar · 1 zugewiesene Person ·
-
Missing PUInt8Array type in the GetIt version.Evtl. wieder frei @MHumm hat das vor 161 Tagen übernommen, und es ist kein Pull Request offen. Offenbug delphi
MHumm/DelphiEncryptionCompendium#92 · 2 Kommentare · 1 zugewiesene Person ·
-
Help with demoOffenquestion
Schwierigkeit 4/5 1-2 Tage Anfängerfreundlichkeit 25/100
MHumm/DelphiEncryptionCompendium#91 · 6 Kommentare ·
-
Chacha20 Poly1305Evtl. wieder frei @MHumm hat das vor 459 Tagen übernommen, und es ist kein Pull Request offen. Offenenhancement
MHumm/DelphiEncryptionCompendium#89 · 1 Kommentar · 1 zugewiesene Person ·