private void startTransferProductProcess(DataModels.Warehouse.TransferProduct dataModel, IDAL dal) { int processDefinitionId = _parameterReader.ReadPublicParameter <int>("MagazalarArasiTransferSureci", 2016); var sourceStore = dal.Read <Store>(dataModel.SourceStore); var intakeBranchId = dataModel.DestinationStore == 999 ? 999 : dal.Read <Store>(dataModel.DestinationStore).OrganizationBranch; GroupOperations gop = new GroupOperations(dal); Group g = gop.FindGroup("Mağazalar Arası Ürün Transfer Kullanıcıları"); Group gWarehouse = gop.FindGroup("Depo Sorumlusu"); IProcessInstance processInstance = new ProcessInstance(processDefinitionId, OTApplication.Context.User.Id); //Set Process Variables processInstance.AddProcessVariable("user", OTApplication.Context.User.Id); processInstance.AddProcessVariable("screenReference", "Warehouse#TransferProductListComponent#" + dataModel.TransferProductId); processInstance.AddProcessVariable("sendBranch", sourceStore.OrganizationBranch); processInstance.AddProcessVariable("transferProductAdminGroup", g.GroupId); processInstance.AddProcessVariable("intakeBranch", intakeBranchId); processInstance.AddProcessVariable("warehouseGroup", gWarehouse.GroupId); processInstance.AddProcessVariable("transferId", dataModel.TransferProductId); processInstance.AddProcessVariable("transferToWarehouse", dataModel.DestinationStore == 999 ? true : false); //Set Action Varibles processInstance.AddActionVariable("user", OTApplication.Context.User.Id); //Start Process var processId = processInstance.Start(dataModel.TransferProductId.ToString()); // Update DB dataModel.ProcessInstance = processId; dataModel.TransferStatus = 2; dal.Update(dataModel); }
internal static byte[] ToBytes(this GroupElementP3 p3) { byte[] res = new byte[32]; GroupOperations.ge_p3_tobytes(res, 0, ref p3); return(res); }
private void startProductionOrderProcess(DataModels.Warehouse.ProductionOrder dataModel, IDAL dal) { int processDefinitionId = _parameterReader.ReadPublicParameter <int>("UretimFisiSureci", 2017); GroupOperations gop = new GroupOperations(dal); Group g = gop.FindGroup("Depo Sorumlusu"); Group g2 = gop.FindGroup("Uretim Grubu"); IProcessInstance processInstance = new ProcessInstance(processDefinitionId, OTApplication.Context.User.Id); //Set Process Variables processInstance.AddProcessVariable("user", OTApplication.Context.User.Id); processInstance.AddProcessVariable("screenReference", "Warehouse#ProductionOrderListComponent#" + dataModel.ProductionOrderId); processInstance.AddProcessVariable("requestId", dataModel.ProductionOrderId); processInstance.AddProcessVariable("acceptanceGroup", g.GroupId); processInstance.AddProcessVariable("productionGroup", g2.GroupId); //Set Action Varibles processInstance.AddActionVariable("user", OTApplication.Context.User.Id); //processInstance.AddActionVariable("description", dataModel.Description); //Start Process var processId = processInstance.Start(dataModel.ProductionOrderId.ToString()); dataModel.ProcessInstance = processId; dataModel.StatusCode = 1; dal.Update(dataModel); }
/* * r = 2 * p */ public static void ge_p3_dbl(out GroupElementP1P1 r, ref GroupElementP3 p) { GroupElementP2 q; GroupOperations.ge_p3_to_p2(out q, ref p); ge_p2_dbl(out r, ref q); }
public static void CryptoSign( byte[] sig, int sigoffset, byte[] m, int moffset, int mlen, byte[] sk, int skoffset) { var hasher = new Sha512(); { hasher.Update(sk, skoffset, 32); var az = hasher.Finalize(); ScalarOperations.Clamp(az, 0); hasher.Init(); hasher.Update(az, 32, 32); hasher.Update(m, moffset, mlen); var r = hasher.Finalize(); ScalarOperations.Reduce(r); GroupElementP3 R; GroupOperations.ScalarMultBase(out R, r, 0); GroupOperations.P3ToBytes(sig, sigoffset, ref R); hasher.Init(); hasher.Update(sig, sigoffset, 32); hasher.Update(sk, skoffset + 32, 32); hasher.Update(m, moffset, mlen); var hram = hasher.Finalize(); ScalarOperations.Reduce(hram); var s = new byte[32]; Array.Copy(sig, sigoffset + 32, s, 0, 32); ScalarOperations.MulAdd(s, hram, az, r); Array.Copy(s, 0, sig, sigoffset + 32, 32); CryptoBytes.Wipe(s); } }
private void startSuggestionProcess(DataModels.Announcement.Suggestion dataModel, IDAL dal) { int processDefinitionId = _parameterReader.ReadPublicParameter <int>("OneriSureci", 2011); var processInstanceRef = dataModel.SuggestionId.ToString(); GroupOperations gop = new GroupOperations(dal); Group suggestionAdminGroup = gop.FindGroup("Öneri Değerlendirme Kullanıcıları"); IProcessInstance processInstance = new ProcessInstance(processDefinitionId, OTApplication.Context.User.Id); //Set Process Variables processInstance.AddProcessVariable("user", OTApplication.Context.User.Id); processInstance.AddProcessVariable("screenReference", "Announcement#SuggestionListComponent#" + processInstanceRef); processInstance.AddProcessVariable("suggestionAdminGroup", suggestionAdminGroup.GroupId); processInstance.AddProcessVariable("suggestionId", dataModel.SuggestionId); //Set Action Varibles processInstance.AddActionVariable("user", OTApplication.Context.User.Id); //processInstance.AddActionVariable("description", dataModel.Description); //Start Process var processId = processInstance.Start(processInstanceRef); dataModel.ProcessInstance = processId; dal.Update(dataModel); }
private void startReturnOrderProcess(DataModels.Warehouse.ReturnOrder dataModel, IDAL dal) { int processDefinitionId = _parameterReader.ReadPublicParameter <int>("UrunIadeSureci", 2009); var store = dal.Read <Store>(dataModel.Store); var branch = dal.Read <Branch>(store.OrganizationBranch); GroupOperations gop = new GroupOperations(dal); Group g = gop.FindGroup("Ürün İade Kullanıcıları"); IProcessInstance processInstance = new ProcessInstance(processDefinitionId, OTApplication.Context.User.Id); //Set Process Variables processInstance.AddProcessVariable("user", OTApplication.Context.User.Id); processInstance.AddProcessVariable("screenReference", "Warehouse#ReturnOrderListComponent#" + dataModel.ReturnOrderId); processInstance.AddProcessVariable("branch", store.OrganizationBranch); processInstance.AddProcessVariable("region", branch.Parent); processInstance.AddProcessVariable("requestId", dataModel.ReturnOrderId); processInstance.AddProcessVariable("accountingGroup", g.GroupId); //Set Action Varibles processInstance.AddActionVariable("user", OTApplication.Context.User.Id); //processInstance.AddActionVariable("description", dataModel.Description); //Start Process var processId = processInstance.Start(dataModel.ReturnOrderId.ToString()); dataModel.ProcessInstance = processId; dal.Update(dataModel); }
public static void GetPublicKey(Span <byte> publicKey, ReadOnlySpan <byte> privateKey) { if (publicKey.Length != PublicKeySizeInBytes) { throw new ArgumentException("privateKey.Count must be 32"); } if (privateKey.Length != PrivateKeySizeInBytes) { throw new ArgumentException("privateKey.Count must be 32"); } // hack: abusing publicKey as temporary storage // todo: remove hack for (int i = 0; i < 32; i++) { publicKey[i] = privateKey[i]; } ScalarOperations.sc_clamp(publicKey); GroupElementP3 A; GroupOperations.ge_scalarmult_base(out A, publicKey); EdwardsToMontgomeryX(out var publicKeyFE, ref A.Y, ref A.Z); FieldOperations.fe_tobytes(publicKey, in publicKeyFE); }
public static void GetPublicKey(ArraySegment <byte> publicKey, ArraySegment <byte> privateKey) { if (publicKey.Array == null) { throw new ArgumentNullException("publicKey.Array"); } if (privateKey.Array == null) { throw new ArgumentNullException("privateKey.Array"); } if (publicKey.Count != PublicKeySizeInBytes) { throw new ArgumentException("privateKey.Count must be 32"); } if (privateKey.Count != PrivateKeySizeInBytes) { throw new ArgumentException("privateKey.Count must be 32"); } // hack: abusing publicKey as temporary storage // todo: remove hack for (int i = 0; i < 32; i++) { publicKey.Array[publicKey.Offset + i] = privateKey.Array[privateKey.Offset + i]; } ScalarOperations.sc_clamp(publicKey.Array, publicKey.Offset); GroupElementP3 A; GroupOperations.ge_scalarmult_base(out A, publicKey.Array, publicKey.Offset); FieldElement publicKeyFE; EdwardsToMontgomeryX(out publicKeyFE, ref A.Y, ref A.Z); FieldOperations.fe_tobytes(publicKey.Array, publicKey.Offset, ref publicKeyFE); }
public RingSignature[] Sign(byte[] msg, byte[] keyImage, IKey[] publicKeys, byte[] secretKey, int index) { RingSignature[] signatures = new RingSignature[publicKeys.Length]; byte[][] pubs = publicKeys.Select(pk => pk.Value.ToArray()).ToArray(); GroupOperations.ge_frombytes(out GroupElementP3 keyImageP3, keyImage, 0); GroupElementCached[] image_pre = new GroupElementCached[8]; GroupOperations.ge_dsm_precomp(image_pre, ref keyImageP3); byte[] sum = new byte[32], k = null, h = null; IHash hasher = HashFactory.Crypto.SHA3.CreateKeccak256(); hasher.TransformBytes(msg); for (int i = 0; i < publicKeys.Length; i++) { signatures[i] = new RingSignature(); if (i == index) { k = GetRandomSeed(true); GroupOperations.ge_scalarmult_base(out GroupElementP3 tmp3, k, 0); byte[] tmp3bytes = new byte[32]; GroupOperations.ge_p3_tobytes(tmp3bytes, 0, ref tmp3); hasher.TransformBytes(tmp3bytes); tmp3 = Hash2Point(pubs[i]); GroupOperations.ge_scalarmult(out GroupElementP2 tmp2, k, ref tmp3); byte[] tmp2bytes = new byte[32]; GroupOperations.ge_tobytes(tmp2bytes, 0, ref tmp2); hasher.TransformBytes(tmp2bytes); } else { signatures[i].C = GetRandomSeed(true); signatures[i].R = GetRandomSeed(true); GroupOperations.ge_frombytes(out GroupElementP3 tmp3, pubs[i], 0); GroupOperations.ge_double_scalarmult_vartime(out GroupElementP2 tmp2, signatures[i].C, ref tmp3, signatures[i].R); byte[] tmp2bytes = new byte[32]; GroupOperations.ge_tobytes(tmp2bytes, 0, ref tmp2); hasher.TransformBytes(tmp2bytes); tmp3 = Hash2Point(pubs[i]); GroupOperations.ge_double_scalarmult_precomp_vartime(out tmp2, signatures[i].R, tmp3, signatures[i].C, image_pre); tmp2bytes = new byte[32]; GroupOperations.ge_tobytes(tmp2bytes, 0, ref tmp2); hasher.TransformBytes(tmp2bytes); ScalarOperations.sc_add(sum, sum, signatures[i].C); } } h = hasher.TransformFinal().GetBytes(); ScalarOperations.sc_sub(signatures[index].C, h, sum); ScalarOperations.sc_reduce32(signatures[index].C); ScalarOperations.sc_mulsub(signatures[index].R, signatures[index].C, secretKey, k); ScalarOperations.sc_reduce32(signatures[index].R); return(signatures); }
/// <summary> /// Creates a new WIFIPLUG client without a API key or secret. /// </summary> /// <param name="apiUrl">The custom base path of the API.</param> public ApiClient(string apiUrl) : base(apiUrl) { _deviceOperations = new DeviceOperations(this); _sessionOperations = new SessionOperations(this); _userOperations = new UserOperations(this); _groupOperations = new GroupOperations(this); _eventOperations = new EventOperations(this); }
public void GetGroupsTest() { GroupOperations groupOperations = new GroupOperations(); groupOperations.GetGroups(); groupOperations.GetGroupById(0); groupOperations.AddGroup(new Models.MGroup()); }
/// <summary> /// Creates a new WIFIPLUG client without a API key or secret. /// </summary> public ApiClient() { _deviceOperations = new DeviceOperations(this); _sessionOperations = new SessionOperations(this); _userOperations = new UserOperations(this); _groupOperations = new GroupOperations(this); _eventOperations = new EventOperations(this); }
private static byte[] GetPublicKey(byte[] secretKey) { byte[] pk = new byte[32]; GroupOperations.ge_scalarmult_base(out GroupElementP3 p3, secretKey, 0); GroupOperations.ge_p3_tobytes(pk, 0, ref p3); return(pk); }
public MainWindow(int userId) { this._userId = userId; this._userOptions = new UserOptions(userId); this._invoiceOperations = new InvoiceOperations(userId); this._invoiceLoanCalculate = new InvoiceLoanCalculate(userId); this._adminOperations = new AdminOperations(userId); this._groupOperations = new GroupOperations(userId); InitializeComponent(); Loaded += MainWindow_Loaded; }
internal static void crypto_sign2( byte[] sig, byte[] m, byte[] sk, int keylen) { byte[] privHash = new byte[64]; byte[] seededHash = new byte[64]; byte[] result = new byte[64]; GroupElementP3 R = new GroupElementP3(); var hasher = new KeccakDigest(512); { var reversedPrivateKey = new byte[keylen]; Array.Copy(sk, 0, reversedPrivateKey, 0, keylen); Array.Reverse(reversedPrivateKey); hasher.BlockUpdate(reversedPrivateKey, 0, keylen); hasher.DoFinal(privHash, 0); ScalarOperations.sc_clamp(privHash, 0); hasher.Reset(); hasher.BlockUpdate(privHash, 32, 32); hasher.BlockUpdate(m, 0, m.Length); hasher.DoFinal(seededHash, 0); ScalarOperations.sc_reduce(seededHash); GroupOperations.ge_scalarmult_base(out R, seededHash, 0); GroupOperations.ge_p3_tobytes(sig, 0, ref R); hasher.Reset(); hasher.BlockUpdate(sig, 0, 32); hasher.BlockUpdate(sk, keylen, 32); hasher.BlockUpdate(m, 0, m.Length); hasher.DoFinal(result, 0); ScalarOperations.sc_reduce(result); var s = new byte[32]; //todo: remove allocation Array.Copy(sig, 32, s, 0, 32); ScalarOperations.sc_muladd(s, result, privHash, seededHash); Array.Copy(s, 0, sig, 32, 32); CryptoBytes.Wipe(s); } }
/// <summary> /// Calculates a new public key by processing an existing one with this license bock. /// The key is calculated as following: <code>new_pub_key = pub_key * hash + parent</code>. /// Where <code>pub_key</code> and <code>parent</code> are public keys, and <code>hash</code> a private key. /// </summary> /// <param name="parent">The preceeding key (from the previous block or root key).</param> /// <returns>The new public key after processing it with this block.</returns> public byte[] DeriveKey(ReadOnlySpan<byte> parent) { ScalarOperations.sc_clamp(Hash); GroupOperations.ge_frombytes_negate_vartime(out var pubkey, Key); GroupOperations.ge_frombytes_negate_vartime(out var parkey, parent); GroupOperations.ge_scalarmult_vartime(out GroupElementP1P1 res, Hash, pubkey); GroupOperations.ge_p3_to_cached(out var pargrp, parkey); GroupOperations.ge_p1p1_to_p3(out var r, res); GroupOperations.ge_add(out var a, r, pargrp); GroupOperations.ge_p1p1_to_p3(out var r2, a); var final = new byte[32]; GroupOperations.ge_p3_tobytes(final, r2); final[31] ^= 0x80; return final; }
public static void crypto_sign_keypair(byte[] pk, int pkoffset, byte[] sk, int skoffset, byte[] seed, int seedoffset) { GroupElementP3 A; int i; Array.Copy(seed, seedoffset, sk, skoffset, 32); byte[] h = SHA512.Hash(sk, skoffset, 32);//ToDo: Remove alloc ScalarOperations.sc_clamp(h, 0); GroupOperations.ge_scalarmult_base(out A, h, 0); GroupOperations.ge_p3_tobytes(pk, pkoffset, ref A); for (i = 0; i < 32; ++i) { sk[skoffset + 32 + i] = pk[pkoffset + i]; } CryptoExtensions.Wipe(h); }
public static void CryptoSignKeyPair(byte[] pk, int pkoffset, byte[] sk, int skoffset, byte[] seed, int seedoffset) { int i; Array.Copy(seed, seedoffset, sk, skoffset, 32); var h = Sha512.Hash(sk, skoffset, 32); ScalarOperations.Clamp(h, 0); GroupOperations.ScalarMultBase(out var A, h, 0); GroupOperations.P3ToBytes(pk, pkoffset, ref A); for (i = 0; i < 32; ++i) { sk[skoffset + 32 + i] = pk[pkoffset + i]; } CryptoBytes.Wipe(h); }
public bool Verify(byte[] msg, byte[] keyImage, IKey[] publicKeys, RingSignature[] signatures) { byte[][] pubs = publicKeys.Select(pk => pk.Value.ToArray()).ToArray(); GroupOperations.ge_frombytes(out GroupElementP3 image_unp, keyImage, 0); GroupElementCached[] image_pre = new GroupElementCached[8]; GroupOperations.ge_dsm_precomp(image_pre, ref image_unp); byte[] sum = new byte[32]; IHash hasher = HashFactory.Crypto.SHA3.CreateKeccak256(); hasher.TransformBytes(msg); for (int i = 0; i < pubs.Length; i++) { if (ScalarOperations.sc_check(signatures[i].C) != 0 || ScalarOperations.sc_check(signatures[i].R) != 0) { return(false); } GroupOperations.ge_frombytes(out GroupElementP3 tmp3, pubs[i], 0); GroupOperations.ge_double_scalarmult_vartime(out GroupElementP2 tmp2, signatures[i].C, ref tmp3, signatures[i].R); byte[] tmp2bytes = new byte[32]; GroupOperations.ge_tobytes(tmp2bytes, 0, ref tmp2); hasher.TransformBytes(tmp2bytes); tmp3 = Hash2Point(pubs[i]); GroupOperations.ge_double_scalarmult_precomp_vartime(out tmp2, signatures[i].R, tmp3, signatures[i].C, image_pre); tmp2bytes = new byte[32]; GroupOperations.ge_tobytes(tmp2bytes, 0, ref tmp2); hasher.TransformBytes(tmp2bytes); ScalarOperations.sc_add(sum, sum, signatures[i].C); } byte[] h = hasher.TransformFinal().GetBytes(); ScalarOperations.sc_reduce32(h); ScalarOperations.sc_sub(h, h, sum); int res = ScalarOperations.sc_isnonzero(h); return(res == 0); }
/// <summary> /// Выполнение операций по рабработе со студентами и группами. /// </summary> private void PerformOperations() { switch ((Actions)_chosedActions) { case Actions.Add: StudentOperations.AddStudent(_inputStudentData, GroupOperations.GetFoundedGroup()); isAbleToBack = true; break; case Actions.Print: StudentOperations.PrintStudents(GroupOperations.GetFoundedGroup()); isAbleToBack = true; break; case Actions.Remove: StudentOperations.RemoveStudent(_singleInput, GroupOperations.GetFoundedGroup()); isAbleToBack = true; break; case Actions.Sort: StudentOperations.SortStudents(GroupOperations.GetFoundedGroup()); isAbleToBack = true; break; case Actions.Find: Console.WriteLine("Не работает такое!"); isAbleToBack = true; break; case Actions.Quit: _menu.CallMenu(); break; default: Console.WriteLine("Опять ты брешишь..."); isAbleToBack = false; break; } }
/*Section="CustomCodeRegion"*/ #region Customized private void startEInvoiceProcess(DataModels.Accounting.SaleInvoice dataModel, IDAL dal) { int processDefinitionId = _parameterReader.ReadPublicParameter <int>("EInvoice", 2020); var store = dal.Read <Store>(dataModel.SaleStore); var branch = dal.Read <Branch>(store.OrganizationBranch); GroupOperations gop = new GroupOperations(dal); Group g = gop.FindGroup("Muhasebe E-Fatura"); long userId; if (OTApplication.Context != null && OTApplication.Context.User != null) { userId = OTApplication.Context.User.Id; } else { userId = 1; } IProcessInstance processInstance = new ProcessInstance(processDefinitionId, userId); //Set Process Variables processInstance.AddProcessVariable("user", OTApplication.Context.User.Id); processInstance.AddProcessVariable("screenReference", "Accounting#SaleInvoiceListComponent#" + dataModel.SaleInvoiceId); processInstance.AddProcessVariable("branch", store.OrganizationBranch); processInstance.AddProcessVariable("region", branch.Parent); processInstance.AddProcessVariable("requestId", dataModel.SaleInvoiceId); processInstance.AddProcessVariable("accountingGroup", g.GroupId); //Set Action Varibles processInstance.AddActionVariable("user", OTApplication.Context.User.Id); processInstance.AddActionVariable("description", $"{store.Name} - {dataModel.CustomerIdNumber} - {dataModel.Title} - {dataModel.SaleDate} - {dataModel.SaleAmount}"); //Start Process var processId = processInstance.Start(dataModel.SaleInvoiceId.ToString()); dataModel.ProcessInstance = processId; dataModel.StatusCode = 1; dal.Update(dataModel); }
public static bool crypto_sign_verify( byte[] sig, int sigoffset, byte[] m, int moffset, int mlen, byte[] pk, int pkoffset) { byte[] h; byte[] checkr = new byte[32]; GroupElementP3 A; GroupElementP2 R; if ((sig[sigoffset + 63] & 224) != 0) { return(false); } if (GroupOperations.ge_frombytes_negate_vartime(out A, pk, pkoffset) != 0) { return(false); } var hasher = new Sha512(); hasher.Update(sig, sigoffset, 32); hasher.Update(pk, pkoffset, 32); hasher.Update(m, moffset, mlen); h = hasher.Finalize(); ScalarOperations.sc_reduce(h); var sm32 = new byte[32]; Array.Copy(sig, sigoffset + 32, sm32, 0, 32); GroupOperations.ge_double_scalarmult_vartime(out R, h, ref A, sm32); GroupOperations.ge_tobytes(checkr, 0, ref R); var result = CryptoBytes.ConstantTimeEquals(checkr, 0, sig, sigoffset, 32); CryptoBytes.Wipe(h); CryptoBytes.Wipe(checkr); return(result); }
/// <summary> /// Выполнение операций по рабработе со студентами и группами /// </summary> private void PerformOperations() { switch ((Actions)_chosedActions) { case Actions.Add: GroupOperations.AddGroup(_input, _school); isAbleToBack = true; break; case Actions.Print: GroupOperations.PrintGroups(_school); isAbleToBack = true; break; case Actions.Remove: GroupOperations.RemoveGroup(_input, _school); isAbleToBack = true; break; case Actions.Sort: Console.WriteLine("Операция не поддерживается!"); isAbleToBack = true; break; case Actions.Find: GroupOperations.FindGroup(_input, _school); isAbleToBack = true; break; case Actions.Quit: _menu.CallMenu(); break; default: Console.WriteLine("Опять ты брешишь..."); isAbleToBack = false; break; } }
public static bool CryptoSignVerify( byte[] sig, int sigoffset, byte[] m, int moffset, int mlen, byte[] pk, int pkoffset) { var checker = new byte[32]; GroupElementP3 A; GroupElementP2 R; if ((sig[sigoffset + 63] & 224) != 0) { return(false); } if (GroupOperations.FromBytes(out A, pk, pkoffset) != 0) { return(false); } var hasher = new Sha512(); hasher.Update(sig, sigoffset, 32); hasher.Update(pk, pkoffset, 32); hasher.Update(m, moffset, mlen); var h = hasher.Finalize(); ScalarOperations.Reduce(h); var sm32 = new byte[32]; Array.Copy(sig, sigoffset + 32, sm32, 0, 32); GroupOperations.DoubleScalarMult(out R, h, ref A, sm32); GroupOperations.ToBytes(checker, 0, ref R); var result = CryptoBytes.ConstantTimeEquals(checker, 0, sig, sigoffset, 32); CryptoBytes.Wipe(h); CryptoBytes.Wipe(checker); return(result); }
public static void GenerateSignature( byte[] sig, int sigoffset, byte[] m, int moffset, int mlen, byte[] sk, int skoffset) { byte[] az; byte[] r; byte[] hram; GroupElementP3 R; var hasher = new SHA512(); { hasher.Update(sk, skoffset, 32); az = hasher.Finish(); ScalarOperations.sc_clamp(az, 0); hasher.Init(); hasher.Update(az, 32, 32); hasher.Update(m, moffset, mlen); r = hasher.Finish(); ScalarOperations.sc_reduce(r); GroupOperations.ge_scalarmult_base(out R, r, 0); GroupOperations.ge_p3_tobytes(sig, sigoffset, ref R); hasher.Init(); hasher.Update(sig, sigoffset, 32); hasher.Update(sk, skoffset + 32, 32); hasher.Update(m, moffset, mlen); hram = hasher.Finish(); ScalarOperations.sc_reduce(hram); var s = new byte[32];//todo: remove allocation Array.Copy(sig, sigoffset + 32, s, 0, 32); ScalarOperations.sc_muladd(s, hram, az, r); Array.Copy(s, 0, sig, sigoffset + 32, 32); CryptoExtensions.Wipe(s); } }
/// <summary> /// Creates a public key from a (pre-clamped) private key. /// </summary> /// <param name="privateKey">Existing private key. 32 bytes in length.</param> /// <returns>Public key as bytes.</returns> public static byte[] CreatePublicKey(byte[] privateKey) { if (privateKey == null) { throw new ArgumentNullException(); } if (privateKey.Length != PrivateKeySeedSizeInBytes) { throw new ArgumentException("Private key must be 32 bytes (256-bit).", "privateKey"); } var publicKey = new byte[SharedKeySizeInBytes]; GroupElementP3 A; GroupOperations.ge_scalarmult_base(out A, privateKey, 0); FieldElement publicKeyFE; EdwardsToMontgomeryX(out publicKeyFE, ref A.Y, ref A.Z); FieldOperations.fe_tobytes(publicKey, 0, ref publicKeyFE); return(publicKey); }
/// <summary> /// Initializes client properties. /// </summary> private void Initialize() { Policy = new PolicyOperations(this); PolicySnippets = new PolicySnippetsOperations(this); Regions = new RegionsOperations(this); Api = new ApiOperations(this); ApiRevisions = new ApiRevisionsOperations(this); ApiRelease = new ApiReleaseOperations(this); ApiOperation = new ApiOperationOperations(this); ApiOperationPolicy = new ApiOperationPolicyOperations(this); ApiProduct = new ApiProductOperations(this); ApiPolicy = new ApiPolicyOperations(this); ApiSchema = new ApiSchemaOperations(this); ApiDiagnostic = new ApiDiagnosticOperations(this); ApiDiagnosticLogger = new ApiDiagnosticLoggerOperations(this); ApiIssue = new ApiIssueOperations(this); ApiIssueComment = new ApiIssueCommentOperations(this); ApiIssueAttachment = new ApiIssueAttachmentOperations(this); AuthorizationServer = new AuthorizationServerOperations(this); Backend = new BackendOperations(this); Certificate = new CertificateOperations(this); ApiManagementOperations = new ApiManagementOperations(this); ApiManagementServiceSkus = new ApiManagementServiceSkusOperations(this); ApiManagementService = new ApiManagementServiceOperations(this); Diagnostic = new DiagnosticOperations(this); DiagnosticLogger = new DiagnosticLoggerOperations(this); EmailTemplate = new EmailTemplateOperations(this); Group = new GroupOperations(this); GroupUser = new GroupUserOperations(this); IdentityProvider = new IdentityProviderOperations(this); Logger = new LoggerOperations(this); Notification = new NotificationOperations(this); NotificationRecipientUser = new NotificationRecipientUserOperations(this); NotificationRecipientEmail = new NotificationRecipientEmailOperations(this); NetworkStatus = new NetworkStatusOperations(this); OpenIdConnectProvider = new OpenIdConnectProviderOperations(this); SignInSettings = new SignInSettingsOperations(this); SignUpSettings = new SignUpSettingsOperations(this); DelegationSettings = new DelegationSettingsOperations(this); Product = new ProductOperations(this); ProductApi = new ProductApiOperations(this); ProductGroup = new ProductGroupOperations(this); ProductSubscriptions = new ProductSubscriptionsOperations(this); ProductPolicy = new ProductPolicyOperations(this); Property = new PropertyOperations(this); QuotaByCounterKeys = new QuotaByCounterKeysOperations(this); QuotaByPeriodKeys = new QuotaByPeriodKeysOperations(this); Reports = new ReportsOperations(this); Subscription = new SubscriptionOperations(this); TagResource = new TagResourceOperations(this); Tag = new TagOperations(this); TagDescription = new TagDescriptionOperations(this); Operation = new OperationOperations(this); TenantAccess = new TenantAccessOperations(this); TenantAccessGit = new TenantAccessGitOperations(this); TenantConfiguration = new TenantConfigurationOperations(this); User = new UserOperations(this); UserGroup = new UserGroupOperations(this); UserSubscription = new UserSubscriptionOperations(this); UserIdentities = new UserIdentitiesOperations(this); ApiVersionSet = new ApiVersionSetOperations(this); ApiExport = new ApiExportOperations(this); BaseUri = new System.Uri("https://management.azure.com"); ApiVersion = "2018-01-01"; AcceptLanguage = "en-US"; LongRunningOperationRetryTimeout = 30; GenerateClientRequestId = true; SerializationSettings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; SerializationSettings.Converters.Add(new TransformationJsonConverter()); DeserializationSettings = new JsonSerializerSettings { DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, ContractResolver = new ReadOnlyJsonContractResolver(), Converters = new List <JsonConverter> { new Iso8601TimeSpanConverter() } }; CustomInitialize(); DeserializationSettings.Converters.Add(new TransformationJsonConverter()); DeserializationSettings.Converters.Add(new CloudErrorJsonConverter()); }
/* * r = a * A + b * B * where a = a[0]+256*a[1]+...+256^31 a[31]. * and b = b[0]+256*b[1]+...+256^31 b[31]. * B is the Ed25519 base point (x,4/5) with x positive. */ public static void ge_double_scalarmult_vartime(out GroupElementP2 r, byte[] a, ref GroupElementP3 A, byte[] b) { var Bi = stellar_dotnet_sdk.chaos.nacl.Internal.Ed25519Ref10.LookupTables.Base2; var aslide = new sbyte[256]; var bslide = new sbyte[256]; var ai = new GroupElementCached[8]; /* A,3A,5A,7A,9A,11A,13A,15A */ int i; Slide(aslide, a); Slide(bslide, b); GroupOperations.ge_p3_to_cached(out ai[0], ref A); GroupOperations.ge_p3_dbl(out var t, ref A); GroupOperations.ge_p1p1_to_p3(out var A2, ref t); ge_add(out t, ref A2, ref ai[0]); GroupOperations.ge_p1p1_to_p3(out var u, ref t); GroupOperations.ge_p3_to_cached(out ai[1], ref u); ge_add(out t, ref A2, ref ai[1]); GroupOperations.ge_p1p1_to_p3(out u, ref t); GroupOperations.ge_p3_to_cached(out ai[2], ref u); ge_add(out t, ref A2, ref ai[2]); GroupOperations.ge_p1p1_to_p3(out u, ref t); GroupOperations.ge_p3_to_cached(out ai[3], ref u); ge_add(out t, ref A2, ref ai[3]); GroupOperations.ge_p1p1_to_p3(out u, ref t); GroupOperations.ge_p3_to_cached(out ai[4], ref u); ge_add(out t, ref A2, ref ai[4]); GroupOperations.ge_p1p1_to_p3(out u, ref t); GroupOperations.ge_p3_to_cached(out ai[5], ref u); ge_add(out t, ref A2, ref ai[5]); GroupOperations.ge_p1p1_to_p3(out u, ref t); GroupOperations.ge_p3_to_cached(out ai[6], ref u); ge_add(out t, ref A2, ref ai[6]); GroupOperations.ge_p1p1_to_p3(out u, ref t); GroupOperations.ge_p3_to_cached(out ai[7], ref u); GroupOperations.ge_p2_0(out r); for (i = 255; i >= 0; --i) { if (aslide[i] != 0 || bslide[i] != 0) { break; } } for (; i >= 0; --i) { GroupOperations.ge_p2_dbl(out t, ref r); if (aslide[i] > 0) { GroupOperations.ge_p1p1_to_p3(out u, ref t); ge_add(out t, ref u, ref ai[aslide[i] / 2]); } else if (aslide[i] < 0) { GroupOperations.ge_p1p1_to_p3(out u, ref t); GroupOperations.GeSub(out t, ref u, ref ai[-aslide[i] / 2]); } if (bslide[i] > 0) { GroupOperations.ge_p1p1_to_p3(out u, ref t); GroupOperations.ge_madd(out t, ref u, ref Bi[bslide[i] / 2]); } else if (bslide[i] < 0) { GroupOperations.ge_p1p1_to_p3(out u, ref t); GroupOperations.ge_msub(out t, ref u, ref Bi[-bslide[i] / 2]); } GroupOperations.ge_p1p1_to_p2(out r, ref t); } }
/// <summary> /// Is called on the UI thread before execution of the IGisTool.Run method. /// </summary> /// <returns></returns> protected override bool BeforeRun() { return(GroupOperations.ValidateWithMessage(Input.Datasource)); }
private StringBuilder ParseFilter(ICollection<JqGridFilter> groups, GroupOperations groupOp, Type targetSearchType) { if (groups == null || groups.Count == 0) return null; var sb = new StringBuilder(); bool firstGroup = true; foreach (var group in groups) { var sbGroup = ParseFilter(group, targetSearchType); if (sbGroup == null || sbGroup.Length == 0) continue; if (!firstGroup) // skip groupOp before the first group sb.Append(groupOp); else firstGroup = false; sb.EnsureCapacity(sb.Length + sbGroup.Length + 2); AppendWithBrackets(sb, sbGroup); } return sb; }
private StringBuilder ParseRule(ICollection<JqGridRule> rules, GroupOperations groupOp, Type targetSearchType) { if (rules == null || rules.Count == 0) return null; var sb = new StringBuilder(); bool firstRule = true; var props = targetSearchType.GetProperties().ToDictionary(p => p.Name, p => p.PropertyType); foreach (var rule in rules) { if (!firstRule) // skip groupOp before the first rule sb.Append(groupOp); else firstRule = false; // get the object type of the rule Type ruleParseType; bool emptyNullable = false; try { string[] childClass = rule.field.Split('.'); Type ruleType = ruleParseType = props[childClass[0]]; for (int i = 1; i < childClass.Length; i++) { var childProps = ruleParseType.GetProperties().ToDictionary(p => p.Name, p => p.PropertyType); ruleType = ruleParseType = childProps[childClass[i]]; } if (ruleType.IsGenericType && ruleType.GetGenericTypeDefinition() == typeof(Nullable<>)) { if (rule.data == "") emptyNullable = true; ruleParseType = Nullable.GetUnderlyingType(ruleType); } } catch (KeyNotFoundException) { throw new ArgumentOutOfRangeException(rule.field + " is not a property of type " + targetSearchType); } // parse it in as the correct object type var fmAdd = ""; if (ruleParseType == typeof(string)) { _formatObjects.Add(rule.data); if (rule.data == "") fmAdd = " OR {0} = NULL"; } else { if (emptyNullable) _formatObjects.Add(null); else { var parseMethod = ruleParseType.GetMethod("Parse", new[] { typeof(string) }); if (parseMethod != null) _formatObjects.Add(parseMethod.Invoke(ruleParseType, new object[] { rule.data }));//props[rule.field], new object[] { rule.data })); //Changed by Zhicheng Su else if (ruleParseType.IsEnum) _formatObjects.Add(Enum.Parse(ruleParseType, rule.data)); else throw new ArgumentOutOfRangeException(rule.field + " is not a string and cannot be parsed either!!"); } } string fm = emptyNullable ? NullValueFormatMapping[(int)rule.op] : FormatMapping[(int)rule.op].Replace("{F}", fmAdd); sb.AppendFormat(fm, rule.field, _formatObjects.Count - 1); } return sb.Length > 0 ? sb : null; }