XU XUv0.8.8
中文

API

#crypto/rsa

import: #crypto/rsa

counts: 5 fns, 1 methods, 2 types, 4 consts, 0 ifaces

PKCS#1 v1.5 encrypt and sign. No OAEP/PSS.

const sha1

XuAPI
pub const sha1 = 3

Purpose

`crypto/rsa` subset: PublicKey / PrivateKey, GenerateKey, EncryptPKCS1v15 / DecryptPKCS1v15, SignPKCS1v15 / VerifyPKCS1v15, EncryptOAEP / DecryptOAEP, SignPSS / VerifyPSS (RFC 8017; hash SHA-1/256/512). Hash IDs match `crypto.Hash` (SHA-1=3, SHA-256=5, SHA-384=6, SHA-512=7). No CRT/blinding. v1 GenerateKey allows bits>=64 (tests) production keys should be >=2048. XU-CT-CLASS: variable-time math/big exponentiation and padding paths have no constant-time contract crypto/subtle is used only for final fixed-shape equality checks. Value `3`.

Parameters

none

const sha256

XuAPI
pub const sha256 = 5

Purpose

Public constant `sha256`. Value `5`.

Parameters

none

const sha384

XuAPI
pub const sha384 = 6

Purpose

Public constant `sha384`. Value `6`.

Parameters

none

const sha512

XuAPI
pub const sha512 = 7

Purpose

Public constant `sha512`. Value `7`.

Parameters

none

struct PublicKey

XuAPI
pub struct PublicKey {
    pub n big.Int
    pub e int
}

Purpose

Public struct `PublicKey`.

Parameters

n big.Int
count, length, or limit
e int
field (int)

struct PrivateKey

XuAPI
pub struct PrivateKey {
    pub public PublicKey
    pub d big.Int
    pub p big.Int
    pub q big.Int
}

Purpose

Public struct `PrivateKey`.

Parameters

public PublicKey
field (PublicKey)
d big.Int
field (big.Int)
p big.Int
field (big.Int)
q big.Int
field (big.Int)

(&PublicKey) size

XuAPI
pub fn (pk &PublicKey) size() int

Purpose

Method on `&PublicKey`: return the size.

Parameters

pk &PublicKey
receiver &PublicKey (borrow)

Returns

int — a value of this type

encrypt_pkcs1v15

XuAPI
pub fn encrypt_pkcs1v15(pk &PublicKey, msg &string) string

Purpose

Encrypt pkcs1v15. Throws on failure.

Parameters

pk &PublicKey
pk (borrowed; caller keeps it; type &PublicKey)
msg &string
message (borrowed; caller keeps it; type &string)

Returns

string — result string

decrypt_pkcs1v15

XuAPI
pub fn decrypt_pkcs1v15(priv &PrivateKey, ciphertext &string) string

Purpose

Decrypt pkcs1v15. Throws on failure.

Parameters

priv &PrivateKey
priv (borrowed; caller keeps it; type &PrivateKey)
ciphertext &string
ciphertext (borrowed; caller keeps it; type &string)

Returns

string — result string

sign_pkcs1v15

XuAPI
pub fn sign_pkcs1v15(priv &PrivateKey, hash int, hashed &string) string

Purpose

Sign pkcs1v15. Throws on failure.

Parameters

priv &PrivateKey
priv (borrowed; caller keeps it; type &PrivateKey)
hash int
hash (int)
hashed &string
hashed (borrowed; caller keeps it; type &string)

Returns

string — result string

verify_pkcs1v15

XuAPI
pub fn verify_pkcs1v15(pk &PublicKey, hash int, hashed &string, sig &string) int

Purpose

Verify pkcs1v15. Throws on failure.

Parameters

pk &PublicKey
pk (borrowed; caller keeps it; type &PublicKey)
hash int
hash (int)
hashed &string
hashed (borrowed; caller keeps it; type &string)
sig &string
sig (borrowed; caller keeps it; type &string)

Returns

int — a value of this type

generate_key

XuAPI
pub fn generate_key(bits int) PrivateKey

Purpose

Generate key. Throws on failure.

Parameters

bits int
bit count (int)

Returns

PrivateKey — a value of this type