我的程序中有两个 uint8_t 指针,我想比较它们的值。我没有处理无符号整数的好主意。这是我的代码
static void bacast_signed_message()
{
uint8_t *M = malloc(MAX_M_LEN*sizeof(uint8_t));//uint8_t M[MAX_M_LEN];//uint8_t *M;
int M_len = MAX_M_LEN;;
uint8_t *C = malloc((2*KEYDIGITS*NN_DIGIT_LEN + 1 + MAX_M_LEN + HMAC_LEN)*sizeof(uint8_t));
int C_len;
//uint8_t C[2*KEYDIGITS*NN_DIGIT_LEN + 1 + MAX_M_LEN + HMAC_LEN];
uint8_t *dM = malloc(MAX_M_LEN*sizeof(uint8_t)); //uint8_t dM[MAX_M_LEN];
int dM_len = MAX_M_LEN;
random_data(M, MAX_M_LEN);
printf("C before encrypt %p\n",*C);
printf("M before encrypt %p\n",*M);
printf("dM before encrypt %p\n",*dM);
C_len = encrypt(C, (2*KEYDIGITS*NN_DIGIT_LEN + 1 + M_len + HMAC_LEN), M, M_len, &pbkey_alice);
//encrypt(uint8_t *C, int C_len, uint8_t *M, int M_len, Point *PublicKey);
printf("C after encrypt %p\n",*C);
printf("M after encrypt %p\n",*M);
printf("dM after encrypt %p\n",*dM);
dM_len = decrypt(dM, dM_len, C, C_len, prKey_alice);
//decrypt(uint8_t *M, int M_len, uint8_t *C, int C_len, NN_DIGIT *d);
printf("C after decrypt %p\n",*C);
printf("M after decrypt %p\n",*M);
printf("dM after decrypt %p\n",*dM);
printf("C_len = %i , M_len = %i\n",C_len,M_len);
if (dM == M){printf("Works\n");}
else{printf("Not Works\n");}
}
这是我得到的输出
C before encrypt 0x40
M before encrypt 0x28
dM before encrypt 0x70
C after encrypt 0x4
M after encrypt 0x28
dM after encrypt 0x70
C after decrypt 0x4
M after decrypt 0x28
dM after decrypt 0x28
C_len = 102 , M_len = 41
Not Works
如果我更改了 private_key(没有更改公钥),那么它看起来像这样
C before encrypt 0x40
M before encrypt 0x28
dM before encrypt 0x70
C after encrypt 0x4
M after encrypt 0x28
dM after encrypt 0x70
C after decrypt 0x4
M after decrypt 0x28
dM after decrypt 0x70
C_len = 102 , M_len = 41
Not Works
这意味着 dM 没有改变。但我不确定这一点。如果我使用 %u 而不是 %p 它会给我完全不同的答案(它说如果我们使用 %u 它会转换为十进制)。请给我一些建议,并告诉我这有什么问题。
提前致谢