|
|
@@ -63,23 +63,28 @@ type
|
|
|
const p: IGlvTypeBParameters): IECCurve; static; inline;
|
|
|
class function FromHex(const Hex: String): TBigInteger; static; inline;
|
|
|
|
|
|
+ class constructor CreateSecNamedCurves();
|
|
|
+ class destructor DestroySecNamedCurves();
|
|
|
+
|
|
|
public
|
|
|
- class function GetByName(const name: String): IX9ECParameters; static;
|
|
|
+ class function GetByName(const name: String): IX9ECParameters;
|
|
|
+ static; inline;
|
|
|
// /**
|
|
|
// * return the X9ECParameters object for the named curve represented by
|
|
|
// * the passed in object identifier. Null if the curve isn't present.
|
|
|
// *
|
|
|
// * @param oid an object identifier representing a named curve, if present.
|
|
|
// */
|
|
|
- class function GetByOid(const oid: IDerObjectIdentifier)
|
|
|
- : IX9ECParameters; static;
|
|
|
+ class function GetByOid(const oid: IDerObjectIdentifier): IX9ECParameters;
|
|
|
+ static; inline;
|
|
|
// /**
|
|
|
// * return the object identifier signified by the passed in name. Null
|
|
|
// * if there is no object identifier associated with name.
|
|
|
// *
|
|
|
// * @return the object identifier associated with name, if present.
|
|
|
// */
|
|
|
- class function GetOid(const name: String): IDerObjectIdentifier; static;
|
|
|
+ class function GetOid(const name: String): IDerObjectIdentifier;
|
|
|
+ static; inline;
|
|
|
// /**
|
|
|
// * return the named curve name represented by the given object identifier.
|
|
|
// */
|
|
|
@@ -727,22 +732,98 @@ type
|
|
|
|
|
|
end;
|
|
|
|
|
|
- class constructor CreateSecNamedCurves();
|
|
|
- class destructor DestroySecNamedCurves();
|
|
|
-
|
|
|
end;
|
|
|
|
|
|
implementation
|
|
|
|
|
|
{ TSecNamedCurves }
|
|
|
|
|
|
+class procedure TSecNamedCurves.DefineCurve(const name: String;
|
|
|
+ const oid: IDerObjectIdentifier; const holder: IX9ECParametersHolder);
|
|
|
+begin
|
|
|
+ FobjIds.Add(UpperCase(name), oid);
|
|
|
+ Fnames.Add(oid, name);
|
|
|
+ Fcurves.Add(oid, holder);
|
|
|
+end;
|
|
|
+
|
|
|
+class function TSecNamedCurves.ConfigureCurve(const curve: IECCurve): IECCurve;
|
|
|
+begin
|
|
|
+ result := curve;
|
|
|
+end;
|
|
|
+
|
|
|
+class function TSecNamedCurves.ConfigureCurveGlv(const c: IECCurve;
|
|
|
+ const p: IGlvTypeBParameters): IECCurve;
|
|
|
+var
|
|
|
+ glv: IGlvTypeBEndomorphism;
|
|
|
+begin
|
|
|
+ glv := TGlvTypeBEndomorphism.Create(c, p);
|
|
|
+ result := c.Configure().SetEndomorphism(glv).CreateCurve();
|
|
|
+end;
|
|
|
+
|
|
|
+class function TSecNamedCurves.FromHex(const Hex: String): TBigInteger;
|
|
|
+begin
|
|
|
+ result := TBigInteger.Create(1, THex.Decode(Hex));
|
|
|
+end;
|
|
|
+
|
|
|
+class function TSecNamedCurves.GetByOid(const oid: IDerObjectIdentifier)
|
|
|
+ : IX9ECParameters;
|
|
|
+var
|
|
|
+ holder: IX9ECParametersHolder;
|
|
|
+begin
|
|
|
+ if Fcurves.TryGetValue(oid, holder) then
|
|
|
+ begin
|
|
|
+ result := holder.Parameters
|
|
|
+ end
|
|
|
+ else
|
|
|
+ begin
|
|
|
+ result := Nil;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+class function TSecNamedCurves.GetOid(const name: String): IDerObjectIdentifier;
|
|
|
+begin
|
|
|
+ if not(FobjIds.TryGetValue(UpperCase(name), result)) then
|
|
|
+ begin
|
|
|
+ result := Nil;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+class function TSecNamedCurves.GetByName(const name: String): IX9ECParameters;
|
|
|
+var
|
|
|
+ oid: IDerObjectIdentifier;
|
|
|
+begin
|
|
|
+ oid := GetOid(name);
|
|
|
+ if oid = Nil then
|
|
|
+ begin
|
|
|
+ result := Nil;
|
|
|
+ end
|
|
|
+ else
|
|
|
+ begin
|
|
|
+ result := GetByOid(oid);
|
|
|
+ end;
|
|
|
+
|
|
|
+end;
|
|
|
+
|
|
|
+class function TSecNamedCurves.GetName(const oid: IDerObjectIdentifier): String;
|
|
|
+begin
|
|
|
+ if not(Fnames.TryGetValue(oid, result)) then
|
|
|
+ begin
|
|
|
+ result := '';
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+class function TSecNamedCurves.GetNames: TCryptoLibStringArray;
|
|
|
+begin
|
|
|
+ result := Fnames.Values.ToArray();
|
|
|
+end;
|
|
|
+
|
|
|
class constructor TSecNamedCurves.CreateSecNamedCurves;
|
|
|
begin
|
|
|
FobjIds := TDictionary<String, IDerObjectIdentifier>.Create();
|
|
|
Fnames := TDictionary<IDerObjectIdentifier, String>.Create();
|
|
|
Fcurves := TDictionary<IDerObjectIdentifier, IX9ECParametersHolder>.Create();
|
|
|
|
|
|
- TSecObjectIdentifiers.Boot;
|
|
|
+ // TSecObjectIdentifiers.Boot;
|
|
|
|
|
|
DefineCurve('secp112r1', TSecObjectIdentifiers.SecP112r1,
|
|
|
TSecp112r1Holder.Instance);
|
|
|
@@ -820,85 +901,6 @@ begin
|
|
|
Fcurves.Free;
|
|
|
end;
|
|
|
|
|
|
-class procedure TSecNamedCurves.DefineCurve(const name: String;
|
|
|
- const oid: IDerObjectIdentifier; const holder: IX9ECParametersHolder);
|
|
|
-begin
|
|
|
- FobjIds.Add(UpperCase(name), oid);
|
|
|
- Fnames.Add(oid, name);
|
|
|
- Fcurves.Add(oid, holder);
|
|
|
-end;
|
|
|
-
|
|
|
-class function TSecNamedCurves.ConfigureCurve(const curve: IECCurve): IECCurve;
|
|
|
-begin
|
|
|
- result := curve;
|
|
|
-end;
|
|
|
-
|
|
|
-class function TSecNamedCurves.ConfigureCurveGlv(const c: IECCurve;
|
|
|
- const p: IGlvTypeBParameters): IECCurve;
|
|
|
-var
|
|
|
- glv: IGlvTypeBEndomorphism;
|
|
|
-begin
|
|
|
- glv := TGlvTypeBEndomorphism.Create(c, p);
|
|
|
- result := c.Configure().SetEndomorphism(glv).CreateCurve();
|
|
|
-end;
|
|
|
-
|
|
|
-class function TSecNamedCurves.FromHex(const Hex: String): TBigInteger;
|
|
|
-begin
|
|
|
- result := TBigInteger.Create(1, THex.Decode(Hex));
|
|
|
-end;
|
|
|
-
|
|
|
-class function TSecNamedCurves.GetByOid(const oid: IDerObjectIdentifier)
|
|
|
- : IX9ECParameters;
|
|
|
-var
|
|
|
- holder: IX9ECParametersHolder;
|
|
|
-begin
|
|
|
- if Fcurves.TryGetValue(oid, holder) then
|
|
|
- begin
|
|
|
- result := holder.Parameters
|
|
|
- end
|
|
|
- else
|
|
|
- begin
|
|
|
- result := Nil;
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
-class function TSecNamedCurves.GetOid(const name: String): IDerObjectIdentifier;
|
|
|
-begin
|
|
|
- if not(FobjIds.TryGetValue(UpperCase(name), result)) then
|
|
|
- begin
|
|
|
- result := Nil;
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
-class function TSecNamedCurves.GetByName(const name: String): IX9ECParameters;
|
|
|
-var
|
|
|
- oid: IDerObjectIdentifier;
|
|
|
-begin
|
|
|
- oid := GetOid(name);
|
|
|
- if oid = Nil then
|
|
|
- begin
|
|
|
- result := Nil;
|
|
|
- end
|
|
|
- else
|
|
|
- begin
|
|
|
- result := GetByOid(oid);
|
|
|
- end;
|
|
|
-
|
|
|
-end;
|
|
|
-
|
|
|
-class function TSecNamedCurves.GetName(const oid: IDerObjectIdentifier): String;
|
|
|
-begin
|
|
|
- if not(Fnames.TryGetValue(oid, result)) then
|
|
|
- begin
|
|
|
- result := '';
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
-class function TSecNamedCurves.GetNames: TCryptoLibStringArray;
|
|
|
-begin
|
|
|
- result := Fnames.Values.ToArray();
|
|
|
-end;
|
|
|
-
|
|
|
{ TSecNamedCurves.TSecp112r1Holder }
|
|
|
|
|
|
function TSecNamedCurves.TSecp112r1Holder.CreateParameters: IX9ECParameters;
|