staticvoid TEACore(unsignedint in[2], unsignedint out[2], unsignedint key[4], long rounds)
{
unsigned int y = in[0], z = in[1];
unsigned int limit = 0, sum = 0;
if(rounds > 0)// encrypt
{
limit = DELTA * rounds;
while(sum != limit)
{
y += ((z<<4)^(z>>5)) + (z^sum) + key[sum&3];
sum += DELTA;
z += ((y<<4)^(y>>5)) + (y^sum) + key[(sum>>11)&3];
}
}
else// decrypt
{
sum = DELTA * (-rounds);
while(sum)
{
z -= ((y<<4)^(y>>5)) + (y^sum) + key[(sum>>11)&3];
sum -= DELTA;
y -= ((z<<4)^(z>>5)) + (z^sum) + key[sum&3];
}
}
//arm 内存4字节对齐
//out[0] = y; out[1] = z;
memcpy((void*)&out[0], (void*)&y, sizeof(unsigned int));
memcpy((void*)&out[1], (void*)&z, sizeof(unsigned int));
}
在进行强制数据类型转换的时候,ios平台竟然要求内存字节对齐。而debug环境又不要求。如果两次强制类型转换用oc的代码隔开,release执行又是正确的,所以再次怀疑是xocde在编译的时候,编译器优化导致的。
ios下一个4字节对齐引起崩溃的问题,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/sealme/p/3774729.html