Access violation if GCM mode is set after cipher is initialized
@MHumm ya está trabajando en esto.
Desde el 8/5/2024.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
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.
- Lenguaje dominante
- HTML
- Estrellas
- 286
- Forks
- 78
- Merge medio
- 1 d 23 min
- PR fusionados (30 d)
- 5
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de MHumm/DelphiEncryptionCompendium
-
CRC64 - PKI AdditionQuizá libre de nuevo @MHumm la tomó hace 151 días y no hay ningún pull request abierto. Abiertoenhancement help wanted
MHumm/DelphiEncryptionCompendium#93 · 1 comentario · 1 asignado ·
-
Missing PUInt8Array type in the GetIt version.Quizá libre de nuevo @MHumm la tomó hace 162 días y no hay ningún pull request abierto. Abiertobug delphi
MHumm/DelphiEncryptionCompendium#92 · 2 comentarios · 1 asignado ·
-
Confused by NEXTGEN directiveQuizá libre de nuevo @MHumm la tomó hace 533 días y no hay ningún pull request abierto. Abiertobug
MHumm/DelphiEncryptionCompendium#88 · 8 comentarios · 1 asignado ·
-
Authenticated tag is wrong on streamsQuizá libre de nuevo @MHumm la tomó hace 543 días y no hay ningún pull request abierto. Abiertobug
MHumm/DelphiEncryptionCompendium#87 · 20 comentarios · 1 asignado ·
-
Support for AEGIS 256Quizá libre de nuevo @MHumm la tomó hace 854 días y no hay ningún pull request abierto. Abiertoenhancement help wanted
MHumm/DelphiEncryptionCompendium#77 · 3 comentarios · 1 reacción · 1 asignado ·