nl::Weave::Crypto

這個命名空間包含 Weave 中的所有介面,用於共用加密編譯。

摘要

列舉

X963EncodedPointFormat 列舉

Typedefs

AES128CTRDRBG typedef
AES128CTRMode typedef
AES256CTRMode typedef
EntropyFunct)(uint8_t *buf, size_t bufSize) typedef
int(*
用來從熵來源收集隨機資料的函式簽章。
HKDFSHA1 typedef
HKDFSHA256 typedef
HMACSHA1 typedef
HMACSHA256 typedef

函式

ClearSecretData(uint8_t *buf, uint32_t len)
NL_DLL_EXPORT void
清除記憶體區域 buf 的前 len 個位元組。
ConstantTimeCompare(const uint8_t *buf1, const uint8_t *buf2, uint16_t len)
bool
比較記憶體區域 buf1 和記憶體區域 buf2 的前 len 個位元組。
DecodeBIGNUMValueLE(BIGNUM & val, uint16_t size, const uint8_t *& p)
DecodeECDSASignature(const EncodedECDSASignature & encodedSig, ECDSA_SIG *& sig)
DecodeECKey(OID curveOID, const EncodedECPrivateKey *encodedPrivKey, const EncodedECPublicKey *encodedPubKey, EC_KEY *& ecKey)
NL_DLL_EXPORT WEAVE_ERROR
DecodeX962ECPoint(const uint8_t *encodedPoint, uint16_t encodedPointLen, EC_GROUP *group, EC_POINT *& point)
NL_DLL_EXPORT WEAVE_ERROR
DecodeX962ECPoint(const uint8_t *encodedPoint, uint16_t encodedPointLen, BIGNUM *& x, BIGNUM *& y)
ECDHComputeSharedSecret(OID curveOID, const EC_GROUP *ecGroup, const EC_POINT *pubKeyPoint, const BIGNUM *privKeyBN, uint8_t *sharedSecretBuf, uint16_t sharedSecretBufSize, uint16_t & sharedSecretLen)
NL_DLL_EXPORT WEAVE_ERROR
ECDHComputeSharedSecret(OID curveOID, const EncodedECPublicKey & encodedPubKey, const EncodedECPrivateKey & encodedPrivKey, uint8_t *sharedSecretBuf, uint16_t sharedSecretBufSize, uint16_t & sharedSecretLen)
ECDSASigToFixedLenSig(OID curveOID, const ECDSA_SIG *ecSig, uint8_t *fixedLenSig)
ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps)
void
ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s)
int
EncodeBIGNUMValueLE(const BIGNUM & val, uint16_t size, uint8_t *& p)
EncodeECDSASignature(const ECDSA_SIG *sig, EncodedECDSASignature & encodedSig)
EncodeX962ECPoint(OID curveOID, EC_GROUP *ecGroup, const EC_POINT *point, uint8_t *buf, uint16_t bufSize, uint16_t & encodedPointLen)
NL_DLL_EXPORT WEAVE_ERROR
FixedLenSigToECDSASig(OID curveOID, const uint8_t *fixedLenSig, ECDSA_SIG *& ecSig)
GenerateAndEncodeWeaveHMACSignature(OID sigAlgoOID, TLVWriter & writer, uint64_t tag, const uint8_t *data, uint16_t dataLen, const uint8_t *key, uint16_t keyLen)
產生 Weave HMAC 簽名並進行編碼。
GenerateAndEncodeWeaveRSASignature(OID sigAlgoOID, TLVWriter & writer, uint64_t tag, const uint8_t *hash, uint8_t hashLen, const uint8_t *keyDER, uint16_t keyDERLen)
產生 Weave RSA 簽名並編碼。
GenerateECDHKey(OID curveOID, EncodedECPublicKey & encodedPubKey, EncodedECPrivateKey & encodedPrivKey)
GenerateECDSASignature(OID curveOID, const uint8_t *msgHash, uint8_t msgHashLen, const EncodedECPrivateKey & encodedPrivKey, EncodedECDSASignature & encodedSig)
GenerateECDSASignature(OID curveOID, const uint8_t *msgHash, uint8_t msgHashLen, const EncodedECPrivateKey & encodedPrivKey, uint8_t *fixedLenSig)
GetCurveG(OID curveOID, EncodedECPublicKey & encodedPubKey)
GetCurveSize(const OID curveOID, const EC_GROUP *ecGroup)
int
GetCurveSize(const OID curveOID)
int
取得橢圓曲線大小 (以位元組為單位)。
GetECGroupForCurve(OID curveOID, EC_GROUP *& ecGroup)
NL_DLL_EXPORT WEAVE_ERROR
ReverseBytes(uint8_t *buf, size_t len)
void
ShaNIDFromSigAlgoOID(OID sigAlgoOID)
int
VerifyECDSASignature(OID curveOID, const uint8_t *msgHash, uint8_t msgHashLen, const EncodedECDSASignature & encodedSig, const EncodedECPublicKey & encodedPubKey)
VerifyECDSASignature(OID curveOID, const uint8_t *msgHash, uint8_t msgHashLen, const uint8_t *fixedLenSig, const EncodedECPublicKey & encodedPubKey)
VerifyHMACSignature(OID sigAlgoOID, const uint8_t *data, uint16_t dataLen, const EncodedHMACSignature & sig, const uint8_t *key, uint16_t keyLen)
驗證 Weave HMAC 簽名。
VerifyRSASignature(OID sigAlgoOID, const uint8_t *hash, uint8_t hashLen, const EncodedRSASignature & sig, const uint8_t *certDER, uint16_t certDERLen)
驗證 Weave RSA 簽名。

類別

nl::Weave::Crypto::CTRMode
nl::Weave::Crypto::CTR_DRBG
nl::Weave::Crypto::EncodedECDSASignature
nl::Weave::Crypto::EncodedECPrivateKey
nl::Weave::Crypto::EncodedECPublicKey
nl::Weave::Crypto::EncodedHMACSignature
nl::Weave::Crypto::EncodedRSAKey
nl::Weave::Crypto::EncodedRSASignature
nl::Weave::Crypto::HKDF
nl::Weave::Crypto::HKDFSHA1Or256
nl::Weave::Crypto::HMAC

列舉

X963EncodedPointFormat

 X963EncodedPointFormat

Typedefs

AES128CTRDRBG

CTR_DRBG< Platform::Security::AES128BlockCipherEnc > AES128CTRDRBG

AES128CTRMode

CTRMode< Platform::Security::AES128BlockCipherEnc > AES128CTRMode

AES256CTRMode

CTRMode< Platform::Security::AES256BlockCipherEnc > AES256CTRMode

EntropyFunct

int(* EntropyFunct)(uint8_t *buf, size_t bufSize)

用來從熵來源收集隨機資料的函式簽章。

HKDFSHA1

HKDF< Platform::Security::SHA1 > HKDFSHA1

HKDFSHA256

HKDF< Platform::Security::SHA256 > HKDFSHA256

HMACSHA1

HMAC< Platform::Security::SHA1 > HMACSHA1

HMACSHA256

HMAC< Platform::Security::SHA256 > HMACSHA256

函式

ClearSecretData

NL_DLL_EXPORT void ClearSecretData(
  uint8_t *buf,
  uint32_t len
)

清除記憶體區域 buf 的前 len 個位元組。

在此實作中,buf 記憶體區域 buf 的前 len 個位元組已填入 0。

詳細說明
參數
[in] buf
記憶體緩衝區的指標,其中含有應清除的密鑰資料。
[in] len
指定密鑰資料大小 (以位元組為單位)。

ConstantTimeCompare

bool ConstantTimeCompare(
  const uint8_t *buf1,
  const uint8_t *buf2,
  uint16_t len
)

比較記憶體區域 buf1 和記憶體區域 buf2 的前 len 個位元組。

這個函式所需的時間與記憶體區域 buf1buf2 中的資料無關。

詳細說明
參數
[in] buf1
記憶體區塊的指標。
[in] buf2
記憶體區塊的指標。
[in] len
要比較的記憶體區域大小 (以位元組為單位)。
傳回值
true
(如果記憶體區域 buf1buf2 的前 len 個位元組相等)。
false
否則。

DecodeBIGNUMValueLE

WEAVE_ERROR DecodeBIGNUMValueLE(
  BIGNUM & val,
  uint16_t size,
  const uint8_t *& p
)

DecodeECDSASignature

WEAVE_ERROR DecodeECDSASignature(
  const EncodedECDSASignature & encodedSig,
  ECDSA_SIG *& sig
)

DecodeECKey

NL_DLL_EXPORT WEAVE_ERROR DecodeECKey(
  OID curveOID,
  const EncodedECPrivateKey *encodedPrivKey,
  const EncodedECPublicKey *encodedPubKey,
  EC_KEY *& ecKey
)

解碼 X962ECPoint

NL_DLL_EXPORT WEAVE_ERROR DecodeX962ECPoint(
  const uint8_t *encodedPoint,
  uint16_t encodedPointLen,
  EC_GROUP *group,
  EC_POINT *& point
)

解碼 X962ECPoint

WEAVE_ERROR DecodeX962ECPoint(
  const uint8_t *encodedPoint,
  uint16_t encodedPointLen,
  BIGNUM *& x,
  BIGNUM *& y
)

