文件
PazeSSH/include/paze/curve25519.h
T

42 行
1.4 KiB
C

#ifndef PAZE_CURVE25519_H
#define PAZE_CURVE25519_H
#include "paze/paze_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* X25519 (RFC 7748):Curve25519 上的 Diffie-Hellman 标量乘法。
*
* 约定:所有标量与点均为 32 字节小端字节串。
* paze_x25519(out, scalar, u) 等价于 out = scalar * u (mod p),
* 其中 u 已按 RFC 7748 第 5 节解码(高位已剥离、第 6 位已清零)。
* 若 u 为基点 9 的字节表示,即为公钥生成。
*
* 返回 PAZE_OK;输出始终确定性填充(防止侧信道泄漏)。
*
* 典型用法:
* 私钥:32 字节随机 -> clamp(由本函数内部完成) -> paze_x25519(pub, sk, basepoint=9)
* 共享秘密:paze_x25519(ss, my_sk, peer_pub)
*/
/* 基点 u=9 的 32 字节小端表示。 */
extern const uint8_t paze_x25519_basepoint[32];
/* 标量乘法:out = scalar * u。
* scalar/u/in/out 均 32 字节小端;内部对 scalar 做 clamp(低位清零、高位置位)。
* 返回 PAZE_OK。 */
int paze_x25519(uint8_t out[32], const uint8_t scalar[32], const uint8_t u[32]);
/* 公钥生成:pub = sk * 9。sk 应为 32 字节随机。 */
int paze_x25519_public(uint8_t pub[32], const uint8_t sk[32]);
/* 共享秘密:shared = my_sk * peer_pub。 */
int paze_x25519_shared(uint8_t shared[32],
const uint8_t my_sk[32],
const uint8_t peer_pub[32]);
#ifdef __cplusplus
}
#endif
#endif /* PAZE_CURVE25519_H */