TLS 1.3 PSK 会话恢复: NewSessionTicket 签发/解析、ticket+binder 校验、selected_identity 回选、恢复握手免证书(pazessl -sess_in/-sess_out 端到端验证); 构建脚本输出 bin/ 并支持独立命令与 psftp; 修复 SFTP 二进制传输与 copy_id -P; 补充 tests/ 调试与 verify_tls
71 行
1.9 KiB
C
71 行
1.9 KiB
C
/* dbg_div2.c —— divmod 小案例与中间量定位 */
|
|
#include "paze/p256.h"
|
|
#include "paze/bignum.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
static void chk(const char *tag, int cond) {
|
|
printf("%s: %s\n", tag, cond ? "PASS" : "FAIL");
|
|
}
|
|
|
|
static void hexbn(const char *tag, const paze_bn_t *x) {
|
|
char h[600];
|
|
paze_bn_to_hex(x, h, sizeof(h));
|
|
printf("%s = %s (n=%d)\n", tag, h, x->n);
|
|
}
|
|
|
|
int main(void) {
|
|
paze_bn_t q, r, a, b;
|
|
|
|
/* 小 case */
|
|
paze_bn_set_u32(&a, 10); paze_bn_set_u32(&b, 3);
|
|
paze_bn_divmod(&q, &r, &a, &b);
|
|
chk("10/3 q==3", paze_bn_cmp(&q, &(paze_bn_t){{},0})==0 || q.n==1 && q.d[0]==3);
|
|
chk("10/3 r==1", r.n==1 && r.d[0]==1);
|
|
|
|
/* 2^32 / 2 */
|
|
paze_bn_set_u32(&a, 0xFFFFFFFFu);
|
|
paze_bn_set_u64(&b, 2);
|
|
paze_bn_t a32;
|
|
paze_bn_set_u64(&a32, 1);
|
|
paze_bn_lshift(&a32, &a32, 32);
|
|
paze_bn_divmod(&q, &r, &a32, &b);
|
|
chk("2^32/2 q==2^31", q.n==2 && q.d[0]==0x80000000u);
|
|
chk("2^32/2 r==0", paze_bn_is_zero(&r));
|
|
|
|
/* (p+1)/p */
|
|
paze_bn_t p;
|
|
paze_p256_load_p(&p);
|
|
paze_bn_t p1;
|
|
paze_bn_set_u32(&p1, 1);
|
|
paze_bn_add(&p1, &p, &p1);
|
|
paze_bn_divmod(&q, &r, &p1, &p);
|
|
chk("(p+1)/p q==1 r==1", q.n==1 && q.d[0]==1 && r.n==1 && r.d[0]==1);
|
|
|
|
/* 2^256 / p == 1 (2^256 > p, < 2p) */
|
|
paze_bn_t b256;
|
|
paze_bn_set_u32(&b256, 1);
|
|
paze_bn_lshift(&b256, &b256, 256);
|
|
paze_bn_divmod(&q, &r, &b256, &p);
|
|
chk("2^256/p q==1", q.n==1 && q.d[0]==1);
|
|
{
|
|
hexbn("r(2^256 mod p)", &r);
|
|
}
|
|
|
|
/* 2^257 / p == 2 */
|
|
paze_bn_t b257;
|
|
paze_bn_set_u32(&b257, 1);
|
|
paze_bn_lshift(&b257, &b257, 257);
|
|
paze_bn_divmod(&q, &r, &b257, &p);
|
|
chk("2^257/p q==2", q.n==1 && q.d[0]==2);
|
|
|
|
/* 2^300 / p */
|
|
paze_bn_t b300;
|
|
paze_bn_set_u32(&b300, 1);
|
|
paze_bn_lshift(&b300, &b300, 300);
|
|
paze_bn_divmod(&q, &r, &b300, &p);
|
|
hexbn("q(2^300/p)", &q);
|
|
hexbn("r(2^300 mod p)", &r);
|
|
return 0;
|
|
}
|