c - 如何将 UInt64 数组转换为 UInt16 数组以执行多精度乘法?

标签 c arrays galois-field montgomery-multiplication

我需要在我的应用程序中执行快速伽罗华域运算。我有一个用汇编语言编写的乘法函数,它针对我的平台(一个 MSP430 微 Controller )进行了优化。该函数计算两个任意大小的大数的乘积,但每个数必须表示为一个 16 位整数数组。但是,在我的项目中,Galois 域元素表示为 16 个 64 位整数的数组。如何将我的 16 个 64 位整数数组转换为我优化的、基于汇编的乘法函数所需的表示(即 64 个 16 位整数数组)?当然,简单地将数组转换为 (UInt16 *) 是行不通的。

MSP430 是小端架构。提前感谢您的任何建议。

最佳答案

我不确定这是否是您想要的,而且这个解决方案在某种意义上是不完整的,因为它只是作为一个示例。此外,它是高度平台依赖的。它适用于我的机器(little_endian)。我在 windows 下使用 Code:Blocks。

   typedef struct {
             uint16_t lo_word0;
             uint16_t hi_word0;
             uint16_t lo_word1;
             uint16_t hi_word1;
              }struct_t;



    int main()
    {
       uint64_t buff_64[4]={0xaaaabbbbccccdddd,0xbbbbccccddddeeee,0x1111222233334444,0x8888aaaabbbbcccc};
       uint16_t buff_16[16];
      /*Please note that you may use simply:
        memcpy(buff_16,buff_64,32); 
        however that would result in reverse order
        with respect to the code below */

       struct_t *ptr = (struct_t *)buff_64;

       for(int j=0; j<16; ptr++)
       {
         buff_16[(j++)%16]=ptr->hi_word1;
         buff_16[(j++)%16]=ptr->lo_word1;
         buff_16[(j++)%16]=ptr->hi_word0;
         buff_16[(j++)%16]=ptr->lo_word0;

       } 
        // The check
        for(int j=0;j<16;j++)
        printf("%x\n",buff_16[j]);  

        return 0;
      }      

关于c - 如何将 UInt64 数组转换为 UInt16 数组以执行多精度乘法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42011382/

相关文章:

c - for 循环内带有 if else 条件的 for 循环

c++ - 如何创建指向结构的指针数组? C++

python - 在 numpy 中重新定义 *= 运算符

c - 将元素存储和访问到嵌套结构的数组

python - 有限域 : Compute the inverse of a matrix

matlab - Gauss-Jordan 消除法对 GF(2) 的消除

c - 为什么“while(!feof(file))”总是错误的?

c - 使用动态数组时增加内存

c - 查找文件中的一行并提取信息

java - Java 或 C 数组中的乘法逆表 GF(2^4)