| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- { *********************************************************************************** }
- { * CryptoLib Library * }
- { * Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe * }
- { * Github Repository <https://github.com/Xor-el> * }
- { * Distributed under the MIT software license, see the accompanying file LICENSE * }
- { * or visit http://www.opensource.org/licenses/mit-license.php. * }
- { * Acknowledgements: * }
- { * * }
- { * Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring * }
- { * development of this library * }
- { * ******************************************************************************* * }
- (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
- unit ClpWNafPreCompInfo;
- {$I ..\..\..\Include\CryptoLib.inc}
- interface
- uses
- ClpCryptoLibTypes,
- ClpIECC,
- ClpIWNafPreCompInfo,
- ClpIPreCompInfo;
- type
- /// <summary>
- /// Class holding precomputation data for the WNAF (Window Non-Adjacent
- /// Form) algorithm.
- /// </summary>
- TWNafPreCompInfo = class sealed(TInterfacedObject, IPreCompInfo,
- IWNafPreCompInfo)
- strict private
- var
- /// <summary>
- /// Array holding the precomputed <c>ECPoint</c>s used for a Window NAF
- /// multiplication.
- /// </summary>
- FPreComp: TCryptoLibGenericArray<IECPoint>;
- /// <summary>
- /// Array holding the negations of the precomputed <c>ECPoint</c>s used
- /// for a Window NAF multiplication.
- /// </summary>
- FPreCompNeg: TCryptoLibGenericArray<IECPoint>;
- /// <summary>
- /// Holds an <c>ECPoint</c> representing Twice(this). Used for the Window
- /// NAF multiplication to create or extend the precomputed values.
- /// </summary>
- FTwice: IECPoint;
- FConfWidth, FWidth: Int32;
- {$IFNDEF FPC}
- {$IFDEF HAS_VOLATILE}[volatile]
- {$ENDIF}
- {$ENDIF}
- FPromotionCountdown: Int32;
- function GetPreComp: TCryptoLibGenericArray<IECPoint>; inline;
- procedure SetPreComp(const Value: TCryptoLibGenericArray<IECPoint>); inline;
- function GetPreCompNeg: TCryptoLibGenericArray<IECPoint>; inline;
- procedure SetPreCompNeg(const Value
- : TCryptoLibGenericArray<IECPoint>); inline;
- function GetTwice: IECPoint; inline;
- procedure SetTwice(const Value: IECPoint); inline;
- function GetConfWidth: Int32; inline;
- procedure SetConfWidth(Value: Int32); inline;
- function GetWidth: Int32; inline;
- procedure SetWidth(Value: Int32); inline;
- function GetPromotionCountdown: Int32; inline;
- procedure SetPromotionCountdown(Value: Int32); inline;
- function DecrementPromotionCountdown: Int32; inline;
- function IsPromoted: Boolean; inline;
- public
- constructor Create();
- destructor Destroy; override;
- property PreComp: TCryptoLibGenericArray<IECPoint> read GetPreComp
- write SetPreComp;
- property PreCompNeg: TCryptoLibGenericArray<IECPoint> read GetPreCompNeg
- write SetPreCompNeg;
- property Twice: IECPoint read GetTwice write SetTwice;
- property ConfWidth: Int32 read GetConfWidth write SetConfWidth;
- property Width: Int32 read GetWidth write SetWidth;
- property PromotionCountdown: Int32 read GetPromotionCountdown
- write SetPromotionCountdown;
- end;
- implementation
- { TWNafPreCompInfo }
- constructor TWNafPreCompInfo.Create;
- begin
- inherited Create();
- FConfWidth := -1;
- FWidth := -1;
- FPromotionCountdown := 4;
- end;
- function TWNafPreCompInfo.DecrementPromotionCountdown: Int32;
- var
- t: Int32;
- begin
- t := PromotionCountdown;
- if (t > 0) then
- begin
- System.Dec(t);
- PromotionCountdown := t;
- end;
- result := t;
- end;
- destructor TWNafPreCompInfo.Destroy;
- var
- i: Integer;
- begin
- if Assigned(FPreComp) then
- begin
- for i := 0 to Length(FPreComp) - 1 do
- FPreComp[i] := nil;
- FPreComp := nil;
- end;
- if Assigned(FPreCompNeg) then
- begin
- for i := 0 to Length(FPreCompNeg) - 1 do
- FPreCompNeg[i] := nil;
- FPreCompNeg := nil;
- end;
- FTwice := nil;
- inherited;
- end;
- function TWNafPreCompInfo.GetConfWidth: Int32;
- begin
- result := FConfWidth;
- end;
- function TWNafPreCompInfo.GetPreComp: TCryptoLibGenericArray<IECPoint>;
- begin
- result := FPreComp;
- end;
- function TWNafPreCompInfo.GetPreCompNeg: TCryptoLibGenericArray<IECPoint>;
- begin
- result := FPreCompNeg;
- end;
- function TWNafPreCompInfo.GetPromotionCountdown: Int32;
- begin
- {$IFDEF FPC}
- result := {$IFDEF HAS_VOLATILE}volatile{$ENDIF}(FPromotionCountdown);
- {$ELSE}
- result := FPromotionCountdown;
- {$ENDIF}
- end;
- function TWNafPreCompInfo.GetTwice: IECPoint;
- begin
- result := FTwice;
- end;
- function TWNafPreCompInfo.GetWidth: Int32;
- begin
- result := FWidth;
- end;
- function TWNafPreCompInfo.IsPromoted: Boolean;
- begin
- result := PromotionCountdown <= 0;
- end;
- procedure TWNafPreCompInfo.SetConfWidth(Value: Int32);
- begin
- FConfWidth := Value;
- end;
- procedure TWNafPreCompInfo.SetPreComp(const Value
- : TCryptoLibGenericArray<IECPoint>);
- begin
- FPreComp := Value;
- end;
- procedure TWNafPreCompInfo.SetPreCompNeg(const Value
- : TCryptoLibGenericArray<IECPoint>);
- begin
- FPreCompNeg := Value;
- end;
- procedure TWNafPreCompInfo.SetPromotionCountdown(Value: Int32);
- begin
- {$IFDEF FPC}
- FPromotionCountdown := {$IFDEF HAS_VOLATILE}volatile{$ENDIF}(Value);
- {$ELSE}
- FPromotionCountdown := Value;
- {$ENDIF}
- end;
- procedure TWNafPreCompInfo.SetTwice(const Value: IECPoint);
- begin
- FTwice := Value;
- end;
- procedure TWNafPreCompInfo.SetWidth(Value: Int32);
- begin
- FWidth := Value;
- end;
- end.
|