crypto

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthCodeMultiSession

func AuthCodeMultiSession(authType types.AuthType, password []byte, sessionID, sessionSeq uint32, ipmiData []byte) []byte

AuthCodeMultiSession computes the multi-session session-header AuthCode.

func AuthCodeSingleSession

func AuthCodeSingleSession(authType types.AuthType, password []byte, sessionID uint32, challenge []byte) []byte

AuthCodeSingleSession computes the Activate Session AuthCode.

func AuthHMAC

func AuthHMAC(alg types.AuthAlg, data, key []byte) ([]byte, error)

AuthHMAC selects the HMAC variant based on the RAKP authentication algorithm (v2.0§13.28). Returns the full digest (RAKP2/RAKP3 and SIK/K1/K2 use the full digest; RAKP4 truncates separately).

func DecryptAES

func DecryptAES(cipherText, cipherKey, iv []byte) ([]byte, error)

DecryptAES decrypts cipherText with AES-CBC.

func DecryptAESPayload

func DecryptAESPayload(cipherText, k2 []byte) ([]byte, error)

DecryptAESPayload decrypts an AES-CBC-128 confidential payload and strips §13.29 padding. Wire format: IV(16) || ciphertext.

func DecryptRC4

func DecryptRC4(cipherText, cipherKey, iv []byte) ([]byte, error)

DecryptRC4 is identical to EncryptRC4 for RC4 (XOR stream).

func DeriveK1

func DeriveK1(authAlg types.AuthAlg, sik []byte) ([]byte, error)

DeriveK1 computes K1 = HMAC(SIK, 0x01 × 20) per v2.0§13.32.

func DeriveK2

func DeriveK2(authAlg types.AuthAlg, sik []byte) ([]byte, error)

DeriveK2 computes K2 = HMAC(SIK, 0x02 × 20) per v2.0§13.32.

func DeriveSIK

func DeriveSIK(authAlg types.AuthAlg, consoleRand, bmcRand []byte, role uint8, username string, kgOrKuid []byte) ([]byte, error)

DeriveSIK computes the Session Integrity Key (v2.0§13.31):

SIK = HMAC(Kg or Kuid, ConsoleRand || BMCRand || Role || UserLen || Username)

kgOrKuid should be Kg when configured, otherwise the 20-byte padded password.

func DeriveSessionKeys

func DeriveSessionKeys(authAlg types.AuthAlg, consoleRand, bmcRand []byte, role uint8, username string, kgOrKuid []byte) (sik, k1, k2 []byte, err error)

DeriveSessionKeys computes SIK, K1, and K2 from session parameters.

func EncryptAES

func EncryptAES(plainText, cipherKey, iv []byte) ([]byte, error)

EncryptAES encrypts plainText (must be block-aligned) with AES-CBC. cipherKey must be 16, 24, or 32 bytes (AES-128/192/256).

Spec: v2.0§13.29 Encryption with AES.

func EncryptAESPayload

func EncryptAESPayload(plain, k2, iv []byte) ([]byte, error)

EncryptAESPayload encrypts an IPMI confidential payload with AES-CBC-128. k2 is the session K2 key; the first 16 bytes are used as the cipher key. iv must be 16 bytes (caller supplies or uses RandomBytes). Wire format: IV(16) || ciphertext.

func EncryptRC4

func EncryptRC4(plainText, cipherKey, _ []byte) ([]byte, error)

EncryptRC4 / DecryptRC4 apply the RC4 stream cipher (xRC4 confidentiality, v2.0§13.30). IV is unused by the cipher itself but kept in the signature for call-site parity with the AES helpers.

func Equal

func Equal(a, b []byte) bool

Equal compares two HMACs in constant time.

func HMAC

func HMAC(alg string, data, key []byte) ([]byte, error)

HMAC computes a hash-based MAC. Supported algorithms: "md5", "sha1", "sha256".

func IntegrityAuthCodeLen

func IntegrityAuthCodeLen(alg types.IntegrityAlg) (int, bool)

IntegrityAuthCodeLen returns the AuthCode (integrity data) field length for alg (v2.0§13.28.4). ok is false for unknown algorithms.

func IntegrityHMAC

func IntegrityHMAC(alg types.IntegrityAlg, data, key []byte) ([]byte, error)

IntegrityHMAC selects the HMAC variant based on the session integrity algorithm (v2.0§13.28.4). Returns the full digest; callers truncate.

func PadAES

func PadAES(plain []byte) []byte

PadAES pads plain to a multiple of 16 bytes per IPMI 2.0 spec §13.29:

plain || pad bytes (1,2,3,...) || pad-length byte

func PadPassword20

func PadPassword20(password []byte) []byte

PadPassword20 returns the user password padded to 20 bytes (Kuid). Spec: v2.0§13.31 (RAKP key exchange uses 160-bit Kuid).