ECDHComputeSharedSecret

NL_DLL_EXPORT WEAVE_ERROR ECDHComputeSharedSecret(
  OID curveOID,
  const EC_GROUP *ecGroup,
  const EC_POINT *pubKeyPoint,
  const BIGNUM *privKeyBN,
  uint8_t *sharedSecretBuf,
  uint16_t sharedSecretBufSize,
  uint16_t & sharedSecretLen
)

ECDHComputeSharedSecret

WEAVE_ERROR ECDHComputeSharedSecret(
  OID curveOID,
  const EncodedECPublicKey & encodedPubKey,
  const EncodedECPrivateKey & encodedPrivKey,
  uint8_t *sharedSecretBuf,
  uint16_t sharedSecretBufSize,
  uint16_t & sharedSecretLen
)

ECDSASigToFixedLenSig

WEAVE_ERROR ECDSASigToFixedLenSig(
  OID curveOID,
  const ECDSA_SIG *ecSig,
  uint8_t *fixedLenSig
)

ECDSA_SIG_get0

void ECDSA_SIG_get0(
  const ECDSA_SIG *sig,
  const BIGNUM **pr,
  const BIGNUM **ps
)

ECDSA_SIG_set0

int ECDSA_SIG_set0(
  ECDSA_SIG *sig,
  BIGNUM *r,
  BIGNUM *s
)

EncodeBIGNUMValueLE

WEAVE_ERROR EncodeBIGNUMValueLE(
  const BIGNUM & val,
  uint16_t size,
  uint8_t *& p
)

EncodeECDSASignature

WEAVE_ERROR EncodeECDSASignature(
  const ECDSA_SIG *sig,
  EncodedECDSASignature & encodedSig
)

EncodeX962ECPoint

NL_DLL_EXPORT WEAVE_ERROR EncodeX962ECPoint(
  OID curveOID,
  EC_GROUP *ecGroup,
  const EC_POINT *point,
  uint8_t *buf,
  uint16_t bufSize,
  uint16_t & encodedPointLen
)

FixedLenSigToECDSASig

WEAVE_ERROR FixedLenSigToECDSASig(
  OID curveOID,
  const uint8_t *fixedLenSig,
  ECDSA_SIG *& ecSig
)

GenerateAndEncodeWeaveHMACSignature

WEAVE_ERROR GenerateAndEncodeWeaveHMACSignature(
  OID sigAlgoOID,
  TLVWriter & writer,
  uint64_t tag,
  const uint8_t *data,
  uint16_t dataLen,
  const uint8_t *key,
  uint16_t keyLen
)

產生 Weave HMAC 簽名並進行編碼。

使用密鑰計算指定資料的 HMAC 簽名,並以 Weave HMAC 簽章結構的形式,將簽章寫入指定的 TLV 寫入者。

詳細說明
參數
[in] sigAlgoOID
要用來產生 HMAC 簽名的演算法 OID。
[in] writer
應寫入編碼簽章的 TLVWriter 物件。
[in] tag
TLV 標記要與編碼的簽名結構建立關聯。
[in] data
包含要簽署資料的緩衝區。
[in] dataLen
資料的長度 (以位元組為單位)。
[in] key
緩衝區,包含用於產生 HMAC 簽名的密鑰。
[in] keyLen
密鑰的長度 (以位元組為單位)。
傳回值
WEAVE_NO_ERROR
如果作業成功。
other
與簽名編碼相關的其他 Weave 錯誤代碼。

GenerateAndEncodeWeaveRSASignature

WEAVE_ERROR GenerateAndEncodeWeaveRSASignature(
  OID sigAlgoOID,
  TLVWriter & writer,
  uint64_t tag,
  const uint8_t *hash,
  uint8_t hashLen,
  const uint8_t *keyDER,
  uint16_t keyDERLen
)

產生 Weave RSA 簽名並編碼。

這個外掛程式能使用指定的 X509 編碼 RSA 私密金鑰和訊息雜湊計算 RSA 簽名,並以 Weave RSASignature 結構的形式將簽名寫入具有指定標記的指定 TLV 寫入者。

詳細說明
參數
[in] sigAlgoOID
用於產生 RSA 簽名的演算法 OID。
[in] writer
應寫入編碼簽章的 TLVWriter 物件。
[in] tag
TLV 標記要與編碼的簽名結構建立關聯。
[in] hash
緩衝區,內含要簽署的資料雜湊。
[in] hashLen
資料雜湊的長度 (以位元組為單位)。
[in] keyDER
包含用於產生簽章的私密金鑰的緩衝區。私密金鑰應採用 X509 RSA 私密金鑰結構進行編碼。
[in] keyDERLen
經過編碼的私密金鑰長度 (以位元組為單位)。
傳回值
WEAVE_NO_ERROR
如果作業成功。
other
其他與將私密金鑰解碼 (產生簽章或編碼) 相關的 Weave 錯誤代碼。

