XU XUv0.16.0

#crypto/rsa

import: #crypto/rsa

counts: 7 functions, 1 methods, 2 types, 4 constants, 0 method sets

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

const SHA1

XuAPI
pub const SHA1 = 3

Purpose

Constant SHA1, defining protocol or algorithm parameters.

const SHA256

XuAPI
pub const SHA256 = 5

Purpose

Constant SHA256, defining protocol or algorithm parameters.

const SHA384

XuAPI
pub const SHA384 = 6

Purpose

Constant SHA384, defining protocol or algorithm parameters.

const SHA512

XuAPI
pub const SHA512 = 7

Purpose

Constant SHA512, defining protocol or algorithm parameters.

struct PublicKey

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

Purpose

Structure encapsulating n, e.

Public fields

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

Structure encapsulating public, d, p, q.

Public fields

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

Operation on &PublicKey: return the size.

Parameters

pk &PublicKey
The PublicKey instance used by this call (borrow).

Returns

int — a value of this type

rsa_priv_op

XuAPI
pub fn rsa_priv_op(priv &PrivateKey, c &big.Int) big.Int

Purpose

Rsa priv op. Throws on failure; handle the error or propagate it to the caller.

Parameters

priv &PrivateKey
priv (read-only borrow; caller keeps the original; type &PrivateKey)
c &big.Int
byte or character code (read-only borrow; caller keeps the original; type &big.Int)

Returns

big.Int — a value of this type

encrypt_pkcs1v15

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

Purpose

Encrypt pkcs1v15. Throws on failure; handle the error or propagate it to the caller.

Parameters

pk &PublicKey
pk (read-only borrow; caller keeps the original; type &PublicKey)
msg &string
message (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

decrypt_pkcs1v15

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

Purpose

Decrypt pkcs1v15. Throws on failure; handle the error or propagate it to the caller.

Parameters

priv &PrivateKey
priv (read-only borrow; caller keeps the original; type &PrivateKey)
ciphertext &string
ciphertext (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

decrypt_pkcs1v15_session_key

XuAPI
pub fn decrypt_pkcs1v15_session_key(priv &PrivateKey, ciphertext &string, key_len int) string

Purpose

decrypt_pkcs1v15_session_key decrypts a fixed-length PKCS#1 v1.5 session key (such as a 48-byte TLS pre-master secret) in constant time without leaking padding validity, substituting a random key on invalid padding. Throws on failure; handle the error or propagate it to the caller.

Parameters

priv &PrivateKey
priv (read-only borrow; caller keeps the original; type &PrivateKey)
ciphertext &string
ciphertext (read-only borrow; caller keeps the original; type &string)
key_len int
key_len (int)

Returns

string — result string

sign_pkcs1v15

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

Purpose

Sign pkcs1v15. Throws on failure; handle the error or propagate it to the caller.

Parameters

priv &PrivateKey
priv (read-only borrow; caller keeps the original; type &PrivateKey)
hash int
hash (int)
hashed &string
hashed (read-only borrow; caller keeps the original; 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; handle the error or propagate it to the caller.

Parameters

pk &PublicKey
pk (read-only borrow; caller keeps the original; type &PublicKey)
hash int
hash (int)
hashed &string
hashed (read-only borrow; caller keeps the original; type &string)
sig &string
sig (read-only borrow; caller keeps the original; 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; handle the error or propagate it to the caller.

Parameters

bits int
bit count (int)

Returns

PrivateKey — a value of this type