Skip to content

Commit 5fa9d48

Browse files
committed
Further removal of absolute
Removed further uses of absolute and got rid of a routine copying values from a constant into some array. Possible now as we give up compatibility with older versions.
1 parent 4fb625c commit 5fa9d48

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

Source/DECCipherModesGCM.pas

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ interface
3838
/// </summary>
3939
P128 = ^T128;
4040

41+
/// <summary>
42+
/// Array of 16 bytes
43+
/// </summary>
44+
T16ByteArray = array[0..15] of Byte;
45+
/// <summary>
46+
/// Pointer to an array of 16 bytes
47+
/// </summary>
48+
P16ByteArray = ^T16ByteArray;
49+
4150
/// <summary>
4251
/// A methopd of this type needs to be supplied for encrypting or decrypting
4352
/// a block via this GCM algorithm. The method is implemented as a parameter,
@@ -334,10 +343,6 @@ TGCM = class(TObject)
334343

335344
implementation
336345

337-
type
338-
T16ByteArray = array[0..15] of Byte;
339-
P16ByteArray = ^T16ByteArray;
340-
341346
function TGCM.XOR_T128(const x, y : T128): T128;
342347
begin
343348
Result[0] := x[0] xor y[0];
@@ -353,9 +358,9 @@ function TGCM.XOR_PointerWithT128(const x : Pointer; y : T128): T128;
353358
procedure TGCM.XOR_ArrayWithT128(const x: TBytes; XIndex, Count: UInt64; y: T128; var Result: TBytes);
354359
var
355360
i : integer;
356-
{ TODO : change to a pointer to y[0], to get rid of the absolute? }
357-
by : array[0..15] of byte absolute y[0];
361+
by : P16ByteArray;
358362
begin
363+
by := @y[0];
359364
for i := 0 to Count-1 do
360365
begin
361366
Result[XIndex] := x[XIndex] xor by[i];
@@ -366,9 +371,9 @@ procedure TGCM.XOR_ArrayWithT128(const x: TBytes; XIndex, Count: UInt64; y: T128
366371
function TGCM.poly_mult_H(const hx : T128): T128;
367372
var
368373
i : integer;
369-
{ TODO : change to a pointer to hx[0], to get rid of the absolute? }
370-
x : array[0..15] of byte absolute hx[0];
374+
x : P16ByteArray;
371375
begin
376+
x := @hx[0];
372377
Result := FM[0, x[0]];
373378

374379
for i := 1 to 15 do
@@ -382,9 +387,9 @@ procedure TGCM.SetAuthenticationCipherLength(var x : T128;
382387
AuthDataLength, CipherTextLength : UInt64);
383388
var
384389
i : integer;
385-
{ TODO : change to a pointer to x[0], to get rid of the absolute? }
386-
hx : array[0..15] of byte absolute x[0];
390+
hx : P16ByteArray;
387391
begin
392+
hx := @x[0];
388393
// al:
389394
x := nullbytes;
390395
i := 7;
@@ -450,10 +455,11 @@ procedure TGCM.GenerateTableM8Bit(const H : T128);
450455

451456
procedure TGCM.ShiftRight(var rx : T128);
452457
var
453-
{ TODO : change to a pointer to rx[0], to get rid of the absolute? }
454-
x : array[0..15] of byte absolute rx[0];
458+
x : P16ByteArray;
455459
i : integer;
456460
begin
461+
x := @rx[0];
462+
457463
for i := 15 downto 1 do
458464
x[i] := (x[i] shr 1) or ((x[i-1] and 1) shl 7);
459465

@@ -648,16 +654,11 @@ function TGCM.GetAuthenticationTagBitLength: UInt32;
648654
end;
649655

650656
function TGCM.GetStandardAuthenticationTagBitLengths: TStandardBitLengths;
651-
const
652-
BitLengths : array[0..4] of Uint16 = (96, 104, 112, 120, 128);
653657
var
654658
i : integer;
655659
begin
656660
SetLength(Result, 5);
657-
{ TODO: When 6.5 is started the array can be assigned directly again }
658-
// Result := [96, 104, 112, 120, 128];
659-
for i := 0 to high(BitLengths) do
660-
result[i] := BitLengths[i];
661+
Result := [96, 104, 112, 120, 128];
661662
end;
662663

663664
//

0 commit comments

Comments
 (0)