func RAKP2AuthCode

func RAKP2AuthCode(authAlg types.AuthAlg, consoleID, bmcID uint32, consoleRand, bmcRand, bmcGUID []byte, role uint8, username string, kuid []byte) ([]byte, error)

RAKP2AuthCode generates the Key Exchange Authentication Code for RAKP Message 2 (v2.0§13.31):

HMAC(Kuid, ConsoleID || BMCID || ConsoleRand || BMCRand || BMCGUID || Role || UserLen || Username)

func RAKP2AuthCodeLen

func RAKP2AuthCodeLen(alg types.AuthAlg) int

RAKP2AuthCodeLen returns the expected Key Exchange Authentication Code length in RAKP Message 2 for the given authentication algorithm.

func RAKP3AuthCode

func RAKP3AuthCode(authAlg types.AuthAlg, bmcRand []byte, consoleID uint32, role uint8, username string, kuid []byte) ([]byte, error)

RAKP3AuthCode generates the auth code for RAKP Message 3 (v2.0§13.31):

HMAC(Kuid, BMCRand || ConsoleID || Role || UserLen || Username)

func RAKP3AuthCodeLen

func RAKP3AuthCodeLen(alg types.AuthAlg) int

RAKP3AuthCodeLen returns the expected auth code length in RAKP Message 3.

func RAKP4ICV

func RAKP4ICV(authAlg types.AuthAlg, consoleRand []byte, bmcID uint32, bmcGUID, sik []byte) ([]byte, error)

RAKP4ICV generates the Integrity Check Value for RAKP Message 4.

HMAC input (v2.0§13.31): ConsoleRand || BMCID || BMCGUID

Per v2.0§13.28.1 / §13.28.1b the ICV truncation is selected by the *authentication* algorithm (not the session integrity algorithm), using SIK as the HMAC key:

  • RAKP-HMAC-SHA1 → HMAC-SHA1-96 (12 bytes)
  • RAKP-HMAC-SHA256 → HMAC-SHA256-128 (16 bytes)
  • RAKP-HMAC-MD5 → HMAC-MD5-128 (16 bytes)
  • RAKP-none → absent

func RAKP4ICVLen

func RAKP4ICVLen(alg types.AuthAlg) int

RAKP4ICVLen returns the expected Integrity Check Value length in RAKP Message 4.

func RandomBytes

func RandomBytes(n int) []byte

RandomBytes returns n cryptographically random bytes. Panics if crypto/rand is unavailable (same contract as prior client/server helpers).

func SessionIntegrityAuthCode

func SessionIntegrityAuthCode(alg types.IntegrityAlg, input, k1 []byte, password string) ([]byte, error)

SessionIntegrityAuthCode computes the AuthCode for an authenticated RMCP+ session packet (v2.0§13.28.4). Truncation matches the integrity algorithm:

  • HMAC-SHA1-96 → 12 bytes
  • HMAC-MD5-128 / HMAC-SHA256-128 → 16 bytes
  • MD5-128 → MD5(password || input || password), 16 bytes

password is only used for IntegrityAlg_MD5_128; HMAC variants use k1.

func TruncateRAKP2AuthCode

func TruncateRAKP2AuthCode(alg types.AuthAlg, full []byte) ([]byte, error)

TruncateRAKP2AuthCode truncates a full AuthHMAC digest to the RAKP2 wire length.

func UnpadAES

func UnpadAES(padded []byte) ([]byte, error)

UnpadAES strips IPMI §13.29 AES padding from a decrypted block.

func VerifyMultiSessionAuthCode

func VerifyMultiSessionAuthCode(authType types.AuthType, password []byte, sessionID, sessionSeq uint32, ipmiData, got []byte) bool

VerifyMultiSessionAuthCode returns true when got matches the expected AuthCode.

Types

type MultiSessionInput

type MultiSessionInput struct {
	Password   string
	SessionID  uint32
	SessionSeq uint32
	IPMIData   []byte
}

MultiSessionInput is the AuthCode carried in the v1.5 session header for authenticated packets (v1.5§18.15.1 / v2.0§22.17.1).

func (MultiSessionInput) AuthCode

func (i MultiSessionInput) AuthCode(authType types.AuthType) []byte

AuthCode computes the multi-session AuthCode for authType.

type SingleSessionInput

type SingleSessionInput struct {
	Password  string
	SessionID uint32
	Challenge []byte
}

SingleSessionInput is the AuthCode carried in Activate Session request data (v1.5§18.15.1 / v2.0§22.17.1).

func (SingleSessionInput) AuthCode

func (a SingleSessionInput) AuthCode(authType types.AuthType) []byte

AuthCode computes the single-session AuthCode for authType.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL