Access violation if GCM mode is set after cipher is initialized
@MHumm đang làm issue này rồi.
Từ ngày 8/5/2024.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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.
- Ngôn ngữ chính
- HTML
- Star
- 286
- Fork
- 78
- Merge trung bình
- 1 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của MHumm/DelphiEncryptionCompendium
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
CRC64 - PKI AdditionCó thể làm lại được @MHumm đã nhận 149 ngày trước và không có pull request nào đang mở. Đang mởenhancement help wanted
MHumm/DelphiEncryptionCompendium#93 · 1 bình luận · 1 người được giao ·
-
Missing PUInt8Array type in the GetIt version.Có thể làm lại được @MHumm đã nhận 160 ngày trước và không có pull request nào đang mở. Đang mởbug delphi
MHumm/DelphiEncryptionCompendium#92 · 2 bình luận · 1 người được giao ·
-
Help with demoĐang mởquestion
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 25/100
MHumm/DelphiEncryptionCompendium#91 · 6 bình luận ·
-
Chacha20 Poly1305Có thể làm lại được @MHumm đã nhận 459 ngày trước và không có pull request nào đang mở. Đang mởenhancement
MHumm/DelphiEncryptionCompendium#89 · 1 bình luận · 1 người được giao ·