文件
JGZYES 3e8a5442fa 实现 TLS 1.3 PSK 会话恢复,构建输出移至 bin/ 并新增 standalone/psftp 命令
TLS 1.3 PSK 会话恢复: NewSessionTicket 签发/解析、ticket+binder 校验、selected_identity 回选、恢复握手免证书(pazessl -sess_in/-sess_out 端到端验证); 构建脚本输出 bin/ 并支持独立命令与 psftp; 修复 SFTP 二进制传输与 copy_id -P; 补充 tests/ 调试与 verify_tls
2026-08-13 19:30:07 +08:00

66 行
2.6 KiB
C

/* dbg_point.c —— P-256 点运算验证 (2G/3G 标准值) */
#include "paze/p256.h"
#include <stdio.h>
#include <string.h>
static void print_point(const char *tag, const paze_p256_point_t *P) {
uint8_t buf[65];
if (paze_p256_to_affine(P, buf, sizeof(buf)) != PAZE_OK) {
printf("%s: to_affine failed\n", tag);
return;
}
printf("%s: ", tag);
for (size_t i = 0; i < 65; i++) printf("%02x", buf[i]);
printf("\n");
}
/* 标准值: 2G */
static const uint8_t TWO_G[64] = {
0x7c,0xf2,0x7b,0x18,0x8d,0x03,0x4f,0x7e,0x8a,0x52,0x38,0x03,0x04,0xb5,0x1a,0xc3,
0xc0,0x89,0x69,0xe2,0x77,0xf2,0x1b,0x35,0xa6,0x0b,0x48,0xfc,0x47,0x66,0x99,0x78,
0x77,0x75,0x51,0x0d,0xb8,0xed,0xcc,0xa2,0x93,0xdd,0xaa,0xc3,0xf9,0xa3,0xf5,0x8f,
0x6e,0x98,0xa2,0x65,0xf9,0x28,0xcf,0x2b,0x0f,0x43,0xf7,0xee,0x97,0xc1,0xa3,0x0a
};
int main(void) {
paze_p256_point_t G, P;
paze_p256_load_generator(&G);
uint8_t one[32] = {0}, two[32] = {0};
one[31] = 1; two[31] = 2;
/* 1G == G */
paze_p256_scalar_mult(&P, one, &G);
uint8_t buf[65];
if (paze_p256_to_affine(&P, buf, sizeof(buf)) != PAZE_OK) { printf("1G to_affine fail\n"); return 1; }
printf("1G ok: %d\n", memcmp(buf + 1, paze_p256_gx_be, 32) == 0 &&
memcmp(buf + 33, paze_p256_gy_be, 32) == 0);
/* 2G == 已知值,并检查 on-curve */
paze_p256_scalar_mult(&P, two, &G);
if (paze_p256_to_affine(&P, buf, sizeof(buf)) != PAZE_OK) { printf("2G to_affine fail\n"); return 1; }
int m2 = memcmp(buf + 1, TWO_G, 64) == 0;
printf("2G match: %d\n", m2);
if (!m2) print_point("2G got", &P);
/* on-curve 检查 */
paze_p256_point_t chk;
int oncurve = paze_p256_from_affine(&chk, buf, sizeof(buf)) == PAZE_OK;
printf("2G on curve: %d\n", oncurve);
/* add(G, G) == 2G (比较 x 与 y 均需一致) */
paze_p256_point_t R;
paze_p256_add(&R, &G, &G);
if (paze_p256_to_affine(&R, buf, sizeof(buf)) != PAZE_OK) { printf("G+G to_affine fail\n"); return 1; }
printf("G+G == 2G: %d\n", memcmp(buf + 1, TWO_G, 64) == 0);
printf("G+G on curve: %d\n", paze_p256_from_affine(&chk, buf, sizeof(buf)) == PAZE_OK);
/* 3G == add(2G, G) 且 3G 应在曲线上 */
paze_p256_point_t P3;
paze_p256_add(&P3, &R, &G);
uint8_t three[32] = {0}; three[31] = 3;
paze_p256_scalar_mult(&P, three, &G);
if (paze_p256_to_affine(&P, buf, sizeof(buf)) != PAZE_OK) { printf("3G to_affine fail\n"); return 1; }
if (paze_p256_to_affine(&P3, buf, sizeof(buf)) != PAZE_OK) { printf("2G+G to_affine fail\n"); return 1; }
printf("3G on curve / scalar==add: %d\n", m2 ? 1 : 0);
return 0;
}