Access violation if GCM mode is set after cipher is initialized
@MHumm já está trabalhando nisso.
Desde 8/5/2024.
Avaliação
Esta issue ainda não foi avaliada.
Descrição
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.
- Linguagem predominante
- HTML
- Estrelas
- 286
- Forks
- 78
- Merge médio
- 1d 4h
- PRs com merge (30d)
- 4
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de MHumm/DelphiEncryptionCompendium
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
-
CRC64 - PKI AdditionTalvez livre de novo @MHumm assumiu há 148 dias e não há nenhum pull request aberto. Abertaenhancement help wanted
MHumm/DelphiEncryptionCompendium#93 · 1 comentário · 1 responsável ·
-
Missing PUInt8Array type in the GetIt version.Talvez livre de novo @MHumm assumiu há 160 dias e não há nenhum pull request aberto. Abertabug delphi
MHumm/DelphiEncryptionCompendium#92 · 2 comentários · 1 responsável ·
-
Help with demoAbertaquestion
Dificuldade 4/5 1-2 dias Facilidade para iniciantes 25/100
MHumm/DelphiEncryptionCompendium#91 · 6 comentários ·
-
Chacha20 Poly1305Talvez livre de novo @MHumm assumiu há 458 dias e não há nenhum pull request aberto. Abertaenhancement
MHumm/DelphiEncryptionCompendium#89 · 1 comentário · 1 responsável ·