GenerateECDHKey

WEAVE_ERROR GenerateECDHKey(
  OID curveOID,
  EncodedECPublicKey & encodedPubKey,
  EncodedECPrivateKey & encodedPrivKey
)

GenerateECDSASignature

WEAVE_ERROR GenerateECDSASignature(
  OID curveOID,
  const uint8_t *msgHash,
  uint8_t msgHashLen,
  const EncodedECPrivateKey & encodedPrivKey,
  EncodedECDSASignature & encodedSig
)

GenerateECDSASignature

WEAVE_ERROR GenerateECDSASignature(
  OID curveOID,
  const uint8_t *msgHash,
  uint8_t msgHashLen,
  const EncodedECPrivateKey & encodedPrivKey,
  uint8_t *fixedLenSig
)

GetCurveG

WEAVE_ERROR GetCurveG(
  OID curveOID,
  EncodedECPublicKey & encodedPubKey
)

GetCurveSize

int GetCurveSize(
  const OID curveOID,
  const EC_GROUP *ecGroup
)

GetCurveSize

int GetCurveSize(
  const OID curveOID
)

取得橢圓曲線大小 (以位元組為單位)。

詳細說明
參數
[in] curveOID
指定橢圓曲線 OID。
傳回值
Returns
如果指定的 curveOID 不支援橢圓曲線,則為 0。否則會傳回曲線大小 (以位元組為單位)。

GetECGroupForCurve

NL_DLL_EXPORT WEAVE_ERROR GetECGroupForCurve(
  OID curveOID,
  EC_GROUP *& ecGroup
)

ReverseBytes

void ReverseBytes(
  uint8_t *buf,
  size_t len
)

ShaNIDFromSigAlgoOID

int ShaNIDFromSigAlgoOID(
  OID sigAlgoOID
)

VerifyECDSASignature

WEAVE_ERROR VerifyECDSASignature(
  OID curveOID,
  const uint8_t *msgHash,
  uint8_t msgHashLen,
  const EncodedECDSASignature & encodedSig,
  const EncodedECPublicKey & encodedPubKey
)

VerifyECDSASignature

WEAVE_ERROR VerifyECDSASignature(
  OID curveOID,
  const uint8_t *msgHash,
  uint8_t msgHashLen,
  const uint8_t *fixedLenSig,
  const EncodedECPublicKey & encodedPubKey
)

VerifyHMACSignature

WEAVE_ERROR VerifyHMACSignature(
  OID sigAlgoOID,
  const uint8_t *data,
  uint16_t dataLen,
  const EncodedHMACSignature & sig,
  const uint8_t *key,
  uint16_t keyLen
)

驗證 Weave HMAC 簽名。

使用指定資料和要用來驗證簽名的密鑰,驗證 HMAC 簽章。

詳細說明
參數
[in] sigAlgoOID
要用來產生 HMAC 簽名的演算法 OID。
[in] data
包含要簽署資料的緩衝區。
[in] dataLen
資料的長度 (以位元組為單位)。
[in] sig
要驗證的已編碼 HMAC 簽名。
[in] key
緩衝區,包含用於產生 HMAC 簽名的密鑰。
[in] keyLen
密鑰的長度 (以位元組為單位)。
傳回值
WEAVE_NO_ERROR
HMAC 簽名驗證成功。
WEAVE_ERROR_INVALID_SIGNATURE
如果 HMAC 簽名驗證失敗,

VerifyRSASignature

WEAVE_ERROR VerifyRSASignature(
  OID sigAlgoOID,
  const uint8_t *hash,
  uint8_t hashLen,
  const EncodedRSASignature & sig,
  const uint8_t *certDER,
  uint16_t certDERLen
)

驗證 Weave RSA 簽名。

使用指定的資料雜湊和 X509 編碼 RSA 憑證來驗證 RSA 簽名,此憑證包含用於驗證簽名的公開金鑰。

詳細說明
參數
[in] sigAlgoOID
用於產生 RSA 簽名的演算法 OID。
[in] hash
緩衝區,內含要簽署的資料雜湊。
[in] hashLen
資料雜湊的長度 (以位元組為單位)。
[in] sig
要驗證的編碼 RSA 簽名。
[in] certDER
這個緩衝區含有憑證,以及用於驗證簽名的公開金鑰。憑證必須採用 DER 編碼為 X509 RSA 結構。
[in] certDERLen
編碼憑證的長度 (以位元組為單位)。
傳回值
WEAVE_NO_ERROR
如果作業成功。