XU XUv0.8.8
中文

API

#crypto/des

import: #crypto/des

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

DES / 3DES-EDE single block.

const block_size

XuAPI
pub const block_size = 8

Purpose

DES and Triple DES (FIPS 46-3) aligned with `crypto/des` NewCipher / NewTripleDESCipher. Single 8-byte block encrypt/decrypt. Permutation tables use lsb bit indices. IP/FP/E/P/S-box are parsed once in new_cipher and read by field index in crypt_block Not constant-time. Value `8`.

Parameters

none

struct Cipher

XuAPI
pub struct Cipher {
    pub subkeys []int
}

Purpose

Public struct `Cipher`.

Parameters

subkeys []int
field ([]int)

struct TripleCipher

XuAPI
pub struct TripleCipher {
    pub k1 []int
    pub k2 []int
    pub k3 []int
}

Purpose

Public struct `TripleCipher`.

Parameters

k1 []int
field ([]int)
k2 []int
field ([]int)
k3 []int
field ([]int)

new_cipher

XuAPI
pub fn new_cipher(key &string) Cipher

Purpose

Construct cipher. Throws on failure.

Parameters

key &string
key (borrowed; caller keeps it; type &string)

Returns

Cipher — a value of this type

(&Cipher) block_size

XuAPI
pub fn (c &Cipher) block_size() int

Purpose

Method on `&Cipher`: block size.

Parameters

c &Cipher
receiver &Cipher (borrow)

Returns

int — a value of this type

(&Cipher) encrypt

XuAPI
pub fn (c &Cipher) encrypt(src &string) string

Purpose

Method on `&Cipher`: encrypt.

Parameters

c &Cipher
receiver &Cipher (borrow)
src &string
source (borrowed; caller keeps it; type &string)

Returns

string — result string

(&Cipher) decrypt

XuAPI
pub fn (c &Cipher) decrypt(src &string) string

Purpose

Method on `&Cipher`: decrypt.

Parameters

c &Cipher
receiver &Cipher (borrow)
src &string
source (borrowed; caller keeps it; type &string)

Returns

string — result string

new_triple_cipher

XuAPI
pub fn new_triple_cipher(key &string) TripleCipher

Purpose

Construct triple cipher. Throws on failure.

Parameters

key &string
key (borrowed; caller keeps it; type &string)

Returns

TripleCipher — a value of this type

(&TripleCipher) encrypt

XuAPI
pub fn (c &TripleCipher) encrypt(src &string) string

Purpose

Method on `&TripleCipher`: encrypt.

Parameters

c &TripleCipher
receiver &TripleCipher (borrow)
src &string
source (borrowed; caller keeps it; type &string)

Returns

string — result string

(&TripleCipher) decrypt

XuAPI
pub fn (c &TripleCipher) decrypt(src &string) string

Purpose

Method on `&TripleCipher`: decrypt.

Parameters

c &TripleCipher
receiver &TripleCipher (borrow)
src &string
source (borrowed; caller keeps it; type &string)

Returns

string — result string