From add0b41aa0ca43d0b3738990614452e483aafdb1 Mon Sep 17 00:00:00 2001 From: Tuomo Kriikkula Date: Mon, 12 Aug 2024 14:19:32 +0300 Subject: [PATCH] Perform memcpy in RunCode 'manually' --- Classes/FCryptoEC_Prime.uc | 82 ++++++++++++++++++++++++++++++++++++-- Classes/FCryptoMemory.uc | 27 +++++++++++++ 2 files changed, 106 insertions(+), 3 deletions(-) diff --git a/Classes/FCryptoEC_Prime.uc b/Classes/FCryptoEC_Prime.uc index 7cf0949..2c4c5d6 100644 --- a/Classes/FCryptoEC_Prime.uc +++ b/Classes/FCryptoEC_Prime.uc @@ -253,11 +253,87 @@ static final function int RunCode( */ // memcpy(t[P1x], P1->c, 3 * I15_LEN * sizeof(uint16_t)); // memcpy(t[P2x], P2->c, 3 * I15_LEN * sizeof(uint16_t)); - // TODO: need static memcpy for these array sizes. + // class'FCryptoMemory'.static.MemCpy_Jacobian_Monty(T[`P1x], P1.C, 222); + // class'FCryptoMemory'.static.MemCpy_Jacobian_Monty(T[`P2x], P2.C, 222); + T[`P1x].X[ 0] = P1.C[0].X[ 0]; T[`P1y].X[ 0] = P1.C[1].X[ 0]; T[`P1z].X[ 0] = P1.C[2].X[ 0]; + T[`P1x].X[ 1] = P1.C[0].X[ 1]; T[`P1y].X[ 1] = P1.C[1].X[ 1]; T[`P1z].X[ 1] = P1.C[2].X[ 1]; + T[`P1x].X[ 2] = P1.C[0].X[ 2]; T[`P1y].X[ 2] = P1.C[1].X[ 2]; T[`P1z].X[ 2] = P1.C[2].X[ 2]; + T[`P1x].X[ 3] = P1.C[0].X[ 3]; T[`P1y].X[ 3] = P1.C[1].X[ 3]; T[`P1z].X[ 3] = P1.C[2].X[ 3]; + T[`P1x].X[ 4] = P1.C[0].X[ 4]; T[`P1y].X[ 4] = P1.C[1].X[ 4]; T[`P1z].X[ 4] = P1.C[2].X[ 4]; + T[`P1x].X[ 5] = P1.C[0].X[ 5]; T[`P1y].X[ 5] = P1.C[1].X[ 5]; T[`P1z].X[ 5] = P1.C[2].X[ 5]; + T[`P1x].X[ 6] = P1.C[0].X[ 6]; T[`P1y].X[ 6] = P1.C[1].X[ 6]; T[`P1z].X[ 6] = P1.C[2].X[ 6]; + T[`P1x].X[ 7] = P1.C[0].X[ 7]; T[`P1y].X[ 7] = P1.C[1].X[ 7]; T[`P1z].X[ 7] = P1.C[2].X[ 7]; + T[`P1x].X[ 8] = P1.C[0].X[ 8]; T[`P1y].X[ 8] = P1.C[1].X[ 8]; T[`P1z].X[ 8] = P1.C[2].X[ 8]; + T[`P1x].X[ 9] = P1.C[0].X[ 9]; T[`P1y].X[ 9] = P1.C[1].X[ 9]; T[`P1z].X[ 9] = P1.C[2].X[ 9]; + T[`P1x].X[10] = P1.C[0].X[10]; T[`P1y].X[10] = P1.C[1].X[10]; T[`P1z].X[10] = P1.C[2].X[10]; + T[`P1x].X[11] = P1.C[0].X[11]; T[`P1y].X[11] = P1.C[1].X[11]; T[`P1z].X[11] = P1.C[2].X[11]; + T[`P1x].X[12] = P1.C[0].X[12]; T[`P1y].X[12] = P1.C[1].X[12]; T[`P1z].X[12] = P1.C[2].X[12]; + T[`P1x].X[13] = P1.C[0].X[13]; T[`P1y].X[13] = P1.C[1].X[13]; T[`P1z].X[13] = P1.C[2].X[13]; + T[`P1x].X[14] = P1.C[0].X[14]; T[`P1y].X[14] = P1.C[1].X[14]; T[`P1z].X[14] = P1.C[2].X[14]; + T[`P1x].X[15] = P1.C[0].X[15]; T[`P1y].X[15] = P1.C[1].X[15]; T[`P1z].X[15] = P1.C[2].X[15]; + T[`P1x].X[16] = P1.C[0].X[16]; T[`P1y].X[16] = P1.C[1].X[16]; T[`P1z].X[16] = P1.C[2].X[16]; + T[`P1x].X[17] = P1.C[0].X[17]; T[`P1y].X[17] = P1.C[1].X[17]; T[`P1z].X[17] = P1.C[2].X[17]; + T[`P1x].X[18] = P1.C[0].X[18]; T[`P1y].X[18] = P1.C[1].X[18]; T[`P1z].X[18] = P1.C[2].X[18]; + T[`P1x].X[19] = P1.C[0].X[19]; T[`P1y].X[19] = P1.C[1].X[19]; T[`P1z].X[19] = P1.C[2].X[19]; + T[`P1x].X[20] = P1.C[0].X[20]; T[`P1y].X[20] = P1.C[1].X[20]; T[`P1z].X[20] = P1.C[2].X[20]; + T[`P1x].X[21] = P1.C[0].X[21]; T[`P1y].X[21] = P1.C[1].X[21]; T[`P1z].X[21] = P1.C[2].X[21]; + T[`P1x].X[22] = P1.C[0].X[22]; T[`P1y].X[22] = P1.C[1].X[22]; T[`P1z].X[22] = P1.C[2].X[22]; + T[`P1x].X[23] = P1.C[0].X[23]; T[`P1y].X[23] = P1.C[1].X[23]; T[`P1z].X[23] = P1.C[2].X[23]; + T[`P1x].X[24] = P1.C[0].X[24]; T[`P1y].X[24] = P1.C[1].X[24]; T[`P1z].X[24] = P1.C[2].X[24]; + T[`P1x].X[25] = P1.C[0].X[25]; T[`P1y].X[25] = P1.C[1].X[25]; T[`P1z].X[25] = P1.C[2].X[25]; + T[`P1x].X[26] = P1.C[0].X[26]; T[`P1y].X[26] = P1.C[1].X[26]; T[`P1z].X[26] = P1.C[2].X[26]; + T[`P1x].X[27] = P1.C[0].X[27]; T[`P1y].X[27] = P1.C[1].X[27]; T[`P1z].X[27] = P1.C[2].X[27]; + T[`P1x].X[28] = P1.C[0].X[28]; T[`P1y].X[28] = P1.C[1].X[28]; T[`P1z].X[28] = P1.C[2].X[28]; + T[`P1x].X[29] = P1.C[0].X[29]; T[`P1y].X[29] = P1.C[1].X[29]; T[`P1z].X[29] = P1.C[2].X[29]; + T[`P1x].X[30] = P1.C[0].X[30]; T[`P1y].X[30] = P1.C[1].X[30]; T[`P1z].X[30] = P1.C[2].X[30]; + T[`P1x].X[31] = P1.C[0].X[31]; T[`P1y].X[31] = P1.C[1].X[31]; T[`P1z].X[31] = P1.C[2].X[31]; + T[`P1x].X[32] = P1.C[0].X[32]; T[`P1y].X[32] = P1.C[1].X[32]; T[`P1z].X[32] = P1.C[2].X[32]; + T[`P1x].X[33] = P1.C[0].X[33]; T[`P1y].X[33] = P1.C[1].X[33]; T[`P1z].X[33] = P1.C[2].X[33]; + T[`P1x].X[34] = P1.C[0].X[34]; T[`P1y].X[34] = P1.C[1].X[34]; T[`P1z].X[34] = P1.C[2].X[34]; + T[`P1x].X[35] = P1.C[0].X[35]; T[`P1y].X[35] = P1.C[1].X[35]; T[`P1z].X[35] = P1.C[2].X[35]; + T[`P1x].X[36] = P1.C[0].X[36]; T[`P1y].X[36] = P1.C[1].X[36]; T[`P1z].X[36] = P1.C[2].X[36]; + + T[`P2x].X[ 0] = P2.C[0].X[ 0]; T[`P2y].X[ 0] = P2.C[1].X[ 0]; T[`P2z].X[ 0] = P2.C[2].X[ 0]; + T[`P2x].X[ 1] = P2.C[0].X[ 1]; T[`P2y].X[ 1] = P2.C[1].X[ 1]; T[`P2z].X[ 1] = P2.C[2].X[ 1]; + T[`P2x].X[ 2] = P2.C[0].X[ 2]; T[`P2y].X[ 2] = P2.C[1].X[ 2]; T[`P2z].X[ 2] = P2.C[2].X[ 2]; + T[`P2x].X[ 3] = P2.C[0].X[ 3]; T[`P2y].X[ 3] = P2.C[1].X[ 3]; T[`P2z].X[ 3] = P2.C[2].X[ 3]; + T[`P2x].X[ 4] = P2.C[0].X[ 4]; T[`P2y].X[ 4] = P2.C[1].X[ 4]; T[`P2z].X[ 4] = P2.C[2].X[ 4]; + T[`P2x].X[ 5] = P2.C[0].X[ 5]; T[`P2y].X[ 5] = P2.C[1].X[ 5]; T[`P2z].X[ 5] = P2.C[2].X[ 5]; + T[`P2x].X[ 6] = P2.C[0].X[ 6]; T[`P2y].X[ 6] = P2.C[1].X[ 6]; T[`P2z].X[ 6] = P2.C[2].X[ 6]; + T[`P2x].X[ 7] = P2.C[0].X[ 7]; T[`P2y].X[ 7] = P2.C[1].X[ 7]; T[`P2z].X[ 7] = P2.C[2].X[ 7]; + T[`P2x].X[ 8] = P2.C[0].X[ 8]; T[`P2y].X[ 8] = P2.C[1].X[ 8]; T[`P2z].X[ 8] = P2.C[2].X[ 8]; + T[`P2x].X[ 9] = P2.C[0].X[ 9]; T[`P2y].X[ 9] = P2.C[1].X[ 9]; T[`P2z].X[ 9] = P2.C[2].X[ 9]; + T[`P2x].X[10] = P2.C[0].X[10]; T[`P2y].X[10] = P2.C[1].X[10]; T[`P2z].X[10] = P2.C[2].X[10]; + T[`P2x].X[11] = P2.C[0].X[11]; T[`P2y].X[11] = P2.C[1].X[11]; T[`P2z].X[11] = P2.C[2].X[11]; + T[`P2x].X[12] = P2.C[0].X[12]; T[`P2y].X[12] = P2.C[1].X[12]; T[`P2z].X[12] = P2.C[2].X[12]; + T[`P2x].X[13] = P2.C[0].X[13]; T[`P2y].X[13] = P2.C[1].X[13]; T[`P2z].X[13] = P2.C[2].X[13]; + T[`P2x].X[14] = P2.C[0].X[14]; T[`P2y].X[14] = P2.C[1].X[14]; T[`P2z].X[14] = P2.C[2].X[14]; + T[`P2x].X[15] = P2.C[0].X[15]; T[`P2y].X[15] = P2.C[1].X[15]; T[`P2z].X[15] = P2.C[2].X[15]; + T[`P2x].X[16] = P2.C[0].X[16]; T[`P2y].X[16] = P2.C[1].X[16]; T[`P2z].X[16] = P2.C[2].X[16]; + T[`P2x].X[17] = P2.C[0].X[17]; T[`P2y].X[17] = P2.C[1].X[17]; T[`P2z].X[17] = P2.C[2].X[17]; + T[`P2x].X[18] = P2.C[0].X[18]; T[`P2y].X[18] = P2.C[1].X[18]; T[`P2z].X[18] = P2.C[2].X[18]; + T[`P2x].X[19] = P2.C[0].X[19]; T[`P2y].X[19] = P2.C[1].X[19]; T[`P2z].X[19] = P2.C[2].X[19]; + T[`P2x].X[20] = P2.C[0].X[20]; T[`P2y].X[20] = P2.C[1].X[20]; T[`P2z].X[20] = P2.C[2].X[20]; + T[`P2x].X[21] = P2.C[0].X[21]; T[`P2y].X[21] = P2.C[1].X[21]; T[`P2z].X[21] = P2.C[2].X[21]; + T[`P2x].X[22] = P2.C[0].X[22]; T[`P2y].X[22] = P2.C[1].X[22]; T[`P2z].X[22] = P2.C[2].X[22]; + T[`P2x].X[23] = P2.C[0].X[23]; T[`P2y].X[23] = P2.C[1].X[23]; T[`P2z].X[23] = P2.C[2].X[23]; + T[`P2x].X[24] = P2.C[0].X[24]; T[`P2y].X[24] = P2.C[1].X[24]; T[`P2z].X[24] = P2.C[2].X[24]; + T[`P2x].X[25] = P2.C[0].X[25]; T[`P2y].X[25] = P2.C[1].X[25]; T[`P2z].X[25] = P2.C[2].X[25]; + T[`P2x].X[26] = P2.C[0].X[26]; T[`P2y].X[26] = P2.C[1].X[26]; T[`P2z].X[26] = P2.C[2].X[26]; + T[`P2x].X[27] = P2.C[0].X[27]; T[`P2y].X[27] = P2.C[1].X[27]; T[`P2z].X[27] = P2.C[2].X[27]; + T[`P2x].X[28] = P2.C[0].X[28]; T[`P2y].X[28] = P2.C[1].X[28]; T[`P2z].X[28] = P2.C[2].X[28]; + T[`P2x].X[29] = P2.C[0].X[29]; T[`P2y].X[29] = P2.C[1].X[29]; T[`P2z].X[29] = P2.C[2].X[29]; + T[`P2x].X[30] = P2.C[0].X[30]; T[`P2y].X[30] = P2.C[1].X[30]; T[`P2z].X[30] = P2.C[2].X[30]; + T[`P2x].X[31] = P2.C[0].X[31]; T[`P2y].X[31] = P2.C[1].X[31]; T[`P2z].X[31] = P2.C[2].X[31]; + T[`P2x].X[32] = P2.C[0].X[32]; T[`P2y].X[32] = P2.C[1].X[32]; T[`P2z].X[32] = P2.C[2].X[32]; + T[`P2x].X[33] = P2.C[0].X[33]; T[`P2y].X[33] = P2.C[1].X[33]; T[`P2z].X[33] = P2.C[2].X[33]; + T[`P2x].X[34] = P2.C[0].X[34]; T[`P2y].X[34] = P2.C[1].X[34]; T[`P2z].X[34] = P2.C[2].X[34]; + T[`P2x].X[35] = P2.C[0].X[35]; T[`P2y].X[35] = P2.C[1].X[35]; T[`P2z].X[35] = P2.C[2].X[35]; + T[`P2x].X[36] = P2.C[0].X[36]; T[`P2y].X[36] = P2.C[1].X[36]; T[`P2z].X[36] = P2.C[2].X[36]; /* - * Run formulas. - */ + * Run formulas. + */ for (U = 0; True; ++U) { Op = Code[U]; diff --git a/Classes/FCryptoMemory.uc b/Classes/FCryptoMemory.uc index a702ad7..47c8fb3 100644 --- a/Classes/FCryptoMemory.uc +++ b/Classes/FCryptoMemory.uc @@ -175,3 +175,30 @@ static final function MemSet_SBytes64( S[ByteIndex] = C; } } + +// TODO: is this even needed? +// // Specialized for FCryptoEC_Prime.Jacobian 2D arrays. +// static final function MemCpy_Jacobian_Monty( +// out FCryptoEC_Prime._Monty Dst, +// const out FCryptoEC_Prime._Monty Src[3], +// int NumBytes +// ) +// { +// local int DstIdx; +// local int SrcIdx_0; +// local int SrcIdx_1; + +// // Start with first sub-array, copy items until NumBytes +// // satisfied, moving to next sub-array as needed. + +// // TODO: probably also need a temporary byte array for this. + +// DstIdx = 0; +// SrcIdx_0 = 0; +// SrcIdx_1 = 0; +// while (NumBytes > 0) +// { +// Dst.X[DstIdx++] = Src[SrcIdx_0].X[SrcIdx_1]; +// --NumBytes; +// } +// }