TLS 1.3 PSK 会话恢复: NewSessionTicket 签发/解析、ticket+binder 校验、selected_identity 回选、恢复握手免证书(pazessl -sess_in/-sess_out 端到端验证); 构建脚本输出 bin/ 并支持独立命令与 psftp; 修复 SFTP 二进制传输与 copy_id -P; 补充 tests/ 调试与 verify_tls
79 行
2.6 KiB
C
79 行
2.6 KiB
C
/* dbg_div3.c —— divmod 恒等式自检: q*b + r == a 且 0 <= r < b */
|
|
#include "paze/p256.h"
|
|
#include "paze/bignum.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
static uint32_t xr = 0x9e3779b9u;
|
|
static uint32_t rnd(void) { xr ^= xr << 13; xr ^= xr >> 17; xr ^= xr << 5; return xr; }
|
|
|
|
int main(void) {
|
|
paze_bn_t p;
|
|
paze_p256_load_p(&p);
|
|
|
|
/* case 1: a = (p-1)^2, b = p */
|
|
paze_bn_t pm1, a, b, q, r, chk, prod;
|
|
paze_bn_set_u32(&pm1, 1);
|
|
paze_bn_sub(&pm1, &p, &pm1);
|
|
paze_bn_mul(&a, &pm1, &pm1);
|
|
paze_bn_divmod(&q, &r, &a, &p);
|
|
paze_bn_mul(&prod, &q, &p);
|
|
paze_bn_add(&chk, &prod, &r);
|
|
printf("case1 q*b+r==a: %d (q.n=%d r.n=%d a.n=%d)\n",
|
|
paze_bn_cmp(&chk, &a) == 0, q.n, r.n, a.n);
|
|
{
|
|
char h[700];
|
|
paze_bn_to_hex(&q, h, sizeof(h)); printf("q = %s\n", h);
|
|
paze_bn_to_hex(&r, h, sizeof(h)); printf("r = %s\n", h);
|
|
/* 期望 q = p-2, r = 1 */
|
|
paze_bn_t pm2;
|
|
paze_bn_set_u32(&pm2, 2);
|
|
paze_bn_sub(&pm2, &p, &pm2);
|
|
paze_bn_to_hex(&pm2, h, sizeof(h)); printf("expect q = %s\n", h);
|
|
printf("q==p-2: %d r==1: %d\n", paze_bn_cmp(&q, &pm2) == 0,
|
|
paze_bn_is_one(&r));
|
|
}
|
|
|
|
/* case 2: 随机 a (8-16 limbs) 除以 p */
|
|
int fails = 0;
|
|
for (int iter = 0; iter < 200 && !fails; iter++) {
|
|
uint8_t ab[40];
|
|
for (int i = 0; i < 40; i++) ab[i] = (uint8_t)rnd();
|
|
paze_bn_from_bytes(&a, ab, 40); /* 320 位 */
|
|
paze_bn_divmod(&q, &r, &a, &p);
|
|
paze_bn_mul(&prod, &q, &p);
|
|
paze_bn_add(&chk, &prod, &r);
|
|
if (paze_bn_cmp(&chk, &a) != 0) {
|
|
printf("case2 FAIL iter=%d\n", iter);
|
|
fails++;
|
|
}
|
|
/* 0 <= r < p */
|
|
if (paze_bn_cmp(&r, &p) >= 0) {
|
|
printf("case2 r>=p FAIL iter=%d\n", iter);
|
|
fails++;
|
|
}
|
|
}
|
|
printf("case2 random 320-bit: fails=%d\n", fails);
|
|
|
|
/* case 3: 随机 512 位 a */
|
|
fails = 0;
|
|
for (int iter = 0; iter < 200 && !fails; iter++) {
|
|
uint8_t ab[64];
|
|
for (int i = 0; i < 64; i++) ab[i] = (uint8_t)rnd();
|
|
paze_bn_from_bytes(&a, ab, 64); /* 512 位 */
|
|
paze_bn_divmod(&q, &r, &a, &p);
|
|
paze_bn_mul(&prod, &q, &p);
|
|
paze_bn_add(&chk, &prod, &r);
|
|
if (paze_bn_cmp(&chk, &a) != 0) {
|
|
printf("case3 FAIL iter=%d\n", iter);
|
|
fails++;
|
|
}
|
|
if (paze_bn_cmp(&r, &p) >= 0) {
|
|
printf("case3 r>=p FAIL iter=%d\n", iter);
|
|
fails++;
|
|
}
|
|
}
|
|
printf("case3 random 512-bit: fails=%d\n", fails);
|
|
return 0;
|
|
}
|