Update code to v1.0.14 (10)

This commit is contained in:
Caten
2024-02-29 19:35:00 +08:00
parent c2ee3b694c
commit a956d26f6d
3188 changed files with 2317293 additions and 146 deletions

View File

@@ -0,0 +1,752 @@
/*!
\ingroup AES
\brief この関数は、キーを設定して初期化ベクトルを設定することでAES構造を初期化します。
\return 0 キーと初期化ベクトルを正常に設定します。
\return BAD_FUNC_ARG キーの長さが無効な場合は返されます。
\param aes 変更するAES構造へのポインタ
\param key 暗号化と復号化のための16,24、または32バイトの秘密鍵
\param len 渡されたキーの長さ
\param iv キーを初期化するために使用される初期化ベクトルへのポインタ
_Example_
\code
Aes enc;
int ret = 0;
byte key[] = { some 16, 24 or 32 byte key };
byte iv[] = { some 16 byte iv };
if (ret = wc_AesSetKey(&enc, key, AES_BLOCK_SIZE, iv,
AES_ENCRYPTION) != 0) {
// failed to set aes key
}
\endcode
\sa wc_AesSetKeyDirect
\sa wc_AesSetIV
*/
int wc_AesSetKey(Aes* aes, const byte* key, word32 len,
const byte* iv, int dir);
/*!
\ingroup AES
\brief この関数は、特定のAESオブジェクトの初期化ベクトルを設定します。AESオブジェクトは、この関数を呼び出す前に初期化されるべきです。
\return 0 初期化ベクトルを正常に設定します。
\return BAD_FUNC_ARG AESポインタがNULLの場合に返されます。
\param aes 初期化ベクトルを設定するAES構造へのポインタ
_Example_
\code
Aes enc;
// set enc key
byte iv[] = { some 16 byte iv };
if (ret = wc_AesSetIV(&enc, iv) != 0) {
// failed to set aes iv
}
\endcode
\sa wc_AesSetKeyDirect
\sa wc_AesSetKey
*/
int wc_AesSetIV(Aes* aes, const byte* iv);
/*!
\ingroup AES
\brief 入力バッファーから平文メッセージを暗号化し、AESでCipher Block Chainingを使用して出力バッファに出力バッファーに入れます。この機能は、メッセージが暗号化される前にAESSetKeyを呼び出すことによってAESオブジェクトが初期化されていることを必要とします。この関数は、入力メッセージがAESブロック長であると仮定し、入力された長さがブロック長の倍数になることを想定しているため、ビルド構成でWolfSSL_AES_CBC_LENGTH_CHECKSが定義されている場合は任意選択でチェックおよび適用されます。ブロック多入力を保証するために、PKCS7スタイルのパディングを事前に追加する必要があります。これはあなたのためにパディングを追加するOpenSSL AES-CBCメソッドとは異なります。WOLFSSLと対応するOpenSSL関数を相互運用するには、OpenSSLコマンドライン関数で-nopadオプションを指定して、WolfSSL AESCCENCRYPTメソッドのように動作し、暗号化中に追加のパディングを追加しません。
\return 0 メッセージの暗号化に成功しました。
\return BAD_ALIGN_E: ブロック整列誤差で返される可能性があります
\return BAD_LENGTH_E 入力長がAESブロック長の倍数でない場合は、ライブラリーがwolfssl_aes_cbc_length_checksで構築されている場合に返されます。
\param aes データの暗号化に使用されるAESオブジェクトへのポインタ
\param out 暗号化されたメッセージの暗号文を格納する出力バッファへのポインタ
\param in 暗号化されるメッセージを含む入力バッファへのポインタ
_Example_
\code
Aes enc;
int ret = 0;
// initialize enc with AesSetKey, using direction AES_ENCRYPTION
byte msg[AES_BLOCK_SIZE * n]; // multiple of 16 bytes
// fill msg with data
byte cipher[AES_BLOCK_SIZE * n]; // Some multiple of 16 bytes
if ((ret = wc_AesCbcEncrypt(&enc, cipher, message, sizeof(msg))) != 0 ) {
// block align error
}
\endcode
\sa wc_AesSetKey
\sa wc_AesSetIV
\sa wc_AesCbcDecrypt
*/
int wc_AesCbcEncrypt(Aes* aes, byte* out,
const byte* in, word32 sz);
/*!
\ingroup AES
\brief 入力バッファーから暗号を復号化し、AESでCipher Block Chainingを使用して出力バッファに出力バッファーに入れます。この機能は、メッセージが復号化される前にAESSetKeyを呼び出すことによってAES構造が初期化されていることを必要とします。この関数は、元のメッセージがAESブロック長で整列していたと仮定し、入力された長さがブロック長の倍数になると予想しています。これはOpenSSL AES-CBCメソッドとは異なります。これは、PKCS7パディングを自動的に追加するため、ブロックマルチ入力を必要としません。WolfSSL機能と同等のOpenSSL関数を相互運用するには、OpenSSLコマンドライン関数で-nopadオプションを指定し、wolfssl aescbceNcryptメソッドのように動作し、復号化中にエラーを発生させません。
\return 0 メッセージを正常に復号化します。
\return BAD_ALIGN_E ブロック整列エラーで返される可能性があります。
\return BAD_LENGTH_E 入力長がAESブロック長の倍数でない場合は、ライブラリーがwolfssl_aes_cbc_length_checksで構築されている場合に返されます。
\param aes データを復号化するために使用されるAESオブジェクトへのポインタ。
\param out 復号化されたメッセージのプレーンテキストを保存する出力バッファへのポインタ。
\param in 復号化する暗号テキストを含む入力バッファへのポインタ。
_Example_
\code
Aes dec;
int ret = 0;
// initialize dec with AesSetKey, using direction AES_DECRYPTION
byte cipher[AES_BLOCK_SIZE * n]; // some multiple of 16 bytes
// fill cipher with cipher text
byte plain [AES_BLOCK_SIZE * n];
if ((ret = wc_AesCbcDecrypt(&dec, plain, cipher, sizeof(cipher))) != 0 ) {
// block align error
}
\endcode
\sa wc_AesSetKey
\sa wc_AesCbcEncrypt
*/
int wc_AesCbcDecrypt(Aes* aes, byte* out,
const byte* in, word32 sz);
/*!
\ingroup AES
\brief 入力バッファーからメッセージを暗号化/復号化し、AESを使用してCTRモードを使用して出力バッファーに出力バッファーに入れます。この関数は、wolfssl_aes_counterがコンパイル時に有効になっている場合にのみ有効になります。この機能を呼び出す前に、AES構造体をAessetKeyで初期化する必要があります。この関数は復号化と暗号化の両方に使用されます。_注暗号化と復号化のための同じAPIを使用することについて。ユーザーは暗号化/復号化のためのAES構造体を区別する必要があります。
\return int WolfSSLエラーまたは成功状況に対応する整数値
\param aes データを復号化するために使用されるAESオブジェクトへのポインタ
\param out 暗号化されたメッセージの暗号化テキストを保存する出力バッファへのポインタ
\param in 暗号化されるプレーンテキストを含む入力バッファへのポインタ
_Example_
\code
Aes enc;
Aes dec;
// initialize enc and dec with AesSetKeyDirect, using direction
AES_ENCRYPTION
// since the underlying API only calls Encrypt and by default calling
encrypt on
// a cipher results in a decryption of the cipher
byte msg[AES_BLOCK_SIZE * n]; //n being a positive integer making msg
some multiple of 16 bytes
// fill plain with message text
byte cipher[AES_BLOCK_SIZE * n];
byte decrypted[AES_BLOCK_SIZE * n];
wc_AesCtrEncrypt(&enc, cipher, msg, sizeof(msg)); // encrypt plain
wc_AesCtrEncrypt(&dec, decrypted, cipher, sizeof(cipher));
// decrypt cipher text
\endcode
\sa wc_AesSetKey
*/
int wc_AesCtrEncrypt(Aes* aes, byte* out,
const byte* in, word32 sz);
/*!
\ingroup AES
\brief この関数は、入力ブロックの入力ブロック、IN、OUTPUTブロック、OUTです。提供されたAES構造体のキーを使用します。これはこの機能を呼び出す前にWC_AESSETKEYで初期化される必要があります。WC_AESSETKEYは、IVセットがNULLに呼び出されたはずです。これは、Configure Option WolfSSL_AES_DIRECTが有効になっている場合にのみ有効になります。__ warningほぼすべてのユースケースでECBモードは安全性が低いと考えられています。可能な限りECB APIを直接使用しないでください。
\return int WolfSSLエラーまたは成功状況に対応する整数値
\param aes データの暗号化に使用されるAESオブジェクトへのポインタ
\param out 暗号化されたメッセージの暗号化テキストを保存する出力バッファへのポインタ
_Example_
\code
Aes enc;
// initialize enc with AesSetKey, using direction AES_ENCRYPTION
byte msg [AES_BLOCK_SIZE]; // 16 bytes
// initialize msg with plain text to encrypt
byte cipher[AES_BLOCK_SIZE];
wc_AesEncryptDirect(&enc, cipher, msg);
\endcode
\sa wc_AesDecryptDirect
\sa wc_AesSetKeyDirect
*/
int wc_AesEncryptDirect(Aes* aes, byte* out, const byte* in);
/*!
\ingroup AES
\brief この関数は、入力ブロックの1ブロック復号化、IN、IN、OUTPUT OUTです。提供されたAES構造体のキーを使用します。これはこの機能を呼び出す前にWC_AESSETKEYで初期化される必要があります。WC_AESSETKEYは、IVセットがNULLに呼び出されたはずです。これは、Configure Option WolfSSL_AES_DIRECTが有効になっている場合にのみ有効になります。__ warningほぼすべてのユースケースでECBモードは安全性が低いと考えられています。可能な限りECB APIを直接使用しないでください。
\return int WolfSSLエラーまたは成功状況に対応する整数値
\param aes データの暗号化に使用されるAESオブジェクトへのポインタ
\param out 復号化された暗号テキストのプレーンテキストを格納する出力バッファへのポインタ
_Example_
\code
Aes dec;
// initialize enc with AesSetKey, using direction AES_DECRYPTION
byte cipher [AES_BLOCK_SIZE]; // 16 bytes
// initialize cipher with cipher text to decrypt
byte msg[AES_BLOCK_SIZE];
wc_AesDecryptDirect(&dec, msg, cipher);
\endcode
\sa wc_AesEncryptDirect
\sa wc_AesSetKeyDirect
*/
int wc_AesDecryptDirect(Aes* aes, byte* out, const byte* in);
/*!
\ingroup AES
\brief この関数は、CTRモードのAESキーをAESで設定するために使用されます。指定されたキー、IV初期化ベクトル、および暗号化DIR方向でAESオブジェクトを初期化します。構成オプションwolfssl_aes_directが有効になっている場合にのみ有効になります。現在WC_AessetKeyDirectは内部的にWC_AESSETKEYを使用します。__ warningほぼすべてのユースケースでECBモードは安全性が低いと考えられています。可能な限りECB APIを直接使用しないでください
\return 0 キーの設定に成功しました。
\return BAD_FUNC_ARG 与えられたキーが無効な長さの場合に返されます。
\param aes データの暗号化に使用されるAESオブジェクトへのポインタ
\param key 暗号化と復号化のための16,24、または32バイトの秘密鍵
\param len 渡されたキーの長さ
\param iv キーを初期化するために使用される初期化ベクトル
_Example_
\code
Aes enc;
int ret = 0;
byte key[] = { some 16, 24, or 32 byte key };
byte iv[] = { some 16 byte iv };
if (ret = wc_AesSetKeyDirect(&enc, key, sizeof(key), iv,
AES_ENCRYPTION) != 0) {
// failed to set aes key
}
\endcode
\sa wc_AesEncryptDirect
\sa wc_AesDecryptDirect
\sa wc_AesSetKey
*/
int wc_AesSetKeyDirect(Aes* aes, const byte* key, word32 len,
const byte* iv, int dir);
/*!
\ingroup AES
\brief この機能は、AES GCMGalois / Counter Modeのキーを設定するために使用されます。与えられたキーでAESオブジェクトを初期化します。コンパイル時にConfigureオプションhous_aesgcmが有効になっている場合にのみ有効になります。
\return 0 キーの設定に成功しました。
\return BAD_FUNC_ARG 与えられたキーが無効な長さの場合に返されます。
\param aes データの暗号化に使用されるAESオブジェクトへのポインタ
\param key 暗号化と復号化のための16,24、または32バイトの秘密鍵
_Example_
\code
Aes enc;
int ret = 0;
byte key[] = { some 16, 24,32 byte key };
if (ret = wc_AesGcmSetKey(&enc, key, sizeof(key)) != 0) {
// failed to set aes key
}
\endcode
\sa wc_AesGcmEncrypt
\sa wc_AesGcmDecrypt
*/
int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len);
/*!
\ingroup AES
\brief この関数は、入力メッセージをバッファINに保持し、結果の暗号テキストを出力バッファOUTに格納します。暗号化する呼び出しごとに新しいIV初期化ベクトルが必要です。また、入力認証ベクトル、Authin、AuthTagへの入力認証ベクトルをエンコードします。
\return 0 入力メッセージの暗号化に成功しました
\param aes - データの暗号化に使用されるAESオブジェクトへのポインタ
\param out 暗号テキストを保存する出力バッファへのポインタ
\param in 暗号化するメッセージを保持している入力バッファへのポインタ
\param sz 暗号化する入力メッセージの長さ
\param iv 初期化ベクトルを含むバッファへのポインタ
\param ivSz 初期化ベクトルの長さ
\param authTag 認証タグを保存するバッファへのポインタ
\param authTagSz 希望の認証タグの長さ
\param authIn 入力認証ベクトルを含むバッファへのポインタ
_Example_
\code
Aes enc;
// initialize aes structure by calling wc_AesGcmSetKey
byte plain[AES_BLOCK_LENGTH * n]; //n being a positive integer
making plain some multiple of 16 bytes
// initialize plain with msg to encrypt
byte cipher[sizeof(plain)];
byte iv[] = // some 16 byte iv
byte authTag[AUTH_TAG_LENGTH];
byte authIn[] = // Authentication Vector
wc_AesGcmEncrypt(&enc, cipher, plain, sizeof(cipher), iv, sizeof(iv),
authTag, sizeof(authTag), authIn, sizeof(authIn));
\endcode
\sa wc_AesGcmSetKey
\sa wc_AesGcmDecrypt
*/
int wc_AesGcmEncrypt(Aes* aes, byte* out,
const byte* in, word32 sz,
const byte* iv, word32 ivSz,
byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz);
/*!
\ingroup AES
\brief この関数は、入力暗号テキストをバッファINに保持し、結果のメッセージテキストを出力バッファOUTに格納します。また、指定された認証タグ、authtagに対して、入力認証ベクトル、Authinをチェックします。
\return 0 入力メッセージの復号化に成功しました
\return AES_GCM_AUTH_E 認証タグが提供された認証コードベクトルと一致しない場合、authtag。
\param aes データの暗号化に使用されるAESオブジェクトへのポインタ
\param out メッセージテキストを保存する出力バッファへのポインタ
\param in 暗号テキストを復号化する入力バッファへのポインタ
\param sz 復号化する暗号テキストの長さ
\param iv 初期化ベクトルを含むバッファへのポインタ
\param ivSz 初期化ベクトルの長さ
\param authTag 認証タグを含むバッファへのポインタ
\param authTagSz 希望の認証タグの長さ
\param authIn 入力認証ベクトルを含むバッファへのポインタ
_Example_
\code
Aes enc; //can use the same struct as was passed to wc_AesGcmEncrypt
// initialize aes structure by calling wc_AesGcmSetKey if not already done
byte cipher[AES_BLOCK_LENGTH * n]; //n being a positive integer
making cipher some multiple of 16 bytes
// initialize cipher with cipher text to decrypt
byte output[sizeof(cipher)];
byte iv[] = // some 16 byte iv
byte authTag[AUTH_TAG_LENGTH];
byte authIn[] = // Authentication Vector
wc_AesGcmDecrypt(&enc, output, cipher, sizeof(cipher), iv, sizeof(iv),
authTag, sizeof(authTag), authIn, sizeof(authIn));
\endcode
\sa wc_AesGcmSetKey
\sa wc_AesGcmEncrypt
*/
int wc_AesGcmDecrypt(Aes* aes, byte* out,
const byte* in, word32 sz,
const byte* iv, word32 ivSz,
const byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz);
/*!
\ingroup AES
\brief この関数は、GAROISメッセージ認証に使用されるGMACオブジェクトのキーを初期化して設定します。
\return 0 キーの設定に成功しました
\return BAD_FUNC_ARG キーの長さが無効な場合は返されます。
\param gmac 認証に使用されるGMACオブジェクトへのポインタ
\param key 認証のための16,24、または32バイトの秘密鍵
_Example_
\code
Gmac gmac;
key[] = { some 16, 24, or 32 byte length key };
wc_GmacSetKey(&gmac, key, sizeof(key));
\endcode
\sa wc_GmacUpdate
*/
int wc_GmacSetKey(Gmac* gmac, const byte* key, word32 len);
/*!
\ingroup AES
\brief この関数はAuthin InputのGMACハッシュを生成し、結果をAuthtagバッファに格納します。wc_gmacupdateを実行した後、生成されたauthtagを既知の認証タグに比較してメッセージの信頼性を検証する必要があります。
\return 0 GMACハッシュの計算に成功しました。
\param gmac 認証に使用されるGMACオブジェクトへのポインタ
\param iv ハッシュに使用される初期化ベクトル
\param ivSz 使用される初期化ベクトルのサイズ
\param authIn 確認する認証ベクトルを含むバッファへのポインタ
\param authInSz 認証ベクトルのサイズ
\param authTag GMACハッシュを保存する出力バッファへのポインタ
_Example_
\code
Gmac gmac;
key[] = { some 16, 24, or 32 byte length key };
iv[] = { some 16 byte length iv };
wc_GmacSetKey(&gmac, key, sizeof(key));
authIn[] = { some 16 byte authentication input };
tag[AES_BLOCK_SIZE]; // will store authentication code
wc_GmacUpdate(&gmac, iv, sizeof(iv), authIn, sizeof(authIn), tag,
sizeof(tag));
\endcode
\sa wc_GmacSetKey
*/
int wc_GmacUpdate(Gmac* gmac, const byte* iv, word32 ivSz,
const byte* authIn, word32 authInSz,
byte* authTag, word32 authTagSz);
/*!
\ingroup AES
\brief この関数は、CCMを使用してAESオブジェクトのキーを設定しますCBC-MACのカウンタ。AES構造体へのポインタを取り、付属のキーで初期化します。
\return none
\param aes 付属のキーを保管するためのAES構造
\param key 暗号化と復号化のための16,24、または32バイトの秘密鍵
_Example_
\code
Aes enc;
key[] = { some 16, 24, or 32 byte length key };
wc_AesCcmSetKey(&aes, key, sizeof(key));
\endcode
\sa wc_AesCcmEncrypt
\sa wc_AesCcmDecrypt
*/
int wc_AesCcmSetKey(Aes* aes, const byte* key, word32 keySz);
/*!
\ingroup AES
\brief この関数は、CCMを使用して、入力メッセージ、IN、OUT、OUT、OUTをCCMCBC-MACのカウンタを暗号化します。その後、Authin Inputから認証タグ、AuthtAgを計算して格納します。
\return none
\param aes データの暗号化に使用されるAESオブジェクトへのポインタ
\param out 暗号テキストを保存する出力バッファへのポインタ
\param in 暗号化するメッセージを保持している入力バッファへのポインタ
\param sz 暗号化する入力メッセージの長さ
\param nonce nonceを含むバッファへのポインタ1回だけ使用されている数
\param nonceSz ノンスの長さ
\param authTag 認証タグを保存するバッファへのポインタ
\param authTagSz 希望の認証タグの長さ
\param authIn 入力認証ベクトルを含むバッファへのポインタ
_Example_
\code
Aes enc;
// initialize enc with wc_AesCcmSetKey
nonce[] = { initialize nonce };
plain[] = { some plain text message };
cipher[sizeof(plain)];
authIn[] = { some 16 byte authentication input };
tag[AES_BLOCK_SIZE]; // will store authentication code
wc_AesCcmEncrypt(&enc, cipher, plain, sizeof(plain), nonce, sizeof(nonce),
tag, sizeof(tag), authIn, sizeof(authIn));
\endcode
\sa wc_AesCcmSetKey
\sa wc_AesCcmDecrypt
*/
int wc_AesCcmEncrypt(Aes* aes, byte* out,
const byte* in, word32 inSz,
const byte* nonce, word32 nonceSz,
byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz);
/*!
\ingroup AES
\brief この関数は、CCMを使用して、入力暗号テキストを、CCMCBC-MACのカウンタを使用して出力バッファーに復号化します。その後、Authin InputからAuthatAg、AuthatAgを計算します。許可タグが無効な場合は、出力バッファをゼロに設定し、AES_CCM_AUTH_Eを返します。
\return 0 入力メッセージの復号化に成功しました
\return AES_CCM_AUTH_E 認証タグが提供された認証コードベクトルと一致しない場合、authtag。
\param aes データの暗号化に使用されるAESオブジェクトへのポインタ
\param out 暗号テキストを保存する出力バッファへのポインタ
\param in 暗号化するメッセージを保持している入力バッファへのポインタ
\param sz 入力暗号テキストの復号化
\param nonce nonceを含むバッファへのポインタ1回だけ使用されている数
\param nonceSz ノンスの長さ
\param authTag 認証タグを保存するバッファへのポインタ
\param authTagSz 希望の認証タグの長さ
\param authIn 入力認証ベクトルを含むバッファへのポインタ
_Example_
\code
Aes dec;
// initialize dec with wc_AesCcmSetKey
nonce[] = { initialize nonce };
cipher[] = { encrypted message };
plain[sizeof(cipher)];
authIn[] = { some 16 byte authentication input };
tag[AES_BLOCK_SIZE] = { authentication tag received for verification };
int return = wc_AesCcmDecrypt(&dec, plain, cipher, sizeof(cipher),
nonce, sizeof(nonce),tag, sizeof(tag), authIn, sizeof(authIn));
if(return != 0) {
// decrypt error, invalid authentication code
}
\endcode
\sa wc_AesCcmSetKey
\sa wc_AesCcmEncrypt
*/
int wc_AesCcmDecrypt(Aes* aes, byte* out,
const byte* in, word32 inSz,
const byte* nonce, word32 nonceSz,
const byte* authTag, word32 authTagSz,
const byte* authIn, word32 authInSz);
/*!
\ingroup AES
\brief これは、暗号化または復号化タイプを修正するためのキーの設定を支援することです。完了したら、AESキーでWC_AESXTSFREEを呼び出すことがユーザーになりました。
\return 0 成功
\param aes ENCRYPT /復号化プロセスのためのAESキー
\param key AESキーを保持しているバッファー| ..Tweak Key
\param len キーバッファのバイト数の長さ。キーサイズの2倍にする必要があります。すなわち、16バイトのキーについて。
\param dir 方向、AES_EncryptionまたはAES_Decryptionのいずれか
\param heap メモリに使用するヒントヒント。nullになることができます
_Example_
\code
XtsAes aes;
if(wc_AesXtsSetKey(&aes, key, sizeof(key), AES_ENCRYPTION, NULL, 0) != 0)
{
// Handle error
}
wc_AesXtsFree(&aes);
\endcode
\sa wc_AesXtsEncrypt
\sa wc_AesXtsDecrypt
\sa wc_AesXtsFree
*/
int wc_AesXtsSetKey(XtsAes* aes, const byte* key,
word32 len, int dir, void* heap, int devId);
/*!
\ingroup AES
\brief WC_AESXTSENCRYPTと同じプロセスですが、バイト配列の代わりにTweak値としてWord64型を使用します。これは、Word64をバイト配列に変換し、WC_AESXTSENCRYPTを呼び出します。
\return 0 成功
\param aes ブロック暗号化/復号化に使用するAESキー
\param out 暗号テキストを保持するための出力バッファ
\param in 暗号化する入力プレーンテキストバッファ
\param sz 両方ともバッファのサイズ
_Example_
\code
XtsAes aes;
unsigned char plain[SIZE];
unsigned char cipher[SIZE];
word64 s = VALUE;
//set up keys with AES_ENCRYPTION as dir
if(wc_AesXtsEncryptSector(&aes, cipher, plain, SIZE, s) != 0)
{
// Handle error
}
wc_AesXtsFree(&aes);
\endcode
\sa wc_AesXtsEncrypt
\sa wc_AesXtsDecrypt
\sa wc_AesXtsSetKey
\sa wc_AesXtsFree
*/
int wc_AesXtsEncryptSector(XtsAes* aes, byte* out,
const byte* in, word32 sz, word64 sector);
/*!
\ingroup AES
\brief WC_AESXTSDECRYPTと同じプロセスではなく、BYTE配列の代わりにWord64タイプを使用します。これはWord64をバイト配列に変換するだけです。
\return 0 成功
\param aes ブロック暗号化/復号化に使用するAESキー
\param out プレーンテキストを保持するための出力バッファ
\param in 復号化する暗号テキストバッファーを入力します
\param sz 両方ともバッファのサイズ
_Example_
\code
XtsAes aes;
unsigned char plain[SIZE];
unsigned char cipher[SIZE];
word64 s = VALUE;
//set up aes key with AES_DECRYPTION as dir and tweak with AES_ENCRYPTION
if(wc_AesXtsDecryptSector(&aes, plain, cipher, SIZE, s) != 0)
{
// Handle error
}
wc_AesXtsFree(&aes);
\endcode
\sa wc_AesXtsEncrypt
\sa wc_AesXtsDecrypt
\sa wc_AesXtsSetKey
\sa wc_AesXtsFree
*/
int wc_AesXtsDecryptSector(XtsAes* aes, byte* out,
const byte* in, word32 sz, word64 sector);
/*!
\ingroup AES
\brief XTSモードのあるAES。XTSXEX暗号化と暗号テキストを盗んだ暗号化。
\return 0 成功
\param aes ブロック暗号化/復号化に使用するAESキー
\param out 暗号テキストを保持するための出力バッファ
\param in 暗号化する入力プレーンテキストバッファ
\param sz 両方ともバッファのサイズ
\param i Tweakに使用する値
_Example_
\code
XtsAes aes;
unsigned char plain[SIZE];
unsigned char cipher[SIZE];
unsigned char i[AES_BLOCK_SIZE];
//set up key with AES_ENCRYPTION as dir
if(wc_AesXtsEncrypt(&aes, cipher, plain, SIZE, i, sizeof(i)) != 0)
{
// Handle error
}
wc_AesXtsFree(&aes);
\endcode
\sa wc_AesXtsDecrypt
\sa wc_AesXtsSetKey
\sa wc_AesXtsFree
*/
int wc_AesXtsEncrypt(XtsAes* aes, byte* out,
const byte* in, word32 sz, const byte* i, word32 iSz);
/*!
\ingroup AES
\brief 暗号化と同じプロセスですが、AESキーはAES_Decryptionタイプです。
\return 0 成功
\param aes ブロック暗号化/復号化に使用するAESキー
\param out プレーンテキストを保持するための出力バッファ
\param in 復号化する暗号テキストバッファーを入力します
\param sz 両方ともバッファのサイズ
\param i Tweakに使用する値
_Example_
\code
XtsAes aes;
unsigned char plain[SIZE];
unsigned char cipher[SIZE];
unsigned char i[AES_BLOCK_SIZE];
//set up key with AES_DECRYPTION as dir and tweak with AES_ENCRYPTION
if(wc_AesXtsDecrypt(&aes, plain, cipher, SIZE, i, sizeof(i)) != 0)
{
// Handle error
}
wc_AesXtsFree(&aes);
\endcode
\sa wc_AesXtsEncrypt
\sa wc_AesXtsSetKey
\sa wc_AesXtsFree
*/
int wc_AesXtsDecrypt(XtsAes* aes, byte* out,
const byte* in, word32 sz, const byte* i, word32 iSz);
/*!
\ingroup AES
\brief これはXTSAES構造によって使用されるすべてのリソースを解放することです
\return 0 成功
_Example_
\code
XtsAes aes;
if(wc_AesXtsSetKey(&aes, key, sizeof(key), AES_ENCRYPTION, NULL, 0) != 0)
{
// Handle error
}
wc_AesXtsFree(&aes);
\endcode
\sa wc_AesXtsEncrypt
\sa wc_AesXtsDecrypt
\sa wc_AesXtsSetKey
*/
int wc_AesXtsFree(XtsAes* aes);
/*!
\ingroup AES
\brief AES構造を初期化します。ASYNCハードウェアで使用するためのヒープヒントとIDを設定する
\return 0 成功
\param aes 初期化にはAES構造
\param heap 必要に応じてmalloc / freeに使用するヒントヒント
_Example_
\code
Aes enc;
void* hint = NULL;
int devId = INVALID_DEVID; //if not using async INVALID_DEVID is default
//heap hint could be set here if used
wc_AesInit(&aes, hint, devId);
\endcode
\sa wc_AesSetKey
\sa wc_AesSetIV
*/
int wc_AesInit(Aes* aes, void* heap, int devId);
/*!
\ingroup AES
\brief CFBモードを持つAES。
\return 0 失敗時の成功と否定的なエラー値
\param aes ブロック暗号化/復号化に使用するAESキー
\param out 暗号テキストを保持するための出力バッファは、少なくともInpectBufferと同じくらい大きい必要があります
\param in 暗号化する入力プレーンテキストバッファ
_Example_
\code
Aes aes;
unsigned char plain[SIZE];
unsigned char cipher[SIZE];
//set up key with AES_ENCRYPTION as dir for both encrypt and decrypt
if(wc_AesCfbEncrypt(&aes, cipher, plain, SIZE) != 0)
{
// Handle error
}
\endcode
\sa wc_AesCfbDecrypt
\sa wc_AesSetKey
*/
int wc_AesCfbEncrypt(Aes* aes, byte* out, const byte* in, word32 sz);
/*!
\ingroup AES
\brief CFBモードを持つAES。
\return 0 失敗時の成功と否定的なエラー値
\param aes ブロック暗号化/復号化に使用するAESキー
\param out 復号化されたテキストを保持するための出力バッファは、少なくともinputBufferと同じ大きさでなければなりません
\param in 復号化する入力バッファ
_Example_
\code
Aes aes;
unsigned char plain[SIZE];
unsigned char cipher[SIZE];
//set up key with AES_ENCRYPTION as dir for both encrypt and decrypt
if(wc_AesCfbDecrypt(&aes, plain, cipher, SIZE) != 0)
{
// Handle error
}
\endcode
\sa wc_AesCfbEncrypt
\sa wc_AesSetKey
*/
int wc_AesCfbDecrypt(Aes* aes, byte* out, const byte* in, word32 sz);
/*!
\ingroup AES
\brief この関数は、RFC 5297に記載されているようにSIV合成初期化ベクトル暗号化を実行します。
\return 0 暗号化に成功した場合
\return BAD_FUNC_ARG キー、SIV、または出力バッファがNULLの場合。キーサイズが32,48、または64バイトの場合にも返されます。
\return Other AESまたはCMAC操作が失敗した場合に返されるその他の負のエラー値。
\param key 使用する鍵を含むバイトバッファ。
\param keySz キーバッファの長さ(バイト単位)。
\param assoc 追加の認証された関連データAD
\param assocSz ADバッファのバイト数
\param nonce 一度使用される数。ADと同じ方法でアルゴリズムによって使用されます。
\param nonceSz バイト単位のNOCEバッファの長さ。
\param in 暗号化する平文のバッファ。
\param inSz 平文バッファの長さ
\param siv S2VによるSIV出力RFC 5297 2.4参照)。
_Example_
\code
byte key[] = { some 32, 48, or 64 byte key };
byte assoc[] = {0x01, 0x2, 0x3};
byte nonce[] = {0x04, 0x5, 0x6};
byte plainText[] = {0xDE, 0xAD, 0xBE, 0xEF};
byte siv[AES_BLOCK_SIZE];
byte cipherText[sizeof(plainText)];
if (wc_AesSivEncrypt(key, sizeof(key), assoc, sizeof(assoc), nonce,
sizeof(nonce), plainText, sizeof(plainText), siv, cipherText) != 0) {
// failed to encrypt
}
\endcode
\sa wc_AesSivDecrypt
*/
int wc_AesSivEncrypt(const byte* key, word32 keySz, const byte* assoc,
word32 assocSz, const byte* nonce, word32 nonceSz,
const byte* in, word32 inSz, byte* siv, byte* out);
/*!
\ingroup AES
\brief この機能は、RFC 5297に記載されているようにSIV合成初期化ベクトル復号化を実行する。
\return 0 復号化に成功した場合
\return BAD_FUNC_ARG キー、SIV、または出力バッファがNULLの場合。キーサイズが32,48、または64バイトの場合にも返されます。
\return AES_SIV_AUTH_E S2Vによって派生したSIVが入力SIVと一致しない場合RFC 5297 2.7を参照)。
\return Other AESまたはCMAC操作が失敗した場合に返されるその他の負のエラー値。
\param key 使用する鍵を含むバイトバッファ。
\param keySz キーバッファの長さ(バイト単位)。
\param assoc 追加の認証された関連データAD
\param assocSz ADバッファのバイト数
\param nonce 一度使用される数。ADと同じ方法で、基礎となるアルゴリズムによって使用されます。
\param nonceSz バイト単位のNOCEバッファの長さ。
\param in 復号化する暗号文バッファー。
\param inSz 暗号文バッファの長さ
\param siv 暗号文に付随するSIVRFC 5297 2.4を参照)。
_Example_
\code
byte key[] = { some 32, 48, or 64 byte key };
byte assoc[] = {0x01, 0x2, 0x3};
byte nonce[] = {0x04, 0x5, 0x6};
byte cipherText[] = {0xDE, 0xAD, 0xBE, 0xEF};
byte siv[AES_BLOCK_SIZE] = { the SIV that came with the ciphertext };
byte plainText[sizeof(cipherText)];
if (wc_AesSivDecrypt(key, sizeof(key), assoc, sizeof(assoc), nonce,
sizeof(nonce), cipherText, sizeof(cipherText), siv, plainText) != 0) {
// failed to decrypt
}
\endcode
\sa wc_AesSivEncrypt
*/
int wc_AesSivDecrypt(const byte* key, word32 keySz, const byte* assoc,
word32 assocSz, const byte* nonce, word32 nonceSz,
const byte* in, word32 inSz, byte* siv, byte* out);

View File

@@ -0,0 +1,40 @@
/*!
\ingroup ARC4
\brief この関数は、バッファ内の入力メッセージを暗号化し、出力バッファーに暗号文を配置するか、またはバッファーから暗号文を復号化したり、ARC4暗号化を使用して、出力バッファーOUTを出力したりします。この関数は暗号化と復号化の両方に使用されます。この方法が呼び出される可能性がある場合は、まずWC_ARC4SETKEYを使用してARC4構造を初期化する必要があります。
\return none
\param arc4 メッセージの処理に使用されるARC4構造へのポインタ
\param out 処理されたメッセージを保存する出力バッファへのポインタ
\param in プロセスするメッセージを含む入力バッファへのポインタ
_Example_
\code
Arc4 enc;
byte key[] = { key to use for encryption };
wc_Arc4SetKey(&enc, key, sizeof(key));
byte plain[] = { plain text to encode };
byte cipher[sizeof(plain)];
byte decrypted[sizeof(plain)];
// encrypt the plain into cipher
wc_Arc4Process(&enc, cipher, plain, sizeof(plain));
// decrypt the cipher
wc_Arc4Process(&enc, decrypted, cipher, sizeof(cipher));
\endcode
\sa wc_Arc4SetKey
*/
int wc_Arc4Process(Arc4* arc4, byte* out, const byte* in, word32 length);
/*!
\ingroup ARC4
\brief この関数はARC4オブジェクトのキーを設定し、それを暗号として使用するために初期化します。WC_ARC4PROCESSを使用した暗号化に使用する前に呼び出される必要があります。
\return none
\param arc4 暗号化に使用されるARC4構造へのポインタ
\param key ARC4構造を初期化するためのキー
_Example_
\code
Arc4 enc;
byte key[] = { initialize with key to use for encryption };
wc_Arc4SetKey(&enc, key, sizeof(key));
\endcode
\sa wc_Arc4Process
*/
int wc_Arc4SetKey(Arc4* arc4, const byte* key, word32 length);

View File

@@ -0,0 +1,143 @@
/*!
\ingroup ASN
\brief この関数はデフォルトの証明書を初期化します。デフォルトのオプションversion = 30x2、sigtype = sha_with_rsa、issuer =空白、dayValid = 500、selfsigned = 1true発行者としての件名=空白
\return none いいえ返します。
_Example_
\code
Cert myCert;
wc_InitCert(&myCert);
\endcode
\sa wc_MakeCert
\sa wc_MakeCertReq
*/
int wc_InitCert(Cert*);
/*!
\ingroup ASN
\brief CA署名付き証明書を作成するために使用されます。被写体情報が入力された後に呼び出されました。この関数は、証明書入力からX509証明書V3 RSAまたはECCを作成します。その後、この証明書をDerbufferに書き込みます。証明書を生成するためのRSAKEYまたはECCKEYのいずれかを取ります。このメソッドが呼び出される前に、証明書をWC_INITCERTで初期化する必要があります。
\return Success 指定された入力証明書からX509証明書を正常に行うと、生成された証明書のサイズを返します。
\return MEMORY_E xmallocでメモリを割り当てるエラーがある場合
\return BUFFER_E 提供されたDerbufferが生成された証明書を保存するには小さすぎる場合に返されます
\return Others 証明書の生成が成功しなかった場合、追加のエラーメッセージが返される可能性があります。
\param cert 初期化された証明書構造へのポインタ
\param derBuffer 生成された証明書を保持するバッファへのポインタ
\param derSz 証明書を保存するバッファのサイズ
\param rsaKey 証明書の生成に使用されるRSAキーを含むRSAKEY構造体へのポインタ
\param eccKey 証明書の生成に使用されるECCキーを含むECCKEY構造体へのポインタ
_Example_
\code
Cert myCert;
wc_InitCert(&myCert);
WC_RNG rng;
//initialize rng;
RsaKey key;
//initialize key;
byte * derCert = malloc(FOURK_BUF);
word32 certSz;
certSz = wc_MakeCert(&myCert, derCert, FOURK_BUF, &key, NULL, &rng);
\endcode
\sa wc_InitCert
\sa wc_MakeCertReq
*/
int wc_MakeCert(Cert* cert, byte* derBuffer, word32 derSz, RsaKey* rsaKey,
ecc_key* eccKey, WC_RNG* rng);
/*!
\ingroup ASN
\brief この関数は、入力証明書を使用して証明書署名要求を行い、出力をDerbufferに書き込みます。証明書要求を生成するRSAKEYまたはECCKEYのどちらかを取ります。この関数が証明書要求に署名するためにwc_signcertを呼び出す必要があります。この関数の使用例については、WolfCryptテストアプリケーション./wolfcrypt/test/test.cを参照してください。
\return Success 指定された入力証明書からX.509証明書要求を正常に行うと、生成された証明書要求のサイズを返します。
\return MEMORY_E xmallocでメモリを割り当てるエラーがある場合
\return BUFFER_E 提供されたDerbufferが生成された証明書を保存するには小さすぎる場合に返されます
\return Other 証明書要求生成が成功しなかった場合、追加のエラーメッセージが返される可能性があります。
\param cert 初期化された証明書構造へのポインタ
\param derBuffer 生成された証明書要求を保持するバッファへのポインタ
\param derSz 証明書要求を保存するバッファのサイズ
\param rsaKey 証明書要求を生成するために使用されるRSAキーを含むRSAKEY構造体へのポインタ
_Example_
\code
Cert myCert;
// initialize myCert
EccKey key;
//initialize key;
byte* derCert = (byte*)malloc(FOURK_BUF);
word32 certSz;
certSz = wc_MakeCertReq(&myCert, derCert, FOURK_BUF, NULL, &key);
\endcode
\sa wc_InitCert
\sa wc_MakeCert
*/
int wc_MakeCertReq(Cert* cert, byte* derBuffer, word32 derSz,
RsaKey* rsaKey, ecc_key* eccKey);
/*!
\ingroup ASN
\brief この関数はバッファーに署名し、署名をバッファの最後に追加します。署名の種類を取ります。CA署名付き証明書を作成する場合は、wc_makecertまたはwc_makecertreqの後に呼び出す必要があります。
\return Success 証明書に正常に署名する場合は、CERTの新しいサイズ署名を含むを返します。
\return MEMORY_E xmallocでメモリを割り当てるエラーがある場合
\return BUFFER_E 提供された証明書を保存するには提供されたバッファが小さすぎる場合に返されます。
\return Other 証明書の生成が成功しなかった場合、追加のエラーメッセージが返される可能性があります。
\param requestSz 署名したことを要求している証明書本文のサイズ
\param sType 作成する署名の種類。有効なオプションは次のとおりです.CTC_MD5WRSA、CTC_SHAWRSA、CTC_SHAWECDSA、CTC_SHA256WECDSA、ANDCTC_SHA256WRSA
\param buffer 署名する証明書を含むバッファへのポインタ。成功:新たに署名された証明書を保持します
\param buffSz 新たに署名された証明書を保存するバッファの(合計)サイズ
\param rsaKey 証明書に署名するために使用されるRSAキーを含むRSAKEY構造体へのポインタ
\param eccKey 証明書に署名するために使用されるECCキーを含むECCKey構造体へのポインタ
_Example_
\code
Cert myCert;
byte* derCert = (byte*)malloc(FOURK_BUF);
// initialize myCert, derCert
RsaKey key;
// initialize key;
WC_RNG rng;
// initialize rng
word32 certSz;
certSz = wc_SignCert(myCert.bodySz, myCert.sigType,derCert,FOURK_BUF,
&key, NULL,
&rng);
\endcode
\sa wc_InitCert
\sa wc_MakeCert
*/
int wc_SignCert(int requestSz, int sigType, byte* derBuffer,
word32 derSz, RsaKey* rsaKey, ecc_key* eccKey, WC_RNG* rng);
/*!
\ingroup ASN
\brief この関数は、以前の2つの関数、wc_makecert、および自己署名のためのwc_signcertの組み合わせです前の関数はCA要求に使用される場合があります。証明書を作成してから、それに署名し、自己署名証明書を生成します。
\return Success 証明書に正常に署名する場合は、CERTの新しいサイズを返します。
\return MEMORY_E xmallocでメモリを割り当てるエラーがある場合
\return BUFFER_E 提供された証明書を保存するには提供されたバッファが小さすぎる場合に返されます。
\return Other 証明書の生成が成功しなかった場合、追加のエラーメッセージが返される可能性があります。
\param cert 作成して署名する証明書へのポインタ
\param buffer 署名付き証明書を保持するためのバッファへのポインタ
\param buffSz 署名付き証明書を保存するバッファのサイズ
\param key 証明書に署名するために使用されるRSAキーを含むRSAKEY構造体へのポインタ
_Example_
\code
Cert myCert;
byte* derCert = (byte*)malloc(FOURK_BUF);
// initialize myCert, derCert
RsaKey key;
// initialize key;
WC_RNG rng;
// initialize rng
word32 certSz;
certSz = wc_MakeSelfCert(&myCert, derCert, FOURK_BUF, &key, NULL, &rng);
\endcode
\sa wc_InitCert
\sa wc_MakeCert
\sa wc_SignCert
*/
int wc_MakeSelfCert(Cert* cert, byte* derBuffer, word32 derSz, RsaKey* key,
WC_RNG* rng);
/*!
\ingroup ASN
\brief この関数は、提供されたPEM ISSUERFILE内の証明書の発行者を発行者に設定します。また、証明書の自己署名属性をfalseに変更します。ISSUERFILEで指定された発行者は、CERT発行者を設定する前に確認されます。このメソッドは、署名の前にフィールドを設定するために使用されます。
\return 0 証明書の発行者を正常に設定した
\return MEMORY_E xmallocでメモリを割り当てるエラーがある場合
\return ASN_PARSE_E CERTヘッダーファイルの解析中にエラーがある場合は返されます。

View File

@@ -0,0 +1,66 @@
/*!
\ingroup BLAKE2
\brief この関数はBlake2 Hash関数で使用するためのBlake2b構造を初期化します。
\return 0 Blake2B構造の初期化に成功し、ダイジェストサイズを設定したときに返されます。
\param b2b 初期化するためにBlake2b構造へのポインタ
_Example_
\code
Blake2b b2b;
// initialize Blake2b structure with 64 byte digest
wc_InitBlake2b(&b2b, 64);
\endcode
\sa wc_Blake2bUpdate
*/
int wc_InitBlake2b(Blake2b* b2b, word32 digestSz);
/*!
\ingroup BLAKE2
\brief この関数は、与えられた入力データとBlake2Bハッシュを更新します。この関数は、wc_initblake2bの後に呼び出され、最後のハッシュwc_blake2bfinalの準備ができているまで繰り返します。
\return 0 与えられたデータを使用してBlake2B構造を正常に更新すると返されます。
\return -1 入力データの圧縮中に障害が発生した場合
\param b2b 更新するBlake2b構造へのポインタ
\param data 追加するデータを含むバッファへのポインタ
_Example_
\code
int ret;
Blake2b b2b;
// initialize Blake2b structure with 64 byte digest
wc_InitBlake2b(&b2b, 64);
byte plain[] = { // initialize input };
ret = wc_Blake2bUpdate(&b2b, plain, sizeof(plain));
if( ret != 0) {
// error updating blake2b
}
\endcode
\sa wc_InitBlake2b
\sa wc_Blake2bFinal
*/
int wc_Blake2bUpdate(Blake2b* b2b, const byte* data, word32 sz);
/*!
\ingroup BLAKE2
\brief この関数は、以前に供給された入力データのBlake2bハッシュを計算します。出力ハッシュは長さREQUESTSZ、あるいは要求された場合はB2B構造のDigestSZを使用します。この関数は、wc_initblake2bの後に呼び出され、wc_blake2bupdateは必要な各入力データに対して処理されています。
\return 0 Blake2B Hashの計算に成功したときに返されました
\return -1 blake2bハッシュを解析している間に失敗がある場合
\param b2b 更新するBlake2b構造へのポインタ
\param final Blake2Bハッシュを保存するバッファへのポインタ。長さrequestszにする必要があります
_Example_
\code
int ret;
Blake2b b2b;
byte hash[64];
// initialize Blake2b structure with 64 byte digest
wc_InitBlake2b(&b2b, 64);
... // call wc_Blake2bUpdate to add data to hash
ret = wc_Blake2bFinal(&b2b, hash, 64);
if( ret != 0) {
// error generating blake2b hash
}
\endcode
\sa wc_InitBlake2b
\sa wc_Blake2bUpdate
*/
int wc_Blake2bFinal(Blake2b* b2b, byte* final, word32 requestSz);

View File

@@ -0,0 +1,22 @@
/*!
\ingroup openSSL
\brief この関数は、次の数学「R =A ^ PM」を実行します。
\return SSL_SUCCESS 数学操作をうまく実行します。
\return SSL_FAILURE エラーケースに遭遇した場合
\param r 結果を保持するための構造。
\param a 電力で上げられる値。
\param p によって上げる力。
\param m 使用率
_Example_
\code
WOLFSSL_BIGNUM r,a,p,m;
int ret;
// set big number values
ret = wolfSSL_BN_mod_exp(r, a, p, m, NULL);
// check ret value
\endcode
\sa wolfSSL_BN_new
\sa wolfSSL_BN_free
*/
int wolfSSL_BN_mod_exp(WOLFSSL_BIGNUM *r, const WOLFSSL_BIGNUM *a,
const WOLFSSL_BIGNUM *p, const WOLFSSL_BIGNUM *m, WOLFSSL_BN_CTX *ctx);

View File

@@ -0,0 +1,128 @@
/*!
\ingroup Camellia
\brief この関数は、Camelliaオブジェクトのキーと初期化ベクトルを設定し、それを暗号として使用するために初期化します。
\return 0 キーと初期化ベクトルを正常に設定すると返されます
\return BAD_FUNC_ARG 入力引数の1つがエラー処理がある場合に返されます
\return MEMORY_E xmallocでメモリを割り当てるエラーがある場合
\param cam キーとIVを設定する椿構造へのポインタ
\param key 暗号化と復号化に使用する16,24、または32バイトのキーを含むバッファへのポインタ
\param len 渡されたキーの長さ
_Example_
\code
Camellia cam;
byte key[32];
// initialize key
byte iv[16];
// initialize iv
if( wc_CamelliaSetKey(&cam, key, sizeof(key), iv) != 0) {
// error initializing camellia structure
}
\endcode
\sa wc_CamelliaEncryptDirect
\sa wc_CamelliaDecryptDirect
\sa wc_CamelliaCbcEncrypt
\sa wc_CamelliaCbcDecrypt
*/
int wc_CamelliaSetKey(Camellia* cam,
const byte* key, word32 len, const byte* iv);
/*!
\ingroup Camellia
\brief この関数は、Camelliaオブジェクトの初期化ベクトルを設定します。
\return 0 キーと初期化ベクトルを正常に設定すると返されます
\return BAD_FUNC_ARG 入力引数の1つがエラー処理がある場合に返されます
\param cam IVを設定する椿構造へのポインタ
_Example_
\code
Camellia cam;
byte iv[16];
// initialize iv
if( wc_CamelliaSetIV(&cam, iv) != 0) {
// error initializing camellia structure
}
\endcode
\sa wc_CamelliaSetKey
*/
int wc_CamelliaSetIV(Camellia* cam, const byte* iv);
/*!
\ingroup Camellia
\brief この機能は、提供されたCamelliaオブジェクトを使用して1ブロック暗号化します。それはバッファーの最初の16バイトブロックを解析し、暗号化結果をバッファアウトに格納します。この機能を使用する前に、WC_CAMELLIASETKEYを使用してCamelliaオブジェクトを初期化する必要があります。
\return none いいえ返します。
\param cam 暗号化に使用する椿構造へのポインタ
\param out 暗号化されたブロックを保存するバッファへのポインタ
_Example_
\code
Camellia cam;
// initialize cam structure with key and iv
byte plain[] = { // initialize with message to encrypt };
byte cipher[16];
wc_CamelliaEncryptDirect(&ca, cipher, plain);
\endcode
\sa wc_CamelliaDecryptDirect
*/
int wc_CamelliaEncryptDirect(Camellia* cam, byte* out,
const byte* in);
/*!
\ingroup Camellia
\brief この機能は、提供されたCamelliaオブジェクトを使用して1ブロック復号化します。それはバッファ内の最初の16バイトブロックを解析し、それを復号化し、結果をバッファアウトに格納します。この機能を使用する前に、WC_CAMELLIASETKEYを使用してCamelliaオブジェクトを初期化する必要があります。
\return none いいえ返します。
\param cam 暗号化に使用する椿構造へのポインタ
\param out 復号化された平文ブロックを保存するバッファへのポインタ
_Example_
\code
Camellia cam;
// initialize cam structure with key and iv
byte cipher[] = { // initialize with encrypted message to decrypt };
byte decrypted[16];
wc_CamelliaDecryptDirect(&cam, decrypted, cipher);
\endcode
\sa wc_CamelliaEncryptDirect
*/
int wc_CamelliaDecryptDirect(Camellia* cam, byte* out,
const byte* in);
/*!
\ingroup Camellia
\brief この関数は、バッファーの平文を暗号化し、その出力をバッファOUTに格納します。暗号ブロックチェーンCBCを使用してCamelliaを使用してこの暗号化を実行します。
\return none いいえ返します。
\param cam 暗号化に使用する椿構造へのポインタ
\param out 暗号化された暗号文を保存するバッファへのポインタ
\param in 暗号化する平文を含むバッファへのポインタ
_Example_
\code
Camellia cam;
// initialize cam structure with key and iv
byte plain[] = { // initialize with encrypted message to decrypt };
byte cipher[sizeof(plain)];
wc_CamelliaCbcEncrypt(&cam, cipher, plain, sizeof(plain));
\endcode
\sa wc_CamelliaCbcDecrypt
*/
int wc_CamelliaCbcEncrypt(Camellia* cam,
byte* out, const byte* in, word32 sz);
/*!
\ingroup Camellia
\brief この関数は、バッファ内の暗号文を復号化し、その出力をバッファOUTに格納します。暗号ブロックチェーンCBCを搭載したCamelliaを使用してこの復号化を実行します。
\return none いいえ返します。
\param cam 暗号化に使用する椿構造へのポインタ
\param out 復号化されたメッセージを保存するバッファへのポインタ
\param in 暗号化された暗号文を含むバッファへのポインタ
_Example_
\code
Camellia cam;
// initialize cam structure with key and iv
byte cipher[] = { // initialize with encrypted message to decrypt };
byte decrypted[sizeof(cipher)];
wc_CamelliaCbcDecrypt(&cam, decrypted, cipher, sizeof(cipher));
\endcode
\sa wc_CamelliaCbcEncrypt
*/
int wc_CamelliaCbcDecrypt(Camellia* cam,
byte* out, const byte* in, word32 sz);

View File

@@ -0,0 +1,67 @@
/*!
\ingroup ChaCha
\brief この関数はChachaオブジェクトの初期化ベクトルnonceを設定し、暗号として使用するために初期化します。WC_CHACHA_SETKEYを使用して、キーが設定された後に呼び出されるべきです。暗号化の各ラウンドに差し違いを使用する必要があります。
\return 0 初期化ベクトルを正常に設定すると返されます
\return BAD_FUNC_ARG CTX入力引数の処理中にエラーが発生した場合
\param ctx IVを設定するChacha構造へのポインタ
\param inIv Chacha構造を初期化するための12バイトの初期化ベクトルを含むバッファへのポインタ
_Example_
\code
ChaCha enc;
// initialize enc with wc_Chacha_SetKey
byte iv[12];
// initialize iv
if( wc_Chacha_SetIV(&enc, iv, 0) != 0) {
// error initializing ChaCha structure
}
\endcode
\sa wc_Chacha_SetKey
\sa wc_Chacha_Process
*/
int wc_Chacha_SetIV(ChaCha* ctx, const byte* inIv, word32 counter);
/*!
\ingroup ChaCha
\brief この関数は、バッファ入力からテキストを処理し、暗号化または復号化し、結果をバッファ出力に格納します。
\return 0 入力の暗号化または復号化に成功したときに返されます
\return BAD_FUNC_ARG CTX入力引数の処理中にエラーが発生した場合
\param ctx IVを設定するChacha構造へのポインタ
\param output 出力暗号文または復号化された平文を保存するバッファへのポインタ
\param input 暗号化する入力平文を含むバッファへのポインタまたは復号化する入力暗号文
_Example_
\code
ChaCha enc;
// initialize enc with wc_Chacha_SetKey and wc_Chacha_SetIV
byte plain[] = { // initialize plaintext };
byte cipher[sizeof(plain)];
if( wc_Chacha_Process(&enc, cipher, plain, sizeof(plain)) != 0) {
// error processing ChaCha cipher
}
\endcode
\sa wc_Chacha_SetKey
\sa wc_Chacha_Process
*/
int wc_Chacha_Process(ChaCha* ctx, byte* cipher, const byte* plain,
word32 msglen);
/*!
\ingroup ChaCha
\brief この関数はChachaオブジェクトのキーを設定し、それを暗号として使用するために初期化します。NONCEをWC_CHACHA_SETIVで設定する前に、WC_CHACHA_PROCESSを使用した暗号化に使用する前に呼び出す必要があります。
\return 0 キーの設定に成功したときに返されます
\return BAD_FUNC_ARG CTX入力引数の処理中にエラーが発生した場合、またはキーが16または32バイトの長さがある場合
\param ctx キーを設定するChacha構造へのポインタ
\param key Chacha構造を初期化するための16または32バイトのキーを含むバッファへのポインタ
_Example_
\code
ChaCha enc;
byte key[] = { // initialize key };
if( wc_Chacha_SetKey(&enc, key, sizeof(key)) != 0) {
// error initializing ChaCha structure
}
\endcode
\sa wc_Chacha_SetIV
\sa wc_Chacha_Process
*/
int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz);

View File

@@ -0,0 +1,87 @@
/*!
\ingroup ChaCha20Poly1305
\brief この関数は、Chacha20 Stream暗号を使用して、Chacha20 Stream暗号を使用して、Output BufferTextに入力メッセージ、InPleaintextを暗号化します。また、Poly-1305認証暗号テキストを実行し、生成した認証タグを出力バッファOutauthTagに格納します。
\return 0 メッセージの暗号化に成功したら返されました
\return BAD_FUNC_ARG 暗号化プロセス中にエラーがある場合
\param inKey 暗号化に使用する32バイトのキーを含むバッファへのポインタ
\param inIv 暗号化に使用する12バイトのIVを含むバッファへのポインタ
\param inAAD 任意の長さの追加認証データAADを含むバッファへのポインタ
\param inAADLen 入力AADの長さ
\param inPlaintext 暗号化する平文を含むバッファへのポインタ
\param inPlaintextLen 暗号化するプレーンテキストの長さ
\param outCiphertext 暗号文を保存するバッファーへのポインタ
_Example_
\code
byte key[] = { // initialize 32 byte key };
byte iv[] = { // initialize 12 byte key };
byte inAAD[] = { // initialize AAD };
byte plain[] = { // initialize message to encrypt };
byte cipher[sizeof(plain)];
byte authTag[16];
int ret = wc_ChaCha20Poly1305_Encrypt(key, iv, inAAD, sizeof(inAAD),
plain, sizeof(plain), cipher, authTag);
if(ret != 0) {
// error running encrypt
}
\endcode
\sa wc_ChaCha20Poly1305_Decrypt
\sa wc_ChaCha_*
\sa wc_Poly1305*
*/
int wc_ChaCha20Poly1305_Encrypt(
const byte inKey[CHACHA20_POLY1305_AEAD_KEYSIZE],
const byte inIV[CHACHA20_POLY1305_AEAD_IV_SIZE],
const byte* inAAD, const word32 inAADLen,
const byte* inPlaintext, const word32 inPlaintextLen,
byte* outCiphertext,
byte outAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE]);
/*!
\ingroup ChaCha20Poly1305
\brief この関数は、Chacha20 Stream暗号を使用して、Chacha20 Stream暗号を使用して、出力バッファ、OutpleAntextに入力された暗号文の入力を復号化します。また、Poly-1305認証を実行し、指定されたINAUTHTAGをINAADで生成された認証任意の長さの追加認証データと比較します。注生成された認証タグが提供された認証タグと一致しない場合、テキストは復号化されません。
\return 0 メッセージの復号化に成功したときに返されました
\return BAD_FUNC_ARG 関数引数のいずれかが予想されるものと一致しない場合に返されます
\return MAC_CMP_FAILED_E 生成された認証タグが提供されているINAUTHTAGと一致しない場合に返されます。
\param inKey 復号化に使用する32バイトのキーを含むバッファへのポインタ
\param inIv 復号化に使用する12バイトのIVを含むバッファへのポインタ
\param inAAD 任意の長さの追加認証データAADを含むバッファへのポインタ
\param inAADLen 入力AADの長さ
\param inCiphertext 復号化する暗号文を含むバッファへのポインタ
\param outCiphertextLen 復号化する暗号文の長さ
\param inAuthTag 認証のための16バイトのダイジェストを含むバッファへのポインタ
_Example_
\code
byte key[] = { // initialize 32 byte key };
byte iv[] = { // initialize 12 byte key };
byte inAAD[] = { // initialize AAD };
byte cipher[] = { // initialize with received ciphertext };
byte authTag[16] = { // initialize with received authentication tag };
byte plain[sizeof(cipher)];
int ret = wc_ChaCha20Poly1305_Decrypt(key, iv, inAAD, sizeof(inAAD),
cipher, sizeof(cipher), plain, authTag);
if(ret == MAC_CMP_FAILED_E) {
// error during authentication
} else if( ret != 0) {
// error with function arguments
}
\endcode
\sa wc_ChaCha20Poly1305_Encrypt
\sa wc_ChaCha_*
\sa wc_Poly1305*
*/
int wc_ChaCha20Poly1305_Decrypt(
const byte inKey[CHACHA20_POLY1305_AEAD_KEYSIZE],
const byte inIV[CHACHA20_POLY1305_AEAD_IV_SIZE],
const byte* inAAD, const word32 inAADLen,
const byte* inCiphertext, const word32 inCiphertextLen,
const byte inAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE],
byte* outPlaintext);

View File

@@ -0,0 +1,158 @@
/*!
\ingroup Base_Encoding
\brief この機能は、与えられたBASS64符号化入力、IN、および出力バッファを出力バッファOUTに格納します。また、変数outlen内の出力バッファに書き込まれたサイズも設定します。
\return 0 Base64エンコード入力の復号化に成功したときに返されます
\return BAD_FUNC_ARG 復号化された入力を保存するには、出力バッファが小さすぎる場合は返されます。
\return ASN_INPUT_E 入力バッファ内の文字がBASE64範囲[A-ZA-Z0-9 + / =]の外側にある場合、またはBASE64エンコード入力に無効な行が終了した場合
\param in デコードする入力バッファへのポインタ
\param inLen デコードする入力バッファの長さ
\param out デコードされたメッセージを保存する出力バッファへのポインタ
_Example_
\code
byte encoded[] = { // initialize text to decode };
byte decoded[sizeof(encoded)];
// requires at least (sizeof(encoded) * 3 + 3) / 4 room
int outLen = sizeof(decoded);
if( Base64_Decode(encoded,sizeof(encoded), decoded, &outLen) != 0 ) {
// error decoding input buffer
}
\endcode
\sa Base64_Encode
\sa Base16_Decode
*/
int Base64_Decode(const byte* in, word32 inLen, byte* out,
word32* outLen);
/*!
\ingroup Base_Encoding
\brief この機能は与えられた入力を符号化し、符号化結果を出力バッファOUTに格納します。エスケープ0A行末の代わりに、従来の '\ N'行の終わりを持つデータを書き込みます。正常に完了すると、この機能はまた、出力バッファに書き込まれたバイト数に統一されます。
\return 0 Base64エンコード入力の復号化に成功したときに返されます
\return BAD_FUNC_ARG 出力バッファが小さすぎてエンコードされた入力を保存する場合は返されます。
\return BUFFER_E 出力バッファがエンコード中に部屋の外に実行された場合に返されます。
\param in エンコードする入力バッファへのポインタ
\param inLen エンコードする入力バッファの長さ
\param out エンコードされたメッセージを保存する出力バッファへのポインタ
_Example_
\code
byte plain[] = { // initialize text to encode };
byte encoded[MAX_BUFFER_SIZE];
int outLen = sizeof(encoded);
if( Base64_Encode(plain, sizeof(plain), encoded, &outLen) != 0 ) {
// error encoding input buffer
}
\endcode
\sa Base64_EncodeEsc
\sa Base64_Decode
*/
int Base64_Encode(const byte* in, word32 inLen, byte* out,
word32* outLen);
/*!
\ingroup Base_Encoding
\brief この機能は与えられた入力を符号化し、符号化結果を出力バッファOUTに格納します。それは '\ n "行の終わりではなく、0aエスケープ行の終わりを持つデータを書き込みます。正常に完了すると、この機能はまた、出力バッファに書き込まれたバイト数に統一されます。
\return 0 Base64エンコード入力の復号化に成功したときに返されます
\return BAD_FUNC_ARG 出力バッファが小さすぎてエンコードされた入力を保存する場合は返されます。
\return BUFFER_E 出力バッファがエンコード中に部屋の外に実行された場合に返されます。
\return ASN_INPUT_E 入力メッセージのデコードの処理中にエラーが発生した場合
\param in エンコードする入力バッファへのポインタ
\param inLen エンコードする入力バッファの長さ
\param out エンコードされたメッセージを保存する出力バッファへのポインタ
_Example_
\code
byte plain[] = { // initialize text to encode };
byte encoded[MAX_BUFFER_SIZE];
int outLen = sizeof(encoded);
if( Base64_EncodeEsc(plain, sizeof(plain), encoded, &outLen) != 0 ) {
// error encoding input buffer
}
\endcode
\sa Base64_Encode
\sa Base64_Decode
*/
int Base64_EncodeEsc(const byte* in, word32 inLen, byte* out,
word32* outLen);
/*!
\ingroup Base_Encoding
\brief この機能は与えられた入力を符号化し、符号化結果を出力バッファOUTに格納します。それは新しい行なしでデータを書き込みます。正常に完了すると、この関数はまた、出力バッファに書き込まれたバイト数に統一されたものを設定します
\return 0 Base64エンコード入力の復号化に成功したときに返されます
\return BAD_FUNC_ARG 出力バッファが小さすぎてエンコードされた入力を保存する場合は返されます。
\return BUFFER_E 出力バッファがエンコード中に部屋の外に実行された場合に返されます。
\return ASN_INPUT_E 入力メッセージのデコードの処理中にエラーが発生した場合
\param in エンコードする入力バッファへのポインタ
\param inLen エンコードする入力バッファの長さ
\param out エンコードされたメッセージを保存する出力バッファへのポインタ
_Example_
\code
byte plain[] = { // initialize text to encode };
byte encoded[MAX_BUFFER_SIZE];
int outLen = sizeof(encoded);
if( Base64_Encode_NoNl(plain, sizeof(plain), encoded, &outLen) != 0 ) {
// error encoding input buffer
}
\endcode
\sa Base64_Encode
\sa Base64_Decode
*/
int Base64_Encode_NoNl(const byte* in, word32 inLen, byte* out,
word32* outLen);
/*!
\ingroup Base_Encoding
\brief この機能は、与えられたBASE16符号化入力、IN、および出力バッファへの結果を記憶する。また、変数outlen内の出力バッファに書き込まれたサイズも設定します。
\return 0 Base16エンコード入力の復号にうまく復号化したときに返されます
\return BAD_FUNC_ARG 出力バッファが復号化された入力を保存するにも小さすぎる場合、または入力長が2つの倍数でない場合に返されます。
\return ASN_INPUT_E 入力バッファ内の文字がBASE16の範囲外にある場合は返されます[0-9a-f]
\param in デコードする入力バッファへのポインタ
\param inLen デコードする入力バッファの長さ
\param out デコードされたメッセージを保存する出力バッファへのポインタ
_Example_
\code
byte encoded[] = { // initialize text to decode };
byte decoded[sizeof(encoded)];
int outLen = sizeof(decoded);
if( Base16_Decode(encoded,sizeof(encoded), decoded, &outLen) != 0 ) {
// error decoding input buffer
}
\endcode
\sa Base64_Encode
\sa Base64_Decode
\sa Base16_Encode
*/
int Base16_Decode(const byte* in, word32 inLen, byte* out, word32* outLen);
/*!
\ingroup Base_Encoding
\brief BASE16出力へのエンコード入力。
\return 0 成功
\return BAD_FUNC_ARG IN、OUT、またはoutlenがNULLの場合、またはoutlenがInlen Plus 1を超えている場合は返します。
\param in エンコードされる入力バッファへのポインタ。
\param inLen 入力バッファの長さ
\param out 出力バッファへのポインタ。
_Example_
\code
byte in[] = { // Contents of something to be encoded };
byte out[NECESSARY_OUTPUT_SIZE];
word32 outSz = sizeof(out);
if(Base16_Encode(in, sizeof(in), out, &outSz) != 0)
{
// Handle encode error
}
\endcode
\sa Base64_Encode
\sa Base64_Decode
\sa Base16_Decode
*/
int Base16_Encode(const byte* in, word32 inLen, byte* out, word32* outLen);

View File

@@ -0,0 +1,47 @@
/*!
\ingroup Compression
\brief この関数は、ハフマン符号化を用いて与えられた入力データを圧縮し、出力をOUTに格納する。出力バッファは、圧縮が可能でないことが存在するため、出力バッファが入力バッファよりも大きいはずです。これはまだルックアップテーブルを必要とします。出力バッファに対してSRCSZ + 0.1+ 12を割り当てることをお勧めします。
\return On 入力データの圧縮に成功し、出力バッファに格納されているバイト数を返します。
\return COMPRESS_INIT_E 圧縮のためにストリームの初期化中にエラーがある場合
\return COMPRESS_E 圧縮中にエラーが発生した場合は返されます
\param out 圧縮データを格納する出力バッファへのポインタ
\param outSz 出力バッファで保存されているサイズ
\param in 圧縮するメッセージを含むバッファへのポインタ
\param inSz 圧縮する入力メッセージのサイズ
_Example_
\code
byte message[] = { // initialize text to compress };
byte compressed[(sizeof(message) + sizeof(message) * .001 + 12 )];
// Recommends at least srcSz + .1% + 12
if( wc_Compress(compressed, sizeof(compressed), message, sizeof(message),
0) != 0){
// error compressing data
}
\endcode
\sa wc_DeCompress
*/
int wc_Compress(byte* out, word32 outSz, const byte* in, word32 inSz, word32 flags);
/*!
\ingroup Compression
\brief この関数は、ハフマン符号化を用いて所定の圧縮データを解凍し、出力をOUTに格納する。
\return Success 入力データの解凍に成功した場合は、出力バッファに格納されているバイト数を返します。
\return COMPRESS_INIT_E: 圧縮のためにストリームの初期化中にエラーがある場合
\return COMPRESS_E: 圧縮中にエラーが発生した場合は返されます
\param out 解凍されたデータを格納する出力バッファへのポインタ
\param outSz 出力バッファで保存されているサイズ
\param in 解凍するメッセージを含むバッファへのポインタ
_Example_
\code
byte compressed[] = { // initialize compressed message };
byte decompressed[MAX_MESSAGE_SIZE];
if( wc_DeCompress(decompressed, sizeof(decompressed),
compressed, sizeof(compressed)) != 0 ) {
// error decompressing data
}
\endcode
\sa wc_Compress
*/
int wc_DeCompress(byte* out, word32 outSz, const byte* in, word32 inSz);

View File

@@ -0,0 +1,89 @@
/*!
\ingroup CryptoCb
\brief この関数は、Crypto Operationsをキーストア、Secure Element、HSM、PKCS11またはTPMなどの外部ハードウェアにオフロードするための固有のデバイス識別子DEVIDとコールバック関数を登録します。CryptoコールバックのSTSAFEの場合は、wolfcrypt / src / port / st / stsafe.cとwolfssl_stsafe_cryptodevcb関数を参照してください。TPMベースのCryptoコールバックの例では、wolftpm src / tpm2_wrap.cのwolftpm2_cryptodevcb関数を参照してください。
\return CRYPTOCB_UNAVAILABLE ソフトウェア暗号を使用するためにフォールバックする
\return 0 成功のために
\return negative 失敗の値
\param devId -2invalid_devidではなく、一意の値ではありません。
_Example_
\code
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/cryptocb.h>
static int myCryptoCb_Func(int devId, wc_CryptoInfo* info, void* ctx)
{
int ret = CRYPTOCB_UNAVAILABLE;
if (info->algo_type == WC_ALGO_TYPE_PK) {
#ifndef NO_RSA
if (info->pk.type == WC_PK_TYPE_RSA) {
switch (info->pk.rsa.type) {
case RSA_PUBLIC_ENCRYPT:
case RSA_PUBLIC_DECRYPT:
// RSA public op
ret = wc_RsaFunction(
info->pk.rsa.in, info->pk.rsa.inLen,
info->pk.rsa.out, info->pk.rsa.outLen,
info->pk.rsa.type, info->pk.rsa.key,
info->pk.rsa.rng);
break;
case RSA_PRIVATE_ENCRYPT:
case RSA_PRIVATE_DECRYPT:
// RSA private op
ret = wc_RsaFunction(
info->pk.rsa.in, info->pk.rsa.inLen,
info->pk.rsa.out, info->pk.rsa.outLen,
info->pk.rsa.type, info->pk.rsa.key,
info->pk.rsa.rng);
break;
}
}
#endif
#ifdef HAVE_ECC
if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
// ECDSA
ret = wc_ecc_sign_hash(
info->pk.eccsign.in, info->pk.eccsign.inlen,
info->pk.eccsign.out, info->pk.eccsign.outlen,
info->pk.eccsign.rng, info->pk.eccsign.key);
}
#endif
#ifdef HAVE_ED25519
if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
// ED25519 sign
ret = wc_ed25519_sign_msg_ex(
info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
info->pk.ed25519sign.key, info->pk.ed25519sign.type,
info->pk.ed25519sign.context,
info->pk.ed25519sign.contextLen);
}
#endif
}
return ret;
}
int devId = 1;
wc_CryptoCb_RegisterDevice(devId, myCryptoCb_Func, &myCtx);
wolfSSL_CTX_SetDevId(ctx, devId);
\endcode
\sa wc_CryptoCb_UnRegisterDevice
\sa wolfSSL_SetDevId
\sa wolfSSL_CTX_SetDevId
*/
int wc_CryptoCb_RegisterDevice(int devId, CryptoDevCallbackFunc cb, void* ctx);
/*!
\ingroup CryptoCb
\brief この関数は、固有のデバイス識別子devidコールバック関数を除外します。
\return none いいえ返します。
_Example_
\code
wc_CryptoCb_UnRegisterDevice(devId);
devId = INVALID_DEVID;
wolfSSL_CTX_SetDevId(ctx, devId);
\endcode
\sa wc_CryptoCb_RegisterDevice
\sa wolfSSL_SetDevId
\sa wolfSSL_CTX_SetDevId
*/
void wc_CryptoCb_UnRegisterDevice(int devId);

View File

@@ -0,0 +1,575 @@
/*!
\ingroup Curve25519
\brief この関数は、与えられたサイズKeysizeの指定された乱数発生器RNGを使用してCurve25519キーを生成し、それを指定されたCurve25519_Key構造体に格納します。キー構造がWC_CURVE25519_INITを介して初期化された後に呼び出されるべきです。
\return 0 キーの生成に成功し、それを指定されたCurve25519_Key構造体に格納します。
\return ECC_BAD_ARG_E 入力キーサイズがCurve25519キー32バイトのキーシェイズに対応していない場合は返されます。
\return RNG_FAILURE_E RNGの内部ステータスがDRBG_OKでない場合、またはRNGを使用して次のランダムブロックを生成する場合に返されます。
\return BAD_FUNC_ARG 渡された入力パラメータのいずれかがNULLの場合に返されます。
\param [in] RNG ECCキーの生成に使用されるRNGオブジェクトへのポインタ。
\param [in] キーサイズ生成キーのサイズ。Curve25519の32バイトでなければなりません。
_Example_
\code
int ret;
curve25519_key key;
wc_curve25519_init(&key); // initialize key
WC_RNG rng;
wc_InitRng(&rng); // initialize random number generator
ret = wc_curve25519_make_key(&rng, 32, &key);
if (ret != 0) {
// error making Curve25519 key
}
\endcode
\sa wc_curve25519_init
*/
int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key);
/*!
\ingroup Curve25519
\brief この関数は、秘密の秘密鍵と受信した公開鍵を考えると、共有秘密鍵を計算します。生成された秘密鍵をバッファアウトに保存し、ounlentの秘密鍵の変数を割り当てます。ビッグエンディアンのみをサポートします。
\return 0 共有秘密鍵を正常に計算したときに返されました。
\return BAD_FUNC_ARG 渡された入力パラメータのいずれかがNULLの場合に返されます。
\return ECC_BAD_ARG_E 公開鍵の最初のビットが設定されている場合は、実装の指紋を避けるために返されます。
\param [in] Private_Key Curve25519_Key構造体の秘密鍵で初期化されました。
\param [in] public_key受信した公開鍵を含むCurve25519_Key構造体へのポインタ。
\param [out] 32バイト計算された秘密鍵を格納するバッファへのポインタ。
_Example_
\code
int ret;
byte sharedKey[32];
word32 keySz;
curve25519_key privKey, pubKey;
// initialize both keys
ret = wc_curve25519_shared_secret(&privKey, &pubKey, sharedKey, &keySz);
if (ret != 0) {
// error generating shared key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
\sa wc_curve25519_shared_secret_ex
*/
int wc_curve25519_shared_secret(curve25519_key* private_key,
curve25519_key* public_key,
byte* out, word32* outlen);
/*!
\ingroup Curve25519
\brief この関数は、秘密の秘密鍵と受信した公開鍵を考えると、共有秘密鍵を計算します。生成された秘密鍵をバッファアウトに保存し、ounlentの秘密鍵の変数を割り当てます。大きくてリトルエンディアンの両方をサポートします。
\return 0 共有秘密鍵を正常に計算したときに返されました。
\return BAD_FUNC_ARG 渡された入力パラメータのいずれかがNULLの場合に返されます。
\return ECC_BAD_ARG_E 公開鍵の最初のビットが設定されている場合は、実装の指紋を避けるために返されます。
\param [in] Private_Key Curve25519_Key構造体の秘密鍵で初期化されました。
\param [in] public_key受信した公開鍵を含むCurve25519_Key構造体へのポインタ。
\param [out] 32バイト計算された秘密鍵を格納するバッファへのポインタ。
\param pin,out] 出力バッファに書き込まれた長さを記憶するポインタの概要。
_Example_
\code
int ret;
byte sharedKey[32];
word32 keySz;
curve25519_key privKey, pubKey;
// initialize both keys
ret = wc_curve25519_shared_secret_ex(&privKey, &pubKey, sharedKey, &keySz,
EC25519_BIG_ENDIAN);
if (ret != 0) {
// error generating shared key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
\sa wc_curve25519_shared_secret
*/
int wc_curve25519_shared_secret_ex(curve25519_key* private_key,
curve25519_key* public_key,
byte* out, word32* outlen, int endian);
/*!
\ingroup Curve25519
\brief この関数はCurve25519キーを初期化します。構造のキーを生成する前に呼び出されるべきです。
\return 0 Curve25519_Key構造体の初期化に成功しました。
\return BAD_FUNC_ARG キーがNULLのときに返されます。
_Example_
\code
curve25519_key key;
wc_curve25519_init(&key); // initialize key
// make key and proceed to encryption
\endcode
\sa wc_curve25519_make_key
*/
int wc_curve25519_init(curve25519_key* key);
/*!
\ingroup Curve25519
\brief この関数はCurve25519オブジェクトを解放します。
_Example_
\code
curve25519_key privKey;
// initialize key, use it to generate shared secret key
wc_curve25519_free(&privKey);
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
*/
void wc_curve25519_free(curve25519_key* key);
/*!
\ingroup Curve25519
\brief この関数はCurve25519秘密鍵のみをインポートします。ビッグエンディアン
\return 0 秘密鍵のインポートに成功しました。
\return BAD_FUNC_ARG キーまたはPRIVがNULLの場合は返します。
\return ECC_BAD_ARG_E PRIVSZがcurve25519_KEY_SIZEと等しくない場合は返します。
\param [in] インポートする秘密鍵を含むバッファへのポイント。
\param [in] インポートする秘密鍵のPrivsz長。
_Example_
\code
int ret;
byte priv[] = { Contents of private key };
curve25519_key key;
wc_curve25519_init(&key);
ret = wc_curve25519_import_private(priv, sizeof(priv), &key);
if (ret != 0) {
// error importing keys
}
\endcode
\sa wc_curve25519_import_private_ex
\sa wc_curve25519_size
*/
int wc_curve25519_import_private(const byte* priv, word32 privSz,
curve25519_key* key);
/*!
\ingroup Curve25519
\brief CURVE25519秘密鍵のインポートのみ。大きなエンディアン
\return 0 秘密鍵のインポートに成功しました。
\return BAD_FUNC_ARG キーまたはPRIVがNULLの場合は返します。
\return ECC_BAD_ARG_E PRIVSZがcurve25519_KEY_SIZEと等しくない場合は返します。
\param [in] インポートする秘密鍵を含むバッファへのポイント。
\param [in] インポートする秘密鍵のPrivsz長。
\param [in,out] インポートされたキーを保存する構造へのキーポインタ。
_Example_
\code
int ret;
byte priv[] = { // Contents of private key };
curve25519_key key;
wc_curve25519_init(&key);
ret = wc_curve25519_import_private_ex(priv, sizeof(priv), &key,
EC25519_BIG_ENDIAN);
if (ret != 0) {
// error importing keys
}
\endcode
\sa wc_curve25519_import_private
\sa wc_curve25519_size
*/
int wc_curve25519_import_private_ex(const byte* priv, word32 privSz,
curve25519_key* key, int endian);
/*!
\ingroup Curve25519
\brief この関数は、パブリック秘密鍵ペアをCurve25519_Key構造体にインポートします。ビッグエンディアンのみ。
\return 0 Curve25519_Key構造体へのインポートに返されます
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返します。
\return ECC_BAD_ARG_E 入力キーのキーサイズがPublicキーサイズまたは秘密鍵サイズと一致しない場合に返されます。
\param [in] インポートする秘密鍵を含むバッファへのポイント。
\param [in] インポートする秘密鍵のPrivsz長。
\param [in] パブリックキーをインポートするバッファへのPub。
\param [in] インポートする公開鍵のPubsz長さ。
_Example_
\code
int ret;
byte priv[32];
byte pub[32];
// initialize with public and private keys
curve25519_key key;
wc_curve25519_init(&key);
// initialize key
ret = wc_curve25519_import_private_raw(&priv, sizeof(priv), pub,
sizeof(pub), &key);
if (ret != 0) {
// error importing keys
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
\sa wc_curve25519_import_public
\sa wc_curve25519_export_private_raw
*/
int wc_curve25519_import_private_raw(const byte* priv, word32 privSz,
const byte* pub, word32 pubSz, curve25519_key* key);
/*!
\ingroup Curve25519
\brief この関数は、パブリック秘密鍵ペアをCurve25519_Key構造体にインポートします。大きくてリトルエンディアンの両方をサポートします。
\return 0 Curve25519_Key構造体へのインポートに返されます
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返します。
\return ECC_BAD_ARG_E 戻されたIFまたは入力キーのキーサイズがパブリックキーサイズまたは秘密鍵サイズと一致しない場合
\param [in] インポートする秘密鍵を含むバッファへのポイント。
\param [in] インポートする秘密鍵のPrivsz長。
\param [in] パブリックキーをインポートするバッファへのPub。
\param [in] インポートする公開鍵のPubsz長さ。
\param [in,out] インポートされたキーを保存する構造へのキーポインタ。
_Example_
\code
int ret;
byte priv[32];
byte pub[32];
// initialize with public and private keys
curve25519_key key;
wc_curve25519_init(&key);
// initialize key
ret = wc_curve25519_import_private_raw_ex(&priv, sizeof(priv), pub,
sizeof(pub), &key, EC25519_BIG_ENDIAN);
if (ret != 0) {
// error importing keys
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
\sa wc_curve25519_import_public
\sa wc_curve25519_export_private_raw
\sa wc_curve25519_import_private_raw
*/
int wc_curve25519_import_private_raw_ex(const byte* priv, word32 privSz,
const byte* pub, word32 pubSz,
curve25519_key* key, int endian);
/*!
\ingroup Curve25519
\brief この関数はCurve25519_Key構造体から秘密鍵をエクスポートし、それを指定されたアウトバッファに格納します。また、エクスポートされたキーのサイズになるように概要を設定します。ビッグエンディアンのみ。
\return 0 Curve25519_Key構造体から秘密鍵を正常にエクスポートしました。
\return BAD_FUNC_ARG 入力パラメータがNULLの場合に返されます。
\return ECC_BAD_ARG_E WC_CURVE25519_SIZEがキーと等しくない場合に返されます。
\param [in] キーをエクスポートする構造へのキーポインタ。
\param [out] エクスポートされたキーを保存するバッファへのポインタ。
_Example_
\code
int ret;
byte priv[32];
int privSz;
curve25519_key key;
// initialize and make key
ret = wc_curve25519_export_private_raw(&key, priv, &privSz);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
\sa wc_curve25519_import_private_raw
\sa wc_curve25519_export_private_raw_ex
*/
int wc_curve25519_export_private_raw(curve25519_key* key, byte* out,
word32* outLen);
/*!
\ingroup Curve25519
\brief この関数はCurve25519_Key構造体から秘密鍵をエクスポートし、それを指定されたアウトバッファに格納します。また、エクスポートされたキーのサイズになるように概要を設定します。それが大きいかリトルエンディアンかを指定できます。
\return 0 Curve25519_Key構造体から秘密鍵を正常にエクスポートしました。
\return BAD_FUNC_ARG 入力パラメータがNULLの場合に返されます。
\return ECC_BAD_ARG_E WC_CURVE25519_SIZEがキーと等しくない場合に返されます。
\param [in] キーをエクスポートする構造へのキーポインタ。
\param [out] エクスポートされたキーを保存するバッファへのポインタ。
\param [in,out] INに照会は、バイト数のサイズです。ON OUTでは、出力バッファに書き込まれたバイトを保存します。
_Example_
\code
int ret;
byte priv[32];
int privSz;
curve25519_key key;
// initialize and make key
ret = wc_curve25519_export_private_raw_ex(&key, priv, &privSz,
EC25519_BIG_ENDIAN);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
\sa wc_curve25519_import_private_raw
\sa wc_curve25519_export_private_raw
\sa wc_curve25519_size
*/
int wc_curve25519_export_private_raw_ex(curve25519_key* key, byte* out,
word32* outLen, int endian);
/*!
\ingroup Curve25519
\brief この関数は、指定されたバッファから公開鍵をインポートし、それをCurve25519_Key構造体に格納します。
\return 0 公開鍵をCurve25519_Key構造体に正常にインポートしました。
\return ECC_BAD_ARG_E InLenパラメータがキー構造のキーサイズと一致しない場合に返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返されます。
\param [in] インポートする公開鍵を含むバッファへのポインタ。
\param [in] インポートする公開鍵のインレル長。
_Example_
\code
int ret;
byte pub[32];
// initialize pub with public key
curve25519_key key;
// initialize key
ret = wc_curve25519_import_public(pub,sizeof(pub), &key);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_export_public
\sa wc_curve25519_import_private_raw
\sa wc_curve25519_import_public_ex
\sa wc_curve25519_check_public
\sa wc_curve25519_size
*/
int wc_curve25519_import_public(const byte* in, word32 inLen,
curve25519_key* key);
/*!
\ingroup Curve25519
\brief この関数は、指定されたバッファから公開鍵をインポートし、それをCurve25519_Key構造体に格納します。
\return 0 公開鍵をCurve25519_Key構造体に正常にインポートしました。
\return ECC_BAD_ARG_E InLenパラメータがキー構造のキーサイズと一致しない場合に返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返されます。
\param [in] インポートする公開鍵を含むバッファへのポインタ。
\param [in] インポートする公開鍵のインレル長。
\param [in,out] キーを保存するカーブ25519キー構造へのキーポインタ。
_Example_
\code
int ret;
byte pub[32];
// initialize pub with public key
curve25519_key key;
// initialize key
ret = wc_curve25519_import_public_ex(pub, sizeof(pub), &key,
EC25519_BIG_ENDIAN);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_export_public
\sa wc_curve25519_import_private_raw
\sa wc_curve25519_import_public
\sa wc_curve25519_check_public
\sa wc_curve25519_size
*/
int wc_curve25519_import_public_ex(const byte* in, word32 inLen,
curve25519_key* key, int endian);
/*!
\ingroup Curve25519
\brief この関数は、公開鍵バッファがエンディアン注文を与えられた有効なCurve2519キー値を保持していることを確認します。
\return 0 公開鍵の値が有効なときに返されます。
\return ECC_BAD_ARG_E 公開鍵の値が無効な場合は返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返されます。
\param [in] チェックするための公開鍵を含むバッファへのPubポインタ。
\param [in] チェックするための公開鍵の長さを掲載します。
_Example_
\code
int ret;
byte pub[] = { Contents of public key };
ret = wc_curve25519_check_public_ex(pub, sizeof(pub), EC25519_BIG_ENDIAN);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_import_public
\sa wc_curve25519_import_public_ex
\sa wc_curve25519_size
*/
int wc_curve25519_check_public(const byte* pub, word32 pubSz, int endian);
/*!
\ingroup Curve25519
\brief この関数は指定されたキー構造から公開鍵をエクスポートし、結果をアウトバッファに格納します。ビッグエンディアンのみ。
\return 0 Curve25519_Key構造体から公開鍵を正常にエクスポートする上で返されます。
\return ECC_BAD_ARG_E outlenがcurve25519_pub_key_sizeより小さい場合に返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返されます。
\param [in] キーをエクスポートするCurve25519_Key構造体へのキーポインタ。
\param [out] 公開鍵を保存するバッファへのポインタ。
_Example_
\code
int ret;
byte pub[32];
int pubSz;
curve25519_key key;
// initialize and make key
ret = wc_curve25519_export_public(&key, pub, &pubSz);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_export_private_raw
\sa wc_curve25519_import_public
*/
int wc_curve25519_export_public(curve25519_key* key, byte* out, word32* outLen);
/*!
\ingroup Curve25519
\brief この関数は指定されたキー構造から公開鍵をエクスポートし、結果をアウトバッファに格納します。大きくてリトルエンディアンの両方をサポートします。
\return 0 Curve25519_Key構造体から公開鍵を正常にエクスポートする上で返されます。
\return ECC_BAD_ARG_E outlenがcurve25519_pub_key_sizeより小さい場合に返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返されます。
\param [in] キーをエクスポートするCurve25519_Key構造体へのキーポインタ。
\param [out] 公開鍵を保存するバッファへのポインタ。
\param [in,out] INに照会は、バイト数のサイズです。ON OUTでは、出力バッファに書き込まれたバイトを保存します。
_Example_
\code
int ret;
byte pub[32];
int pubSz;
curve25519_key key;
// initialize and make key
ret = wc_curve25519_export_public_ex(&key, pub, &pubSz, EC25519_BIG_ENDIAN);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_export_private_raw
\sa wc_curve25519_import_public
*/
int wc_curve25519_export_public_ex(curve25519_key* key, byte* out,
word32* outLen, int endian);
/*!
\ingroup Curve25519
\brief Export Curve25519キーペア。ビッグエンディアンのみ。
\return 0 Curve25519_Key構造体からキーペアのエクスポートに成功しました。
\return BAD_FUNC_ARG 入力パラメータがNULLの場合に返されます。
\return ECC_BAD_ARG_E PRIVSZがCURUV25519_SEY_SIZEまたはPUBSZよりも小さい場合は、PUBSZがCURUG25519_PUB_KEY_SIZEよりも小さい場合に返されます。
\param [in] キーペアをエクスポートするCURUN448_KEY構造体へのキーポインタ。
\param [out] 秘密鍵を保存するバッファへのPRIVポインタ。
\param [in,out] PRIVSZ ON INは、PRIVバッファのサイズをバイト単位でです。ON OUTは、PRIVバッファに書き込まれたバイトを保存します。
\param [out] パブリックキーを保存するバッファへのPub。
_Example_
\code
int ret;
byte pub[32];
byte priv[32];
int pubSz;
int privSz;
curve25519_key key;
// initialize and make key
ret = wc_curve25519_export_key_raw(&key, priv, &privSz, pub, &pubSz);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve25519_export_key_raw_ex
\sa wc_curve25519_export_private_raw
*/
int wc_curve25519_export_key_raw(curve25519_key* key,
byte* priv, word32 *privSz,
byte* pub, word32 *pubSz);
/*!
\ingroup Curve25519
\brief Export Curve25519キーペア。大きいまたはリトルエンディアン。
\return 0 Curve25519_Key構造体からキーペアのエクスポートに成功しました。
\return BAD_FUNC_ARG 入力パラメータがNULLの場合に返されます。
\return ECC_BAD_ARG_E PRIVSZがCURUV25519_SEY_SIZEまたはPUBSZよりも小さい場合は、PUBSZがCURUG25519_PUB_KEY_SIZEよりも小さい場合に返されます。
\param [in] キーペアをエクスポートするCURUN448_KEY構造体へのキーポインタ。
\param [out] 秘密鍵を保存するバッファへのPRIVポインタ。
\param [in,out] PRIVSZ ON INは、PRIVバッファのサイズをバイト単位でです。ON OUTは、PRIVバッファに書き込まれたバイトを保存します。
\param [out] パブリックキーを保存するバッファへのPub。
\param [in,out] PUBSZ ON INは、パブバッファのサイズをバイト単位でです。ON OUTでは、PUBバッファに書き込まれたバイトを保存します。
_Example_
\code
int ret;
byte pub[32];
byte priv[32];
int pubSz;
int privSz;
curve25519_key key;
// initialize and make key
ret = wc_curve25519_export_key_raw_ex(&key,priv, &privSz, pub, &pubSz,
EC25519_BIG_ENDIAN);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve25519_export_key_raw
\sa wc_curve25519_export_private_raw_ex
\sa wc_curve25519_export_public_ex
*/
int wc_curve25519_export_key_raw_ex(curve25519_key* key,
byte* priv, word32 *privSz,
byte* pub, word32 *pubSz,
int endian);
/*!
\ingroup Curve25519
\brief この関数は与えられたキー構造のキーサイズを返します。
\return Success 有効な初期化されたCurve25519_Key構造体を考慮すると、キーのサイズを返します。
\return 0 キーがNULLの場合は返されます
_Example_
\code
int keySz;
curve25519_key key;
// initialize and make key
keySz = wc_curve25519_size(&key);
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
*/
int wc_curve25519_size(curve25519_key* key);

View File

@@ -0,0 +1,576 @@
/*!
\ingroup Curve448
\brief この関数は、与えられたサイズKeysizeのサイズの指定された乱数発生器RNGを使用してCurve448キーを生成し、それを指定されたCurve448_Key構造体に格納します。キー構造がWC_CURVE448_INITを介して初期化された後に呼び出されるべきです。
\return 0 キーの生成に成功し、それを指定されたCurve448_Key構造体に格納します。
\return ECC_BAD_ARG_E 入力キーサイズがCurve448キー56バイトのキーシェイズに対応していない場合は返されます。
\return RNG_FAILURE_E RNGの内部ステータスがDRBG_OKでない場合、またはRNGを使用して次のランダムブロックを生成する場合に返されます。
\return BAD_FUNC_ARG 渡された入力パラメータのいずれかがNULLの場合に返されます。
\param [in] RNG ECCキーの生成に使用されるRNGオブジェクトへのポインタ。
\param [in] キーサイズ生成キーのサイズ。Curve448の場合は56バイトでなければなりません。
_Example_
\code
int ret;
curve448_key key;
wc_curve448_init(&key); // initialize key
WC_RNG rng;
wc_InitRng(&rng); // initialize random number generator
ret = wc_curve448_make_key(&rng, 56, &key);
if (ret != 0) {
// error making Curve448 key
}
\endcode
\sa wc_curve448_init
*/
int wc_curve448_make_key(WC_RNG* rng, int keysize, curve448_key* key);
/*!
\ingroup Curve448
\brief この関数は、秘密の秘密鍵と受信した公開鍵を考えると、共有秘密鍵を計算します。生成された秘密鍵をバッファアウトに保存し、ounlentの秘密鍵の変数を割り当てます。ビッグエンディアンのみをサポートします。
\return 0 共有秘密鍵を正常に計算する上で返却されました
\return BAD_FUNC_ARG 渡された入力パラメーターのいずれかがNULLの場合に返されます
\param [in] Private_Key Curve448_Key構造体へのポインタユーザーの秘密鍵で初期化されました。
\param [in] public_key受信した公開鍵を含むCurve448_Key構造体へのポインタ。
\param [out] 56バイトの計算された秘密鍵を保存するバッファへのポインタ。
_Example_
\code
int ret;
byte sharedKey[56];
word32 keySz;
curve448_key privKey, pubKey;
// initialize both keys
ret = wc_curve448_shared_secret(&privKey, &pubKey, sharedKey, &keySz);
if (ret != 0) {
// error generating shared key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
\sa wc_curve448_shared_secret_ex
*/
int wc_curve448_shared_secret(curve448_key* private_key,
curve448_key* public_key,
byte* out, word32* outlen);
/*!
\ingroup Curve448
\brief この関数は、秘密の秘密鍵と受信した公開鍵を考えると、共有秘密鍵を計算します。生成された秘密鍵をバッファアウトに保存し、ounlentの秘密鍵の変数を割り当てます。大きくてリトルエンディアンの両方をサポートします。
\return 0 共有秘密鍵を正常に計算したときに返されました。
\return BAD_FUNC_ARG 渡された入力パラメータのいずれかがNULLの場合に返されます。
\param [in] Private_Key Curve448_Key構造体へのポインタユーザーの秘密鍵で初期化されました。
\param [in] public_key受信した公開鍵を含むCurve448_Key構造体へのポインタ。
\param [out] 56バイトの計算された秘密鍵を保存するバッファへのポインタ。
\param [in,out] 出力バッファに書き込まれた長さを記憶するポインタの概要。
_Example_
\code
int ret;
byte sharedKey[56];
word32 keySz;
curve448_key privKey, pubKey;
// initialize both keys
ret = wc_curve448_shared_secret_ex(&privKey, &pubKey, sharedKey, &keySz,
EC448_BIG_ENDIAN);
if (ret != 0) {
// error generating shared key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
\sa wc_curve448_shared_secret
*/
int wc_curve448_shared_secret_ex(curve448_key* private_key,
curve448_key* public_key,
byte* out, word32* outlen, int endian);
/*!
\ingroup Curve448
\brief この関数はCurve448キーを初期化します。構造のキーを生成する前に呼び出されるべきです。
\return 0 Curve448_Key構造体の初期化に成功しました。
\return BAD_FUNC_ARG キーがNULLのときに返されます。
_Example_
\code
curve448_key key;
wc_curve448_init(&key); // initialize key
// make key and proceed to encryption
\endcode
\sa wc_curve448_make_key
*/
int wc_curve448_init(curve448_key* key);
/*!
\ingroup Curve448
\brief この関数はCurve448オブジェクトを解放します。
_Example_
\code
curve448_key privKey;
// initialize key, use it to generate shared secret key
wc_curve448_free(&privKey);
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
*/
void wc_curve448_free(curve448_key* key);
/*!
\ingroup Curve448
\brief この関数はCurve448秘密鍵のみをインポートします。ビッグエンディアン
\return 0 秘密鍵のインポートに成功しました。
\return BAD_FUNC_ARG キーまたはPRIVがNULLの場合は返します。
\return ECC_BAD_ARG_E PRIVSZがCURUG448_KEY_SIZEと等しくない場合は返します。
\param [in] インポートする秘密鍵を含むバッファへのポイント。
\param [in] インポートする秘密鍵のPrivsz長。
_Example_
\code
int ret;
byte priv[] = { Contents of private key };
curve448_key key;
wc_curve448_init(&key);
ret = wc_curve448_import_private(priv, sizeof(priv), &key);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve448_import_private_ex
\sa wc_curve448_size
*/
int wc_curve448_import_private(const byte* priv, word32 privSz,
curve448_key* key);
/*!
\ingroup Curve448
\brief CURVE448秘密鍵のインポートのみ。大きなエンディアン
\return 0 秘密鍵のインポートに成功しました。
\return BAD_FUNC_ARG キーまたはPRIVがNULLの場合は返します。
\return ECC_BAD_ARG_E PRIVSZがCURUG448_KEY_SIZEと等しくない場合は返します。
\param [in] インポートする秘密鍵を含むバッファへのポイント。
\param [in] インポートする秘密鍵のPrivsz長。
\param [in,out] インポートされたキーを保存する構造へのキーポインタ。
_Example_
\code
int ret;
byte priv[] = { // Contents of private key };
curve448_key key;
wc_curve448_init(&key);
ret = wc_curve448_import_private_ex(priv, sizeof(priv), &key,
EC448_BIG_ENDIAN);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve448_import_private
\sa wc_curve448_size
*/
int wc_curve448_import_private_ex(const byte* priv, word32 privSz,
curve448_key* key, int endian);
/*!
\ingroup Curve448
\brief この関数は、public-秘密鍵のペアをCurve448_Key構造体にインポートします。ビッグエンディアンのみ。
\return 0 Curve448_Key構造体へのインポート時に返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返します。
\return ECC_BAD_ARG_E 入力キーのキーサイズがPublicキーサイズまたは秘密鍵サイズと一致しない場合に返されます。
\param [in] インポートする秘密鍵を含むバッファへのポイント。
\param [in] インポートする秘密鍵のPrivsz長。
\param [in] パブリックキーをインポートするバッファへのPub。
\param [in] インポートする公開鍵のPubsz長さ。
_Example_
\code
int ret;
byte priv[56];
byte pub[56];
// initialize with public and private keys
curve448_key key;
wc_curve448_init(&key);
// initialize key
ret = wc_curve448_import_private_raw(&priv, sizeof(priv), pub, sizeof(pub),
&key);
if (ret != 0) {
// error importing keys
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
\sa wc_curve448_import_public
\sa wc_curve448_export_private_raw
*/
int wc_curve448_import_private_raw(const byte* priv, word32 privSz,
const byte* pub, word32 pubSz, curve448_key* key);
/*!
\ingroup Curve448
\brief この関数は、public-秘密鍵のペアをCurve448_Key構造体にインポートします。大きくてリトルエンディアンの両方をサポートします。
\return 0 Curve448_Key構造体へのインポート時に返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返します。
\return ECC_BAD_ARG_E 入力キーのキーサイズがPublicキーサイズまたは秘密鍵サイズと一致しない場合に返されます。
\param [in] インポートする秘密鍵を含むバッファへのポイント。
\param [in] インポートする秘密鍵のPrivsz長。
\param [in] パブリックキーをインポートするバッファへのPub。
\param [in] インポートする公開鍵のPubsz長さ。
\param [in,out] インポートされたキーを保存する構造へのキーポインタ。
_Example_
\code
int ret;
byte priv[56];
byte pub[56];
// initialize with public and private keys
curve448_key key;
wc_curve448_init(&key);
// initialize key
ret = wc_curve448_import_private_raw_ex(&priv, sizeof(priv), pub,
sizeof(pub), &key, EC448_BIG_ENDIAN);
if (ret != 0) {
// error importing keys
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
\sa wc_curve448_import_public
\sa wc_curve448_export_private_raw
\sa wc_curve448_import_private_raw
*/
int wc_curve448_import_private_raw_ex(const byte* priv, word32 privSz,
const byte* pub, word32 pubSz,
curve448_key* key, int endian);
/*!
\ingroup Curve448
\brief この関数はCurve448_Key構造体から秘密鍵をエクスポートし、それを指定されたバッファに格納します。また、エクスポートされたキーのサイズになるように概要を設定します。ビッグエンディアンのみ。
\return 0 Curve448_Key構造体から秘密鍵を正常にエクスポートする上で返されました。
\return BAD_FUNC_ARG 入力パラメータがNULLの場合に返されます。
\return ECC_BAD_ARG_E WC_CURVE448_SIZEがキーと等しくない場合に返されます。
\param [in] キーをエクスポートする構造へのキーポインタ。
\param [out] エクスポートされたキーを保存するバッファへのポインタ。
_Example_
\code
int ret;
byte priv[56];
int privSz;
curve448_key key;
// initialize and make key
ret = wc_curve448_export_private_raw(&key, priv, &privSz);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
\sa wc_curve448_import_private_raw
\sa wc_curve448_export_private_raw_ex
*/
int wc_curve448_export_private_raw(curve448_key* key, byte* out,
word32* outLen);
/*!
\ingroup Curve448
\brief この関数はCurve448_Key構造体から秘密鍵をエクスポートし、それを指定されたバッファに格納します。また、エクスポートされたキーのサイズになるように概要を設定します。それが大きいかリトルエンディアンかを指定できます。
\return 0 Curve448_Key構造体から秘密鍵を正常にエクスポートする上で返されました。
\return BAD_FUNC_ARG 入力パラメータがNULLの場合に返されます。
\return ECC_BAD_ARG_E WC_CURVE448_SIZEがキーと等しくない場合に返されます。
\param [in] キーをエクスポートする構造へのキーポインタ。
\param [out] エクスポートされたキーを保存するバッファへのポインタ。
\param [in,out] INに照会は、バイト数のサイズです。ON OUTでは、出力バッファに書き込まれたバイトを保存します。
_Example_
\code
int ret;
byte priv[56];
int privSz;
curve448_key key;
// initialize and make key
ret = wc_curve448_export_private_raw_ex(&key, priv, &privSz,
EC448_BIG_ENDIAN);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
\sa wc_curve448_import_private_raw
\sa wc_curve448_export_private_raw
\sa wc_curve448_size
*/
int wc_curve448_export_private_raw_ex(curve448_key* key, byte* out,
word32* outLen, int endian);
/*!
\ingroup Curve448
\brief この関数は、指定されたバッファから公開鍵をインポートし、それをCurve448_Key構造体に格納します。
\return 0 公開鍵をCurve448_Key構造体に正常にインポートしました。
\return ECC_BAD_ARG_E InLenパラメータがキー構造のキーサイズと一致しない場合に返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返されます。
\param [in] インポートする公開鍵を含むバッファへのポインタ。
\param [in] インポートする公開鍵のインレル長。
_Example_
\code
int ret;
byte pub[56];
// initialize pub with public key
curve448_key key;
// initialize key
ret = wc_curve448_import_public(pub,sizeof(pub), &key);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_export_public
\sa wc_curve448_import_private_raw
\sa wc_curve448_import_public_ex
\sa wc_curve448_check_public
\sa wc_curve448_size
*/
int wc_curve448_import_public(const byte* in, word32 inLen,
curve448_key* key);
/*!
\ingroup Curve448
\brief この関数は、指定されたバッファから公開鍵をインポートし、それをCurve448_Key構造体に格納します。
\return 0 公開鍵をCurve448_Key構造体に正常にインポートしました。
\return ECC_BAD_ARG_E InLenパラメータがキー構造のキーサイズと一致しない場合に返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返されます。
\param [in] インポートする公開鍵を含むバッファへのポインタ。
\param [in] インポートする公開鍵のインレル長。
\param [in,out] キーを保存するCurve448_Key構造体へのキーポインタ。
_Example_
\code
int ret;
byte pub[56];
// initialize pub with public key
curve448_key key;
// initialize key
ret = wc_curve448_import_public_ex(pub, sizeof(pub), &key,
EC448_BIG_ENDIAN);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_export_public
\sa wc_curve448_import_private_raw
\sa wc_curve448_import_public
\sa wc_curve448_check_public
\sa wc_curve448_size
*/
int wc_curve448_import_public_ex(const byte* in, word32 inLen,
curve448_key* key, int endian);
/*!
\ingroup Curve448
\brief この関数は、公開鍵バッファがエンディアン順序付けを与えられた有効なCurve448キー値を保持することを確認します。
\return 0 公開鍵の値が有効なときに返されます。
\return ECC_BAD_ARG_E 公開鍵の値が無効な場合は返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返されます。
\param [in] チェックするための公開鍵を含むバッファへのPubポインタ。
\param [in] チェックするための公開鍵の長さを掲載します。
_Example_
\code
int ret;
byte pub[] = { Contents of public key };
ret = wc_curve448_check_public_ex(pub, sizeof(pub), EC448_BIG_ENDIAN);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_import_public
\sa wc_curve448_import_public_ex
\sa wc_curve448_size
*/
int wc_curve448_check_public(const byte* pub, word32 pubSz, int endian);
/*!
\ingroup Curve448
\brief この関数は指定されたキー構造から公開鍵をエクスポートし、結果をアウトバッファに格納します。ビッグエンディアンのみ。
\return 0 Curve448_Key構造体から公開鍵のエクスポートに成功しました。
\return ECC_BAD_ARG_E outlenがcurve448_pub_key_sizeより小さい場合に返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返されます。
\param [in] キーをエクスポートするCurve448_Key構造体へのキーポインタ。
\param [out] 公開鍵を保存するバッファへのポインタ。
_Example_
\code
int ret;
byte pub[56];
int pubSz;
curve448_key key;
// initialize and make key
ret = wc_curve448_export_public(&key, pub, &pubSz);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_export_private_raw
\sa wc_curve448_import_public
*/
int wc_curve448_export_public(curve448_key* key, byte* out, word32* outLen);
/*!
\ingroup Curve448
\brief この関数は指定されたキー構造から公開鍵をエクスポートし、結果をアウトバッファに格納します。大きくてリトルエンディアンの両方をサポートします。
\return 0 Curve448_Key構造体から公開鍵のエクスポートに成功しました。
\return ECC_BAD_ARG_E outlenがcurve448_pub_key_sizeより小さい場合に返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLの場合に返されます。
\param [in] キーをエクスポートするCurve448_Key構造体へのキーポインタ。
\param [out] 公開鍵を保存するバッファへのポインタ。
\param [in,out] INに照会は、バイト数のサイズです。ON OUTでは、出力バッファに書き込まれたバイトを保存します。
_Example_
\code
int ret;
byte pub[56];
int pubSz;
curve448_key key;
// initialize and make key
ret = wc_curve448_export_public_ex(&key, pub, &pubSz, EC448_BIG_ENDIAN);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_export_private_raw
\sa wc_curve448_import_public
*/
int wc_curve448_export_public_ex(curve448_key* key, byte* out,
word32* outLen, int endian);
/*!
\ingroup Curve448
\brief この関数は指定されたキー構造からキーペアをエクスポートし、結果をアウトバッファに格納します。ビッグエンディアンのみ。
\return 0 Curve448_Key構造体からキーペアのエクスポートに成功しました。
\return BAD_FUNC_ARG 入力パラメータがNULLの場合に返されます。
\return ECC_BAD_ARG_E PRIVSZがCURUV448_KEY_SIZEまたはPUBSZよりも小さい場合は、Curge448_PUB_KEY_SIZEよりも小さい場合に返されます。
\param [in] キーペアをエクスポートするCURUN448_KEY構造体へのキーポインタ。
\param [out] 秘密鍵を保存するバッファへのPRIVポインタ。
\param [in,out] PRIVSZ ON INは、PRIVバッファのサイズをバイト単位でです。ON OUTは、PRIVバッファに書き込まれたバイトを保存します。
\param [out] パブリックキーを保存するバッファへのPub。
_Example_
\code
int ret;
byte pub[56];
byte priv[56];
int pubSz;
int privSz;
curve448_key key;
// initialize and make key
ret = wc_curve448_export_key_raw(&key, priv, &privSz, pub, &pubSz);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve448_export_key_raw_ex
\sa wc_curve448_export_private_raw
*/
int wc_curve448_export_key_raw(curve448_key* key,
byte* priv, word32 *privSz,
byte* pub, word32 *pubSz);
/*!
\ingroup Curve448
\brief Curve448キーペアをエクスポートします。大きいまたはリトルエンディアン。
\brief この関数は指定されたキー構造からキーペアをエクスポートし、結果をアウトバッファに格納します。大きいまたはリトルエンディアン。
\return 0 成功
\return BAD_FUNC_ARG 入力パラメータがNULLの場合に返されます。
\return ECC_BAD_ARG_E PRIVSZがCURUV448_KEY_SIZEまたはPUBSZよりも小さい場合は、Curge448_PUB_KEY_SIZEよりも小さい場合に返されます。
\param [in] キーペアをエクスポートするCURUN448_KEY構造体へのキーポインタ。
\param [out] 秘密鍵を保存するバッファへのPRIVポインタ。
\param [in,out] PRIVSZ ON INは、PRIVバッファのサイズをバイト単位でです。ON OUTは、PRIVバッファに書き込まれたバイトを保存します。
\param [out] パブリックキーを保存するバッファへのPub。
\param [in,out] PUBSZ ON INは、パブバッファのサイズをバイト単位でです。ON OUTでは、PUBバッファに書き込まれたバイトを保存します。
_Example_
\code
int ret;
byte pub[56];
byte priv[56];
int pubSz;
int privSz;
curve448_key key;
// initialize and make key
ret = wc_curve448_export_key_raw_ex(&key,priv, &privSz, pub, &pubSz,
EC448_BIG_ENDIAN);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve448_export_key_raw
\sa wc_curve448_export_private_raw_ex
\sa wc_curve448_export_public_ex
*/
int wc_curve448_export_key_raw_ex(curve448_key* key,
byte* priv, word32 *privSz,
byte* pub, word32 *pubSz,
int endian);
/*!
\ingroup Curve448
\brief この関数は与えられたキー構造のキーサイズを返します。
\return Success 有効な初期化されたCurve448_Key構造体を考慮すると、キーのサイズを返します。
\return 0 キーがNULLの場合は返されます。
_Example_
\code
int keySz;
curve448_key key;
// initialize and make key
keySz = wc_curve448_size(&key);
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
*/
int wc_curve448_size(curve448_key* key);

View File

@@ -0,0 +1,234 @@
/*!
\ingroup 3DES
\brief この関数は、引数として与えられたDES構造体のキーと初期化ベクトルIVを設定します。また、これらがまだ初期化されていない場合は、暗号化と復号化に必要なバッファーのスペースを初期化して割り当てます。注IVが指定されていない場合i.e.iv == null初期化ベクトルは、デフォルトのIV 0になります。
\return 0 DES構造体のキーと初期化ベクトルを正常に設定する
\param des 初期化するDES構造へのポインタ
\param key DES構造を初期化するための8バイトのキーを含むバッファへのポインタ
\param iv DES構造を初期化するための8バイトIVを含むバッファへのポインタ。これが提供されていない場合、IVはデフォルトで0になります
_Example_
\code
Des enc; // Des structure used for encryption
int ret;
byte key[] = { // initialize with 8 byte key };
byte iv[] = { // initialize with 8 byte iv };
ret = wc_Des_SetKey(&des, key, iv, DES_ENCRYPTION);
if (ret != 0) {
// error initializing des structure
}
\endcode
\sa wc_Des_SetIV
\sa wc_Des3_SetKey
*/
int wc_Des_SetKey(Des* des, const byte* key,
const byte* iv, int dir);
/*!
\ingroup 3DES
\brief この関数は、引数として与えられたDES構造体の初期化ベクトルIVを設定します。NULL IVを渡したら、初期化ベクトルを0に設定します。
\return none いいえ返します。
\param des IVを設定するためのDES構造へのポインタ
_Example_
\code
Des enc; // Des structure used for encryption
// initialize enc with wc_Des_SetKey
byte iv[] = { // initialize with 8 byte iv };
wc_Des_SetIV(&enc, iv);
}
\endcode
\sa wc_Des_SetKey
*/
void wc_Des_SetIV(Des* des, const byte* iv);
/*!
\ingroup 3DES
\brief この関数は入力メッセージを暗号化し、結果を出力バッファーに格納します。暗号ブロックチェーンチェーンCBCモードでDES暗号化を使用します。
\return 0 与えられた入力メッセージの暗号化に成功したときに返されます
\param des 暗号化に使用するDES構造へのポインタ
\param out 暗号化された暗号文を保存するバッファへのポインタ
\param in 暗号化するメッセージを含む入力バッファへのポインタ
_Example_
\code
Des enc; // Des structure used for encryption
// initialize enc with wc_Des_SetKey, use mode DES_ENCRYPTION
byte plain[] = { // initialize with message };
byte cipher[sizeof(plain)];
if ( wc_Des_CbcEncrypt(&enc, cipher, plain, sizeof(plain)) != 0) {
// error encrypting message
}
\endcode
\sa wc_Des_SetKey
\sa wc_Des_CbcDecrypt
*/
int wc_Des_CbcEncrypt(Des* des, byte* out,
const byte* in, word32 sz);
/*!
\ingroup 3DES
\brief この関数は入力暗号文を復号化し、結果の平文を出力バッファーに出力します。暗号ブロックチェーンチェーンCBCモードでDES暗号化を使用します。
\return 0 与えられた暗号文を正常に復号化したときに返されました
\param des 復号化に使用するDES構造へのポインタ
\param out 復号化された平文を保存するバッファへのポインタ
\param in 暗号化された暗号文を含む入力バッファへのポインタ
_Example_
\code
Des dec; // Des structure used for decryption
// initialize dec with wc_Des_SetKey, use mode DES_DECRYPTION
byte cipher[] = { // initialize with ciphertext };
byte decoded[sizeof(cipher)];
if ( wc_Des_CbcDecrypt(&dec, decoded, cipher, sizeof(cipher)) != 0) {
// error decrypting message
}
\endcode
\sa wc_Des_SetKey
\sa wc_Des_CbcEncrypt
*/
int wc_Des_CbcDecrypt(Des* des, byte* out,
const byte* in, word32 sz);
/*!
\ingroup 3DES
\brief この関数は入力メッセージを暗号化し、結果を出力バッファーに格納します。電子コードブックECBモードでDES暗号化を使用します。
\return 0: 与えられた平文を正常に暗号化すると返されます。
\param des 暗号化に使用するDES構造へのポインタ
\param out 暗号化されたメッセージを保存するバッファへのポインタ
\param in 暗号化する平文を含む入力バッファへのポインタ
_Example_
\code
Des enc; // Des structure used for encryption
// initialize enc with wc_Des_SetKey, use mode DES_ENCRYPTION
byte plain[] = { // initialize with message to encrypt };
byte cipher[sizeof(plain)];
if ( wc_Des_EcbEncrypt(&enc,cipher, plain, sizeof(plain)) != 0) {
// error encrypting message
}
\endcode
\sa wc_Des_SetKe
*/
int wc_Des_EcbEncrypt(Des* des, byte* out,
const byte* in, word32 sz);
/*!
\ingroup 3DES
\brief この関数は入力メッセージを暗号化し、結果を出力バッファーに格納します。電子コードブックECBモードでDES3暗号化を使用します。警告ほぼすべてのユースケースでECBモードは安全性が低いと考えられています。可能な限りECB APIを直接使用しないでください。
\return 0 与えられた平文を正常に暗号化すると返されます
\param des3 暗号化に使用するDES3構造へのポインタ
\param out 暗号化されたメッセージを保存するバッファへのポインタ
\param in 暗号化する平文を含む入力バッファへのポインタ
_Example_
\code
Des3 enc; // Des3 structure used for encryption
// initialize enc with wc_Des3_SetKey, use mode DES_ENCRYPTION
byte plain[] = { // initialize with message to encrypt };
byte cipher[sizeof(plain)];
if ( wc_Des3_EcbEncrypt(&enc,cipher, plain, sizeof(plain)) != 0) {
// error encrypting message
}
\endcode
\sa wc_Des3_SetKey
*/
int wc_Des3_EcbEncrypt(Des3* des, byte* out,
const byte* in, word32 sz);
/*!
\ingroup 3DES
\brief この関数は、引数として与えられたDES3構造のキーと初期化ベクトルIVを設定します。また、これらがまだ初期化されていない場合は、暗号化と復号化に必要なバッファーのスペースを初期化して割り当てます。注IVが指定されていない場合i.e.iv == null初期化ベクトルは、デフォルトのIV 0になります。
\return 0 DES構造体のキーと初期化ベクトルを正常に設定する
\param des3 初期化するDES3構造へのポインタ
\param key DES3構造を初期化する24バイトのキーを含むバッファへのポインタ
\param iv DES3構造を初期化するための8バイトIVを含むバッファへのポインタ。これが提供されていない場合、IVはデフォルトで0になります
_Example_
\code
Des3 enc; // Des3 structure used for encryption
int ret;
byte key[] = { // initialize with 24 byte key };
byte iv[] = { // initialize with 8 byte iv };
ret = wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION);
if (ret != 0) {
// error initializing des structure
}
\endcode
\sa wc_Des3_SetIV
\sa wc_Des3_CbcEncrypt
\sa wc_Des3_CbcDecrypt
*/
int wc_Des3_SetKey(Des3* des, const byte* key,
const byte* iv,int dir);
/*!
\ingroup 3DES
\brief この関数は、引数として与えられたDES3構造の初期化ベクトルIVを設定します。NULL IVを渡したら、初期化ベクトルを0に設定します。
\return none いいえ返します。
\param des IVを設定するためのDES3構造へのポインタ
_Example_
\code
Des3 enc; // Des3 structure used for encryption
// initialize enc with wc_Des3_SetKey
byte iv[] = { // initialize with 8 byte iv };
wc_Des3_SetIV(&enc, iv);
}
\endcode
\sa wc_Des3_SetKey
*/
int wc_Des3_SetIV(Des3* des, const byte* iv);
/*!
\ingroup 3DES
\brief この関数は入力メッセージを暗号化し、結果を出力バッファーに格納します。暗号ブロックチェーンCBCモードでトリプルDES3DES暗号化を使用します。
\return 0 与えられた入力メッセージの暗号化に成功したときに返されます
\param des 暗号化に使用するDES3構造へのポインタ
\param out 暗号化された暗号文を保存するバッファへのポインタ
\param in 暗号化するメッセージを含む入力バッファへのポインタ
_Example_
\code
Des3 enc; // Des3 structure used for encryption
// initialize enc with wc_Des3_SetKey, use mode DES_ENCRYPTION
byte plain[] = { // initialize with message };
byte cipher[sizeof(plain)];
if ( wc_Des3_CbcEncrypt(&enc, cipher, plain, sizeof(plain)) != 0) {
// error encrypting message
}
\endcode
\sa wc_Des3_SetKey
\sa wc_Des3_CbcDecrypt
*/
int wc_Des3_CbcEncrypt(Des3* des, byte* out,
const byte* in,word32 sz);
/*!
\ingroup 3DES
\brief この関数は入力暗号文を復号化し、結果の平文を出力バッファーに出力します。暗号ブロックチェーンCBCモードでトリプルDES3DES暗号化を使用します。
\return 0 与えられた暗号文を正常に復号化したときに返されました
\param des 復号化に使用するDES3構造へのポインタ
\param out 復号化された平文を保存するバッファへのポインタ
\param in 暗号化された暗号文を含む入力バッファへのポインタ
_Example_
\code
Des3 dec; // Des structure used for decryption
// initialize dec with wc_Des3_SetKey, use mode DES_DECRYPTION
byte cipher[] = { // initialize with ciphertext };
byte decoded[sizeof(cipher)];
if ( wc_Des3_CbcDecrypt(&dec, decoded, cipher, sizeof(cipher)) != 0) {
// error decrypting message
}
\endcode
\sa wc_Des3_SetKey
\sa wc_Des3_CbcEncrypt
*/
int wc_Des3_CbcDecrypt(Des3* des, byte* out,
const byte* in,word32 sz);

View File

@@ -0,0 +1,281 @@
/*!
\ingroup Diffie-Hellman
\brief この関数は、Diffie-Hellman Exchangeプロトコルを使用して安全な秘密鍵を交渉するのに使用するためのDiffie-Hellmanキーを初期化します。
\return none いいえ返します。
_Example_
\code
DhKey key;
wc_InitDhKey(&key); // initialize DH key
\endcode
\sa wc_FreeDhKey
\sa wc_DhGenerateKeyPair
*/
int wc_InitDhKey(DhKey* key);
/*!
\ingroup Diffie-Hellman
\brief この関数は、Diffie-Hellman Exchangeプロトコルを使用して安全な秘密鍵をネゴシエートするために使用された後にDiffie-Hellmanキーを解放します。
\return none いいえ返します。
_Example_
\code
DhKey key;
// initialize key, perform key exchange
wc_FreeDhKey(&key); // free DH key to avoid memory leaks
\endcode
\sa wc_InitDhKey
*/
void wc_FreeDhKey(DhKey* key);
/*!
\ingroup Diffie-Hellman
\brief この関数はdiffie-hellmanパブリックパラメータに基づいてパブリック/秘密鍵ペアを生成し、PRIVSの秘密鍵とPubの公開鍵を格納します。初期化されたDiffie-Hellmanキーと初期化されたRNG構造を取ります。
\return BAD_FUNC_ARG この関数への入力の1つを解析するエラーがある場合に返されます
\return RNG_FAILURE_E RNGを使用して乱数を生成するエラーが発生した場合
\return MP_INIT_E 公開鍵の生成中に数学ライブラリにエラーがある場合は返却される可能性があります
\return MP_READ_E 公開鍵の生成中に数学ライブラリにエラーがある場合は返却される可能性があります
\return MP_EXPTMOD_E 公開鍵の生成中に数学ライブラリにエラーがある場合は返却される可能性があります
\return MP_TO_E 公開鍵の生成中に数学ライブラリにエラーがある場合は返却される可能性があります
\param key キーペアを生成するDHKEY構造体へのポインタ
\param rng キーを生成するための初期化された乱数発生器RNGへのポインタ
\param priv 秘密鍵を保存するバッファへのポインタ
\param privSz PRIVに書かれた秘密鍵のサイズを保存します
\param pub 公開鍵を保存するバッファへのポインタ
_Example_
\code
DhKey key;
int ret;
byte priv[256];
byte pub[256];
word32 privSz, pubSz;
wc_InitDhKey(&key); // initialize key
// Set DH parameters using wc_DhSetKey or wc_DhKeyDecode
WC_RNG rng;
wc_InitRng(&rng); // initialize rng
ret = wc_DhGenerateKeyPair(&key, &rng, priv, &privSz, pub, &pubSz);
\endcode
\sa wc_InitDhKey
\sa wc_DhSetKey
\sa wc_DhKeyDecode
*/
int wc_DhGenerateKeyPair(DhKey* key, WC_RNG* rng, byte* priv,
word32* privSz, byte* pub, word32* pubSz);
/*!
\ingroup Diffie-Hellman
\brief この関数は、ローカル秘密鍵と受信した公開鍵に基づいて合意された秘密鍵を生成します。交換の両側で完了した場合、この関数は対称通信のための秘密鍵の合意を生成します。共有秘密鍵の生成に成功すると、書かれた秘密鍵のサイズは仲間に保存されます。
\return 0 合意された秘密鍵の生成に成功しました
\return MP_INIT_E 共有秘密鍵の生成中にエラーが発生した場合に返却される可能性があります
\return MP_READ_E 共有秘密鍵の生成中にエラーが発生した場合に返却される可能性があります
\return MP_EXPTMOD_E 共有秘密鍵の生成中にエラーが発生した場合に返却される可能性があります
\return MP_TO_E 共有秘密鍵の生成中にエラーが発生した場合に返却される可能性があります
\param key 共有キーを計算するために使用するDHKEY構造体へのポインタ
\param agree 秘密キーを保存するバッファへのポインタ
\param agreeSz 成功した後に秘密鍵のサイズを保持します
\param priv ローカル秘密鍵を含むバッファへのポインタ
\param privSz 地元の秘密鍵のサイズ
\param otherPub 受信した公開鍵を含むバッファへのポインタ
_Example_
\code
DhKey key;
int ret;
byte priv[256];
byte agree[256];
word32 agreeSz;
// initialize key, set key prime and base
// wc_DhGenerateKeyPair -- store private key in priv
byte pub[] = { // initialized with the received public key };
ret = wc_DhAgree(&key, agree, &agreeSz, priv, sizeof(priv), pub,
sizeof(pub));
if ( ret != 0 ) {
// error generating shared key
}
\endcode
\sa wc_DhGenerateKeyPair
*/
int wc_DhAgree(DhKey* key, byte* agree, word32* agreeSz,
const byte* priv, word32 privSz, const byte* otherPub,
word32 pubSz);
/*!
\ingroup Diffie-Hellman
\brief この機能は、DERフォーマットのキーを含む与えられた入力バッファからDiffie-Hellmanキーをデコードします。結果をDHKEY構造体に格納します。
\return 0 入力キーの復号に成功したときに返されます
\return ASN_PARSE_E 入力のシーケンスを解析したエラーがある場合に返されます
\return ASN_DH_KEY_E 解析された入力から秘密鍵パラメータを読み取るエラーがある場合
\param input derフォーマットされたdiffie-hellmanキーを含むバッファへのポインタ
\param inOutIdx キーをデコードしている間に解析されたインデックスを保存する整数へのポインタ
\param key 入力キーで初期化するためのDHKEY構造体へのポインタ
_Example_
\code
DhKey key;
word32 idx = 0;
byte keyBuff[1024];
// initialize with DER formatted key
wc_DhKeyInit(&key);
ret = wc_DhKeyDecode(keyBuff, &idx, &key, sizeof(keyBuff));
if ( ret != 0 ) {
// error decoding key
}
\endcode
\sa wc_DhSetKey
*/
int wc_DhKeyDecode(const byte* input, word32* inOutIdx, DhKey* key,
word32);
/*!
\ingroup Diffie-Hellman
\brief この関数は、入力秘密鍵パラメータを使用してDHKEY構造体のキーを設定します。WC_DHKEYDECODEとは異なり、この関数は入力キーがDERフォーマットでフォーマットされ、代わりにPARSED入力パラメータPPrimeとGBaseを受け入れる必要はありません。
\return 0 鍵の設定に成功しました
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLに評価された場合に返されます。
\return MP_INIT_E ストレージのキーパラメータの初期化中にエラーがある場合に返されます。
\return ASN_DH_KEY_E DHキーパラメータPおよびGでエラーの読み取りがある場合は返されます
\param key キーを設定するDHKEY構造体へのポインタ
\param p キーで使用するためのプライムを含むバッファへのポインタ
\param pSz 入力プライムの長さ
\param g キーで使用するためのベースを含むバッファへのポインタ
_Example_
\code
DhKey key;
byte p[] = { // initialize with prime };
byte g[] = { // initialize with base };
wc_DhKeyInit(&key);
ret = wc_DhSetKey(key, p, sizeof(p), g, sizeof(g));
if ( ret != 0 ) {
// error setting key
}
\endcode
\sa wc_DhKeyDecode
*/
int wc_DhSetKey(DhKey* key, const byte* p, word32 pSz, const byte* g,
word32 gSz);
/*!
\ingroup Diffie-Hellman
\brief この関数は、与えられた入力バッファからDiffie-HellmanパラメータPPrimeとGベースをフォーマットされています。
\return 0 DHパラメータの抽出に成功しました
\return ASN_PARSE_E DERフォーマットのDH証明書の解析中にエラーが発生した場合に返されます。
\return BUFFER_E 解析されたパラメータを格納するためにPまたはGに不適切なスペースがある場合
\param input 解析するDERフォーマットされたDifie-Hellman証明書を含むバッファへのポインタ
\param inSz 入力バッファのサイズ
\param p 解析されたプライムを保存するバッファへのポインタ
\param pInOutSz Pバッファ内の使用可能なサイズを含むWord32オブジェクトへのポインタ。関数呼び出しを完了した後にバッファに書き込まれたバイト数で上書きされます。
\param g 解析されたベースを保存するバッファへのポインタ
_Example_
\code
byte dhCert[] = { initialize with DER formatted certificate };
byte p[MAX_DH_SIZE];
byte g[MAX_DH_SIZE];
word32 pSz = MAX_DH_SIZE;
word32 gSz = MAX_DH_SIZE;
ret = wc_DhParamsLoad(dhCert, sizeof(dhCert), p, &pSz, g, &gSz);
if ( ret != 0 ) {
// error parsing inputs
}
\endcode
\sa wc_DhSetKey
\sa wc_DhKeyDecode
*/
int wc_DhParamsLoad(const byte* input, word32 inSz, byte* p,
word32* pInOutSz, byte* g, word32* gInOutSz);
/*!
\ingroup Diffie-Hellman
\sa wc_Dh_ffdhe3072_Get
\sa wc_Dh_ffdhe4096_Get
\sa wc_Dh_ffdhe6144_Get
\sa wc_Dh_ffdhe8192_Get
*/
const DhParams* wc_Dh_ffdhe2048_Get(void);
/*!
\ingroup Diffie-Hellman
\sa wc_Dh_ffdhe2048_Get
\sa wc_Dh_ffdhe4096_Get
\sa wc_Dh_ffdhe6144_Get
\sa wc_Dh_ffdhe8192_Get
*/
const DhParams* wc_Dh_ffdhe3072_Get(void);
/*!
\ingroup Diffie-Hellman
\sa wc_Dh_ffdhe2048_Get
\sa wc_Dh_ffdhe3072_Get
\sa wc_Dh_ffdhe6144_Get
\sa wc_Dh_ffdhe8192_Get
*/
const DhParams* wc_Dh_ffdhe4096_Get(void);
/*!
\ingroup Diffie-Hellman
\sa wc_Dh_ffdhe2048_Get
\sa wc_Dh_ffdhe3072_Get
\sa wc_Dh_ffdhe4096_Get
\sa wc_Dh_ffdhe8192_Get
*/
const DhParams* wc_Dh_ffdhe6144_Get(void);
/*!
\ingroup Diffie-Hellman
\sa wc_Dh_ffdhe2048_Get
\sa wc_Dh_ffdhe3072_Get
\sa wc_Dh_ffdhe4096_Get
\sa wc_Dh_ffdhe6144_Get
*/
const DhParams* wc_Dh_ffdhe8192_Get(void);
/*!
\ingroup Diffie-Hellman
*/
int wc_DhCheckKeyPair(DhKey* key, const byte* pub, word32 pubSz,
const byte* priv, word32 privSz);
/*!
\ingroup Diffie-Hellman
*/
int wc_DhCheckPrivKey(DhKey* key, const byte* priv, word32 pubSz);
/*!
*/
int wc_DhCheckPrivKey_ex(DhKey* key, const byte* priv, word32 pubSz,
const byte* prime, word32 primeSz);
/*!
*/
int wc_DhCheckPubKey(DhKey* key, const byte* pub, word32 pubSz);
/*!
*/
int wc_DhCheckPubKey_ex(DhKey* key, const byte* pub, word32 pubSz,
const byte* prime, word32 primeSz);
/*!
*/
int wc_DhExportParamsRaw(DhKey* dh, byte* p, word32* pSz,
byte* q, word32* qSz, byte* g, word32* gSz);
/*!
*/
int wc_DhGenerateParams(WC_RNG *rng, int modSz, DhKey *dh);
/*!
*/
int wc_DhSetCheckKey(DhKey* key, const byte* p, word32 pSz,
const byte* g, word32 gSz, const byte* q, word32 qSz,
int trusted, WC_RNG* rng);
/*!
*/
int wc_DhSetKey_ex(DhKey* key, const byte* p, word32 pSz,
const byte* g, word32 gSz, const byte* q, word32 qSz);
/*!
*/
int wc_FreeDhKey(DhKey* key);

View File

@@ -0,0 +1,243 @@
/*!
\defgroup 3DES Algorithms - 3DES
\defgroup AES Algorithms - AES
\defgroup ARC4 Algorithms - ARC4
\defgroup BLAKE2 Algorithms - BLAKE2
\defgroup Camellia Algorithms - Camellia
\defgroup ChaCha Algorithms - ChaCha
\defgroup ChaCha20Poly1305 Algorithms - ChaCha20_Poly1305
\defgroup Crypto Callbacks - CryptoCb
\defgroup Curve25519 Algorithms - Curve25519
\defgroup Curve448 Algorithms - Curve448
\defgroup DSA Algorithms - DSA
\defgroup Diffie-Hellman Algorithms - Diffie-Hellman
\defgroup ECC Algorithms - ECC
\defgroup ED25519 Algorithms - ED25519
\defgroup ED448 Algorithms - ED448
\defgroup ECCSI_Overview Overview of ECCSI
ECCSI (Elliptic Curve-Based Certificateless Signatures for Identity-Based Encryption) is specified in RFC 6507 (https://tools.ietf.org/html/rfc6507).
In Identity-Based cryptography, there is a Key Management Service that generates keys based on an identity for a client.
The private key (SSK) and public key (PVT) are delivered to the signer and the public key (PVT) only delivered to the verifier on request.\n\n
wolfCrypt offers the ability to:
-# Create KMS keys,
-# Generate signing key pairs,
-# Validate signing key pairs,
-# Sign messages and
-# Verify messages.
KMS:
-# Initialize ECCSI Key: wc_InitEccsiKey()
-# Make and save or load ECCSI Key:
-# wc_MakeEccsiKey(), wc_ExportEccsiKey(), wc_ExportEccsiPublicKey() or
-# wc_ImportEccsiKey()
-# Wait for request:
-# Receive signing ID from client.
-# Generate signing key pair from ID: wc_MakeEccsiPair()
-# Encode result:
-# For signer, signing key pair: wc_EncodeEccsiPair()
-# Send KPAK and result
-# Free ECCSI Key: wc_FreeEccsiKey()
Client, signer:
-# Initialize ECCSI Key: wc_InitEccsiKey()
-# (When signing pair not cached) Request KPAK and signing pair from KMS
-# Send signing ID to KMS.
-# Receive signing key pair from KMS.
-# Load KMS Public Key: wc_ImportEccsiPublicKey()
-# Decode signing key pair: wc_DecodeEccsiPair()
-# Validate the key pair: wc_ValidateEccsiPair()
-# (If not done above) Load KMS Public Key: wc_ImportEccsiPublicKey()
-# (If not cached) Calculate hash of the ID and PVT: wc_HashEccsiId()
-# For each message:
-# Set Hash of Identity: wc_SetEccsiHash()
-# Sign message: wc_SignEccsiHash()
-# Send hash ID, message and signature to peer.
-# Free ECCSI Key: wc_FreeEccsiKey()
Client, verifier:
-# Receive hash ID, message and signature from signer.
-# Request KPAK (if not cached) and PVT (if not cached) for hash ID from KMS.
-# Receive KPAK (if not cached) and PVT (if not cached) for hash ID from KMS.
-# Initialize ECCSI Key: wc_InitEccsiKey()
-# Load KMS Public Key: wc_ImportEccsiPublicKey()
-# Decode PVT: wc_DecodeEccsiPvtFromSig()
-# Calculate hash of the ID and PVT: wc_HashEccsiId()
-# Set ECCSI key pair: wc_SetEccsiPair()
-# Verify signature of message: wc_VerifyEccsiHash()
-# Free ECCSI Key: wc_FreeEccsiKey()
\defgroup ECCSI_Setup Setup ECCSI Key
Operations for establinshing an ECCSI key.
Initialize ECCSI Key before use (wc_InitEccsiKey()).\n
Initialize ECCSI Key before use (wc_InitEccsiKey_ex()) for use with a curve other than P256.\n
Either make a new key (wc_MakeEccsiKey()), import an existing key (wc_ImportEccsiKey()) or import existing private key (wc_ImportEccsiPrivateKey()) and public key (wc_ImportEccsiPublicKey()).\n
Export the key (wc_ExportEccsiKey()) after making a new key for future use.\n
Export the private key (wc_ExportEccsiPrivateKey()) after making a new key for future use.\n
Export the public key (wc_ExportEccsiPublicKey()) from KMS to pass to client.\n
Import the public key (wc_ImportEccsiPublicKey()) into client.\n
Free the ECCSI Key (wc_FreeEccsiKey()) when finished.
\defgroup ECCSI_Operations Operations for Signing and Verifying with ECCSI Key
These operations are for signing and verifying with ECCSI keys.
Make an ECCSI key pair (wc_MakeEccsiPair()) with the signer's ID for use when signing.\n
Validate the ECCSI key pair (wc_ValidateEccsiPair()) with the signer's ID.\n
Validate the ECCSI Public Validation Token (PVT) (wc_ValidateEccsiPvt()).\n
Encode the ECCSI key pair (wc_EncodeEccsiPair()) for transfer to client.\n
Encode the ECCSI SSK (wc_EncodeEccsiSsk()) for transfer to client.\n
Encode the ECCSI PVT (wc_EncodeEccsiPvt()) for transfer to verifier.\n
Decode the ECCSI key pair (wc_DecodeEccsiPair()) on client for signing.\n
Decode the ECCSI SSK (wc_DecodeEccsiSsk()) on client for signing.\n
Decode the ECCSI PVT (wc_DecodeEccsiPvt()) on client for signing.\n
Decode the ECCSI PVT from the signature (wc_DecodeEccsiPvtFromSig()) on client for verifying.\n
Calculate hash of the ID (wc_HashEccsiId()) for signing/verifying using ID and Public Validation Token (PVT).\n
Sign (wc_SignEccsiHash()) a message with the hash of the ID and the Secret Signing Key (SSK) and Public Validation Token (PVT).\n
Verify (wc_VerifyEccsiHash()) a message with the hash of the signer's ID.
\defgroup SAKKE_Overview Overview of SAKKE Key
SAKKE (Sakai-Kasahara Key Encryption) is specified in RFC 6508 (https://tools.ietf.org/html/rfc6508).
SAKKE is used to transfer a secret to a peer using Identity Based cryptography.\n
The Key Management Service (KMS) is responsible for issuing Receiver Secret %Keys (RSKs).
Data up to (2^hashlen)^hashlen bytes of data can be transferred.\n
The sender must know the identity of the receiver and the KMS Public Key.\n
The receiver must have obtained a Receiver Secret Key (RSK) for the identity from a KMS in order to derive the secret.
KMS:
-# Initialize SAKKE Key: wc_InitSakkeKey()
-# Make and save or load SAKKE Key:
-# wc_MakeSakkeKey(), wc_ExportSakkeKey(), wc_ExportSakkePublicKey() or
-# wc_ImportSakkeKey()
-# Wait for request:
-# Make an RSK base on ID for the client: wc_MakeSakkeRsk()
-# Encode RSK for transfer to client: wc_EncodeSakkeRsk()
-# Free SAKKE Key: wc_FreeSakkeKey()
Key Exchange, Peer A:
-# Initialize SAKKE Key: wc_InitSakkeKey()
-# Load KMS Public Key: wc_ImportSakkePublicKey()
-# Generate a random SSV: wc_GenerateSakkeSSV()
-# Set the identity of Peer B: wc_SetSakkeIdentity()
-# Make an encapsulated SSV and auth data: wc_MakeSakkeEncapsulatedSSV()
-# Send encapsulated data to Peer B
-# Free SAKKE Key: wc_FreeSakkeKey()
Key Exchange, Peer B:
-# Receive encapsulated data.
-# Initialize SAKKE Key: wc_InitSakkeKey()
-# Load KMS Public Key: wc_ImportSakkePublicKey()
-# Decode RSK transferred from KMS or stored locally: wc_DecodeSakkeRsk()
-# [Optional] Validate RSK before first use: wc_ValidateSakkeRsk()
-# Set the identity: wc_SetSakkeIdentity()
-# Set the RSK and, optionally precomputation table: wc_SetSakkeRsk()
-# Derive SSV with auth data: wc_DeriveSakkeSSV()
-# Free SAKKE Key: wc_FreeSakkeKey()
Transfer secret, Peer A:
-# Initialize SAKKE Key: wc_InitSakkeKey()
-# Load KMS Public Key: wc_ImportSakkePublicKey()
-# Set the identity of Peer B: wc_SetSakkeIdentity()
-# Make an encapsulation of the SSV and auth data: wc_MakeSakkeEncapsulatedSSV()
-# Send encapsulated data to Peer B
-# Free SAKKE Key: wc_FreeSakkeKey()
Transfer secret, Peer B:
-# Initialize SAKKE Key: wc_InitSakkeKey()
-# Load KMS Public Key: wc_ImportSakkePublicKey()
-# Decode RSK transferred from KMS or stored locally: wc_DecodeSakkeRsk()
-# [Optional] Validate RSK before first use: wc_ValidateSakkeRsk()
-# Receive encapsulated data.
-# Set the identity: wc_SetSakkeIdentity()
-# Set the RSK and, optionally precomputation table: wc_SetSakkeRsk()
-# Derive SSV and auth data: wc_DeriveSakkeSSV()
-# Free SAKKE Key: wc_FreeSakkeKey()
\defgroup SAKKE_Setup Setup SAKKE Key
Operations for establishing a SAKKE key.
Initialization SAKKE Key before use (wc_InitSakkeKey() or wc_InitSakkeKey_ex()).\n
Either make a new key (wc_MakeSakkeKey()) or import an existing key (wc_ImportSakkeKey()).\n
Export the key (wc_ExportSakkeKey()) after making a new key for future use.\n
If only the private part of the KMS SAKKE Key is available, make the public key (wc_MakeSakkePublicKey()).\n
Export the private key (wc_ExportSakkePrivateKey()) from KMS from storage.\n
Import the private key (wc_ImportSakkePrivateKey()) into KMS from storage.\n
Export the public key (wc_ExportSakkePublicKey()) from KMS to pass to client.\n
Import the public key (wc_ImportSakkePublicKey()) into client.\n
Set the identity to use (wc_SetSakkeIdentity()) into client.\n
Free the SAKKE Key (wc_FreeSakkeKey()) when finished.
\defgroup SAKKE_RSK Operations on/with SAKKE RSK
These operations make, validate, encode and decode a Receiver Secret Key (RSK).
An RSK is required to derive an SSV (see wc_DeriveSakkeSSV()).\n
On the KMS, make an RSK (wc_MakeSakkeRsk()) from the client's ID.\n
On the client, validate the RSK (wc_ValidateSakkeRsk()) with the ID.\n
Encode the RSK (wc_EncodeSakkeRsk()) to pass to client or for storage.\n
Decode the RSK (wc_DecodeSakkeRsk()) on the client when needed.\n
Import the RSK (wc_ImportSakkeRsk()) on the client when needed.\n
Set the RSK and, optionally, a pre-computation table (wc_SetSakkeRsk()) on the client when needed.
\defgroup SAKKE_Operations Operations using SAKKE Key
These operations transfer a Shared Secret Value (SSV) from one client to another. The SSV may be randomly generated.
Calculate the size of the authentication data (wc_GetSakkeAuthSize()) to determine where the SSV starts in a buffer.\n
Make the intermediate point I (wc_MakeSakkePointI()) to speed making an encapsulated and deriving SSV.\n
Get intermediate point I (wc_GetSakkePointI()) for storage.\n
Set intermediate point I (wc_SetSakkePointI()) from storage.\n
Generate a pre-computation table for intermediate point I (wc_GenerateSakkePointITable()) to further enhance performance. Store as necessary.\n
Set the pre-computation table for intermediate point I (wc_SetSakkePointITable()) to further enhance performance.\n
Clear the pre-computation table for intermediate point I (wc_ClearSakkePointITable()) to remove reference to external table pointer.\n
Make an encapsulated SSV (wc_MakeSakkeEncapsulatedSSV()) to share with another client. Data in SSV is modified.\n
Generate a random SSV (wc_GenerateSakkeSSV()) for key exchange.\n
Derive the SSV, (wc_DeriveSakkeSSV()) on the recipient from the encapsulated SSV.
\defgroup HMAC Algorithms - HMAC
\defgroup MD2 Algorithms - MD2
\defgroup MD4 Algorithms - MD4
\defgroup MD5 Algorithms - MD5
\defgroup PKCS7 Algorithms - PKCS7
\defgroup PKCS11 Algorithms - PKCS11
\defgroup Password Algorithms - Password Based
\defgroup Poly1305 Algorithms - Poly1305
\defgroup RIPEMD Algorithms - RIPEMD
\defgroup RSA Algorithms - RSA
\defgroup SHA Algorithms - SHA 128/224/256/384/512
\defgroup SipHash Algorithm - SipHash
\defgroup SRP Algorithms - SRP
\defgroup ASN ASN.1
\defgroup Base_Encoding Base Encoding
\defgroup CertManager CertManager API
\defgroup Compression Compression
\defgroup Error Error Reporting
\defgroup IoTSafe IoT-Safe Module
IoT-Safe (IoT-SIM Applet For Secure End-2-End Communication) is a technology that leverage the SIM as robust,
scalable and standardized hardware Root of Trust to protect data communication.
IoT-Safe SSL sessions use the SIM as Hardware Security Module, offloading all the crypto public
key operations and reducing the attack surface by restricting access to certificate and keys
to the SIM.
IoT-Safe support can be enabled on an existing WOLFSSL_CTX contex, using wolfSSL_CTX_iotsafe_enable().\n
Session created within the context can set the parameters for IoT-Safe key and files usage, and enable
the public keys callback, with wolfSSL_iotsafe_on().
If compiled in, the module supports IoT-Safe random number generator as source of entropy for wolfCrypt.
\defgroup PSA Platform Security Architecture (PSA) API
\defgroup Keys Key and Cert Conversion
\defgroup Logging Logging
\defgroup Math Math API
\defgroup Memory Memory Handling
\defgroup Random Random Number Generation
\defgroup Signature Signature API
\defgroup openSSL OpenSSL API
\defgroup wolfCrypt wolfCrypt Init and Cleanup
\defgroup TLS wolfSSL Initialization/Shutdown
\defgroup CertsKeys wolfSSL Certificates and Keys
\defgroup Setup wolfSSL Context and Session Set Up
\defgroup IO wolfSSL Connection, Session, and I/O
\defgroup Debug wolfSSL Error Handling and Reporting
*/

View File

@@ -0,0 +1,75 @@
/*!
\page wolfssl_API wolfSSL API Reference
- \ref CertManager
- \ref Memory
- \ref openSSL
- \ref CertsKeys
- \ref IO
- \ref Setup
- \ref Debug
- \ref TLS
*/
/*!
\page wolfcrypt_API wolfCrypt API Reference
<ul>
<li>\ref ASN</li>
<li>\ref Base_Encoding</li>
<li>\ref Compression</li>
<li>\ref Error</li>
<li>\ref IoTSafe</li>
<li>\ref PSA</li>
<li>\ref Keys</li>
<li>\ref Logging</li>
<li>\ref Math</li>
<li>\ref Random</li>
<li>\ref Signature</li>
<li>\ref wolfCrypt</li>
</ul>
<ul>
<li>\ref DES</li>
<li>\ref AES</li>
<li>\ref ARC4</li>
<li>\ref BLAKE2</li>
<li>\ref Camellia</li>
<li>\ref ChaCha</li>
<li>\ref ChaCha20Poly1305</li>
<li>\ref Crypto Callbacks</li>
<li>\ref Curve25519</li>
<li>\ref Curve448</li>
<li>\ref DSA</li>
<li>\ref Diffie-Hellman</li>
<li>\ref ECC</li>
<li>\ref ED25519</li>
<li>\ref ED448</li>
<li>\ref ECCSI</li>
<li>\ref SAKKE</li>
<li>\ref HMAC</li>
<li>\ref MD2</li>
<li>\ref MD4</li>
<li>\ref MD5</li>
<li>\ref Password</li>
<li>\ref PKCS7</li>
<li>\ref PKCS11</li>
<li>\ref Poly1305</li>
<li>\ref RIPEMD</li>
<li>\ref RSA</li>
<li>\ref SHA</li>
<li>\ref SipHash</li>
<li>\ref SRP</li>
</ul>
*/
/*!
\page ECCSI ECCSI API Reference
- \ref ECCSI_Overview
- \ref ECCSI_Setup
- \ref ECCSI_Operations
*/
/*!
\page SAKKE SAKKE API Reference
- \ref SAKKE_Overview
- \ref SAKKE_Setup
- \ref SAKKE_RSK
- \ref SAKKE_Operations
*/

View File

@@ -0,0 +1,237 @@
/*!
\ingroup DSA
\brief この関数は、デジタル署名アルゴリズムDSAを介した認証に使用するためにDSAKEYオブジェクトを初期化します。
\return 0 成功に戻りました。
\return BAD_FUNC_ARG NULLキーが渡された場合に返されます。
_Example_
\code
DsaKey key;
int ret;
ret = wc_InitDsaKey(&key); // initialize DSA key
\endcode
\sa wc_FreeDsaKey
*/
int wc_InitDsaKey(DsaKey* key);
/*!
\ingroup DSA
\brief この関数は、使用された後にdsakeyオブジェクトを解放します。
\return none いいえ返します。
_Example_
\code
DsaKey key;
// initialize key, use for authentication
...
wc_FreeDsaKey(&key); // free DSA key
\endcode
\sa wc_FreeDsaKey
*/
void wc_FreeDsaKey(DsaKey* key);
/*!
\ingroup DSA
\brief この機能は入力ダイジェストに署名し、結果を出力バッファーに格納します。
\return 0 入力ダイジェストに正常に署名したときに返されました
\return MP_INIT_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_READ_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_CMP_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_INVMOD_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_EXPTMOD_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_MOD_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_MUL_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_ADD_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_MULMOD_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_TO_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_MEM DSA署名の処理にエラーがある場合は返される可能性があります。
\param digest 署名するハッシュへのポインタ
\param out 署名を保存するバッファへのポインタ
\param key 署名を生成するための初期化されたDsakey構造へのポインタ
_Example_
\code
DsaKey key;
// initialize DSA key, load private Key
int ret;
WC_RNG rng;
wc_InitRng(&rng);
byte hash[] = { // initialize with hash digest };
byte signature[40]; // signature will be 40 bytes (320 bits)
ret = wc_DsaSign(hash, signature, &key, &rng);
if (ret != 0) {
// error generating DSA signature
}
\endcode
\sa wc_DsaVerify
*/
int wc_DsaSign(const byte* digest, byte* out,
DsaKey* key, WC_RNG* rng);
/*!
\ingroup DSA
\brief この関数は、秘密鍵を考えると、ダイジェストの署名を検証します。回答パラメータでキーが正しく検証されているかどうか、正常な検証に対応する1、および失敗した検証に対応する0が格納されます。
\return 0 検証要求の処理に成功したときに返されます。注:これは、署名が検証されていることを意味するわけではなく、関数が成功したというだけです。
\return MP_INIT_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_READ_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_CMP_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_INVMOD_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_EXPTMOD_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_MOD_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_MUL_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_ADD_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_MULMOD_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_TO_E DSA署名の処理にエラーがある場合は返される可能性があります。
\return MP_MEM DSA署名の処理にエラーがある場合は返される可能性があります。
\param digest 署名の主題を含むダイジェストへのポインタ
\param sig 確認する署名を含むバッファへのポインタ
\param key 署名を検証するための初期化されたDsakey構造へのポインタ
_Example_
\code
DsaKey key;
// initialize DSA key, load public Key
int ret;
int verified;
byte hash[] = { // initialize with hash digest };
byte signature[] = { // initialize with signature to verify };
ret = wc_DsaVerify(hash, signature, &key, &verified);
if (ret != 0) {
// error processing verify request
} else if (answer == 0) {
// invalid signature
}
\endcode
\sa wc_DsaSign
*/
int wc_DsaVerify(const byte* digest, const byte* sig,
DsaKey* key, int* answer);
/*!
\ingroup DSA
\brief この機能は、DSA公開鍵を含むDERフォーマットの証明書バッファを復号し、与えられたDSakey構造体にキーを格納します。また、入力読み取りの長さに応じてINOUTIDXパラメータを設定します。
\return 0 dsakeyオブジェクトの公開鍵を正常に設定する
\return ASN_PARSE_E 証明書バッファを読みながらエンコーディングにエラーがある場合
\return ASN_DH_KEY_E DSAパラメータの1つが誤ってフォーマットされている場合に返されます
\param input DERフォーマットDSA公開鍵を含むバッファへのポインタ
\param inOutIdx 証明書の最後のインデックスを保存する整数へのポインタ
\param key 公開鍵を保存するDsakey構造へのポインタ
_Example_
\code
int ret, idx=0;
DsaKey key;
wc_InitDsaKey(&key);
byte derBuff[] = { // DSA public key};
ret = wc_DsaPublicKeyDecode(derBuff, &idx, &key, inSz);
if (ret != 0) {
// error reading public key
}
\endcode
\sa wc_InitDsaKey
\sa wc_DsaPrivateKeyDecode
*/
int wc_DsaPublicKeyDecode(const byte* input, word32* inOutIdx,
DsaKey* key, word32 inSz);
/*!
\ingroup DSA
\brief この機能は、DSA秘密鍵を含むDERフォーマットの証明書バッファをデコードし、指定されたDSakey構造体にキーを格納します。また、入力読み取りの長さに応じてINOUTIDXパラメータを設定します。
\return 0 dsakeyオブジェクトの秘密鍵を正常に設定するに返されました
\return ASN_PARSE_E 証明書バッファを読みながらエンコーディングにエラーがある場合
\return ASN_DH_KEY_E DSAパラメータの1つが誤ってフォーマットされている場合に返されます
\param input DERフォーマットDSA秘密鍵を含むバッファへのポインタ
\param inOutIdx 証明書の最後のインデックスを保存する整数へのポインタ
\param key 秘密鍵を保存するDSakey構造へのポインタ
_Example_
\code
int ret, idx=0;
DsaKey key;
wc_InitDsaKey(&key);
byte derBuff[] = { // DSA private key };
ret = wc_DsaPrivateKeyDecode(derBuff, &idx, &key, inSz);
if (ret != 0) {
// error reading private key
}
\endcode
\sa wc_InitDsaKey
\sa wc_DsaPublicKeyDecode
*/
int wc_DsaPrivateKeyDecode(const byte* input, word32* inOutIdx,
DsaKey* key, word32 inSz);
/*!
\ingroup DSA
\brief DSAKEYキーをDERフォーマット、出力への書き込みInlen、書き込まれたバイトを返します。
\return outLen 成功、書かれたバイト数
\return BAD_FUNC_ARG キーまたは出力はNULLまたはキー - >タイプがDSA_PRIVATEではありません。
\return MEMORY_E メモリの割り当て中にエラーが発生しました。
\param key 変換するdsakey構造へのポインタ。
\param output 変換キーの出力バッファへのポインタ。
_Example_
\code
DsaKey key;
WC_RNG rng;
int derSz;
int bufferSize = // Sufficient buffer size;
byte der[bufferSize];
wc_InitDsaKey(&key);
wc_InitRng(&rng);
wc_MakeDsaKey(&rng, &key);
derSz = wc_DsaKeyToDer(&key, der, bufferSize);
\endcode
\sa wc_InitDsaKey
\sa wc_FreeDsaKey
\sa wc_MakeDsaKey
*/
int wc_DsaKeyToDer(DsaKey* key, byte* output, word32 inLen);
/*!
\ingroup DSA
\brief DSAキーを作成します。
\return MP_OKAY 成功
\return BAD_FUNC_ARG RNGまたはDSAのどちらかがnullです。
\return MEMORY_E バッファにメモリを割り当てることができませんでした。
\return MP_INIT_E MP_INTの初期化エラー
\param rng WC_RNG構造体へのポインタ。
_Example_
\code
WC_RNG rng;
DsaKey dsa;
wc_InitRng(&rng);
wc_InitDsa(&dsa);
if(wc_MakeDsaKey(&rng, &dsa) != 0)
{
// Error creating key
}
\endcode
\sa wc_InitDsaKey
\sa wc_FreeDsaKey
\sa wc_DsaSign
*/
int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa);
/*!
\ingroup DSA
\brief FIPS 186-4は、modulus_size値の有効な値を定義します1024,1602048,2563072,256
\return 0 成功
\return BAD_FUNC_ARG RNGまたはDSAはNULLまたはMODULUS_SIZEが無効です。
\return MEMORY_E メモリを割り当てようとするエラーが発生しました。
\param rng WolfCrypt RNGへのポインタ。
\param modulus_size 1024,2048、または3072は有効な値です。
_Example_
\code
DsaKey key;
WC_RNG rng;
wc_InitDsaKey(&key);
wc_InitRng(&rng);
if(wc_MakeDsaParameters(&rng, 1024, &genKey) != 0)
{
// Handle error
}
\endcode
\sa wc_MakeDsaKey
\sa wc_DsaKeyToDer
\sa wc_InitDsaKey
*/
int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,106 @@
/*!
*/
int wc_InitEccsiKey(EccsiKey* key, void* heap, int devId);
/*!
*/
int wc_InitEccsiKey_ex(EccsiKey* key, int keySz, int curveId,
void* heap, int devId);
/*!
*/
void wc_FreeEccsiKey(EccsiKey* key);
/*!
*/
int wc_MakeEccsiKey(EccsiKey* key, WC_RNG* rng);
/*!
*/
int wc_MakeEccsiPair(EccsiKey* key, WC_RNG* rng,
enum wc_HashType hashType, const byte* id, word32 idSz, mp_int* ssk,
ecc_point* pvt);
/*!
*/
int wc_ValidateEccsiPair(EccsiKey* key, enum wc_HashType hashType,
const byte* id, word32 idSz, const mp_int* ssk, ecc_point* pvt,
int* valid);
/*!
*/
int wc_ValidateEccsiPvt(EccsiKey* key, const ecc_point* pvt,
int* valid);
/*!
*/
int wc_EncodeEccsiPair(const EccsiKey* key, mp_int* ssk,
ecc_point* pvt, byte* data, word32* sz);
/*!
*/
int wc_EncodeEccsiSsk(const EccsiKey* key, mp_int* ssk, byte* data,
word32* sz);
/*!
*/
int wc_EncodeEccsiPvt(const EccsiKey* key, ecc_point* pvt,
byte* data, word32* sz, int raw);
/*!
*/
int wc_DecodeEccsiPair(const EccsiKey* key, const byte* data,
word32 sz, mp_int* ssk, ecc_point* pvt);
/*!
*/
int wc_DecodeEccsiSsk(const EccsiKey* key, const byte* data,
word32 sz, mp_int* ssk);
/*!
*/
int wc_DecodeEccsiPvt(const EccsiKey* key, const byte* data,
word32 sz, ecc_point* pvt);
/*!
*/
int wc_DecodeEccsiPvtFromSig(const EccsiKey* key, const byte* sig,
word32 sz, ecc_point* pvt);
/*!
*/
int wc_ExportEccsiKey(EccsiKey* key, byte* data, word32* sz);
/*!
*/
int wc_ImportEccsiKey(EccsiKey* key, const byte* data, word32 sz);
/*!
*/
int wc_ExportEccsiPrivateKey(EccsiKey* key, byte* data, word32* sz);
/*!
*/
int wc_ImportEccsiPrivateKey(EccsiKey* key, const byte* data,
word32 sz);
/*!
*/
int wc_ExportEccsiPublicKey(EccsiKey* key, byte* data, word32* sz,
int raw);
/*!
*/
int wc_ImportEccsiPublicKey(EccsiKey* key, const byte* data,
word32 sz, int trusted);
/*!
*/
int wc_HashEccsiId(EccsiKey* key, enum wc_HashType hashType,
const byte* id, word32 idSz, ecc_point* pvt, byte* hash, byte* hashSz);
/*!
*/
int wc_SetEccsiHash(EccsiKey* key, const byte* hash, byte hashSz);
/*!
*/
int wc_SetEccsiPair(EccsiKey* key, const mp_int* ssk,
const ecc_point* pvt);
/*!
*/
int wc_SignEccsiHash(EccsiKey* key, WC_RNG* rng,
enum wc_HashType hashType, const byte* msg, word32 msgSz, byte* sig,
word32* sigSz);
/*!
*/
int wc_VerifyEccsiHash(EccsiKey* key, enum wc_HashType hashType,
const byte* msg, word32 msgSz, const byte* sig, word32 sigSz,
int* verified);

View File

@@ -0,0 +1,719 @@
/*!
\ingroup ED25519
\brief この関数は秘密鍵からED25519公開鍵を生成します。公開鍵をバッファPubkeyに格納し、Pubkeyszでこのバッファに書き込まれたバイトを設定します。
\return 0 公開鍵の作成に成功したときに返されます。
\return BAD_FUNC_ARG IFIキーまたはPubKeyがNULLに評価された場合、または指定されたキーサイズが32バイトではない場合ED25519に32バイトのキーがあります
\return MEMORY_E 関数の実行中にメモリを割り当てるエラーがある場合に返されます。
\param [in] キーを生成するED25519_Keyへのキーポインタ。
\param [out] 公開鍵を保存するバッファへのポインタ。
_Example_
\code
int ret;
ed25519_key key;
byte priv[] = { initialize with 32 byte private key };
byte pub[32];
word32 pubSz = sizeof(pub);
wc_ed25519_init(&key);
wc_ed25519_import_private_only(priv, sizeof(priv), &key);
ret = wc_ed25519_make_public(&key, pub, &pubSz);
if (ret != 0) {
// error making public key
}
\endcode
\sa wc_ed25519_init
\sa wc_ed25519_import_private_only
\sa wc_ed25519_make_key
*/
int wc_ed25519_make_public(ed25519_key* key, unsigned char* pubKey,
word32 pubKeySz);
/*!
\ingroup ED25519
\brief この関数は新しいED25519キーを生成し、それをキーに格納します。
\return 0 ED25519_KEYを正常に行うと返されます。
\return BAD_FUNC_ARG RNGまたはKEYがNULLに評価された場合、または指定されたキーサイズが32バイトではない場合ED25519に32バイトのキーがあります
\return MEMORY_E 関数の実行中にメモリを割り当てるエラーがある場合に返されます。
\param [in] RNGキーを生成する初期化されたRNGオブジェクトへのポインタ。
\param [in] keysize keyの長さを生成します。ED25519の場合は常に32になります。
_Example_
\code
int ret;
WC_RNG rng;
ed25519_key key;
wc_InitRng(&rng);
wc_ed25519_init(&key);
wc_ed25519_make_key(&rng, 32, &key);
if (ret != 0) {
// error making key
}
\endcode
\sa wc_ed25519_init
*/
int wc_ed25519_make_key(WC_RNG* rng, int keysize, ed25519_key* key);
/*!
\ingroup ED25519
\brief この関数は、ED25519_Keyオブジェクトを使用して認証を保証するメッセージに署名します。
\return 0 メッセージの署名を正常に生成すると返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLに評価された場合、または出力バッファが小さすぎて生成された署名を保存する場合は返されます。
\return MEMORY_E 関数の実行中にメモリを割り当てるエラーがある場合に返されます。
\param [in] 署名するメッセージを含むバッファへのポインタ。
\param [in] 署名するメッセージのインレル長。
\param [out] 生成された署名を格納するためのバッファー。
\param [in,out] 出力バッファの最大長の範囲内。メッセージ署名の生成に成功したときに、書き込まれたバイトを保存します。
_Example_
\code
ed25519_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[64]; // will hold generated signature
sigSz = sizeof(sig);
byte message[] = { initialize with message };
wc_InitRng(&rng); // initialize rng
wc_ed25519_init(&key); // initialize key
wc_ed25519_make_key(&rng, 32, &key); // make public/private key pair
ret = wc_ed25519_sign_msg(message, sizeof(message), sig, &sigSz, &key);
if (ret != 0) {
// error generating message signature
}
\endcode
\sa wc_ed25519ctx_sign_msg
\sa wc_ed25519ph_sign_hash
\sa wc_ed25519ph_sign_msg
\sa wc_ed25519_verify_msg
*/
int wc_ed25519_sign_msg(const byte* in, word32 inlen, byte* out,
word32 *outlen, ed25519_key* key);
/*!
\ingroup ED25519
\brief この関数は、ED25519_Keyオブジェクトを使用して認証を保証するメッセージに署名します。コンテキストは署名されたデータの一部です。
\return 0 メッセージの署名を正常に生成すると返されます。
\return BAD_FUNC_ARG 返された入力パラメータはNULLに評価されます。出力バッファが小さすぎて生成された署名を保存するには小さすぎます。
\return MEMORY_E 関数の実行中にメモリを割り当てるエラーがある場合に返されます。
\param [in] 署名するメッセージを含むバッファへのポインタ。
\param [in] 署名するメッセージのインレル長。
\param [out] 生成された署名を格納するためのバッファー。
\param [in,out] 出力バッファの最大長の範囲内。メッセージ署名の生成に成功したときに、書き込まれたバイトを保存します。
\param [in] 署名を生成するプライベートED25519_KEYへのキーポインタ。
\param [in] メッセージが署名されているコンテキストを含むバッファへのコンテキストポインタ。
_Example_
\code
ed25519_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[64]; // will hold generated signature
sigSz = sizeof(sig);
byte message[] = { initialize with message };
byte context[] = { initialize with context of signing };
wc_InitRng(&rng); // initialize rng
wc_ed25519_init(&key); // initialize key
wc_ed25519_make_key(&rng, 32, &key); // make public/private key pair
ret = wc_ed25519ctx_sign_msg(message, sizeof(message), sig, &sigSz, &key,
context, sizeof(context));
if (ret != 0) {
// error generating message signature
}
\endcode
\sa wc_ed25519_sign_msg
\sa wc_ed25519ph_sign_hash
\sa wc_ed25519ph_sign_msg
\sa wc_ed25519_verify_msg
*/
int wc_ed25519ctx_sign_msg(const byte* in, word32 inlen, byte* out,
word32 *outlen, ed25519_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED25519
\brief この関数は、ED25519_Keyオブジェクトを使用してメッセージダイジェストに署名して信頼性を保証します。コンテキストは署名されたデータの一部として含まれています。署名計算の前にメッセージは事前にハッシュされています。メッセージダイジェストを作成するために使用されるハッシュアルゴリズムはShake-256でなければなりません。
\return 0 メッセージダイジェストの署名を正常に生成すると返されます。
\return BAD_FUNC_ARG 返された入力パラメータはNULLに評価されます。出力バッファが小さすぎて生成された署名を保存するには小さすぎます。
\return MEMORY_E 関数の実行中にメモリを割り当てるエラーがある場合に返されます。
\param [in] サインへのメッセージのハッシュを含むバッファへのハッシュポインタ。
\param [in] サインへのメッセージのハッシュのハッシュの長さ。
\param [out] 生成された署名を格納するためのバッファー。
\param [in,out] 出力バッファの最大長の範囲内。メッセージ署名の生成に成功したときに、書き込まれたバイトを保存します。
\param [in] 署名を生成するプライベートED25519_KEYへのキーポインタ。
\param [in] メッセージが署名されているコンテキストを含むバッファへのコンテキストポインタ。
_Example_
\code
ed25519_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[64]; // will hold generated signature
sigSz = sizeof(sig);
byte hash[] = { initialize with SHA-512 hash of message };
byte context[] = { initialize with context of signing };
wc_InitRng(&rng); // initialize rng
wc_ed25519_init(&key); // initialize key
wc_ed25519_make_key(&rng, 32, &key); // make public/private key pair
ret = wc_ed25519ph_sign_hash(hash, sizeof(hash), sig, &sigSz, &key,
context, sizeof(context));
if (ret != 0) {
// error generating message signature
}
\endcode
\sa wc_ed25519_sign_msg
\sa wc_ed25519ctx_sign_msg
\sa wc_ed25519ph_sign_msg
\sa wc_ed25519_verify_msg
*/
int wc_ed25519ph_sign_hash(const byte* hash, word32 hashLen, byte* out,
word32 *outLen, ed25519_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED25519
\brief この関数は、ED25519_Keyオブジェクトを使用して認証を保証するメッセージに署名します。コンテキストは署名されたデータの一部として含まれています。署名計算の前にメッセージは事前にハッシュされています。
\return 0 メッセージの署名を正常に生成すると返されます。
\return BAD_FUNC_ARG 返された入力パラメータはNULLに評価されます。出力バッファが小さすぎて生成された署名を保存するには小さすぎます。
\return MEMORY_E 関数の実行中にメモリを割り当てるエラーがある場合に返されます。
\param [in] 署名するメッセージを含むバッファへのポインタ。
\param [in] 署名するメッセージのインレル長。
\param [out] 生成された署名を格納するためのバッファー。
\param [in,out] 出力バッファの最大長の範囲内。メッセージ署名の生成に成功したときに、書き込まれたバイトを保存します。
\param [in] 署名を生成するプライベートED25519_KEYへのキーポインタ。
\param [in] メッセージが署名されているコンテキストを含むバッファへのコンテキストポインタ。
_Example_
\code
ed25519_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[64]; // will hold generated signature
sigSz = sizeof(sig);
byte message[] = { initialize with message };
byte context[] = { initialize with context of signing };
wc_InitRng(&rng); // initialize rng
wc_ed25519_init(&key); // initialize key
wc_ed25519_make_key(&rng, 32, &key); // make public/private key pair
ret = wc_ed25519ph_sign_msg(message, sizeof(message), sig, &sigSz, &key,
context, sizeof(context));
if (ret != 0) {
// error generating message signature
}
\endcode
\sa wc_ed25519_sign_msg
\sa wc_ed25519ctx_sign_msg
\sa wc_ed25519ph_sign_hash
\sa wc_ed25519_verify_msg
*/
int wc_ed25519ph_sign_msg(const byte* in, word32 inlen, byte* out,
word32 *outlen, ed25519_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED25519
\brief この関数はメッセージのED25519署名を確認して信頼性を確保します。RESを介して答えを返し、有効な署名に対応する1、無効な署名に対応する0を返します。
\return 0 署名検証と認証を正常に実行したときに返されます。
\return BAD_FUNC_ARG いずれかの入力パラメータがNULLに評価された場合、またはSIGLENが署名の実際の長さと一致しない場合に返されます。
\return SIG_VERIFY_E 検証が完了した場合は返されますが、生成された署名は提供された署名と一致しません。
\param [in] 検証するシグネチャを含むバッファへのSIGポインタ。
\param [in] 検証するシグネチャのシグレンの長さ。
\param [in] メッセージを含むバッファへのMSGポインタを確認する。
\param [in] 検証するメッセージのMSGlen長。
\param [out] 検証の結果へのRESポインタ。1メッセージが正常に検証されたことを示します。
_Example_
\code
ed25519_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte msg[] = { initialize with message };
// initialize key with received public key
ret = wc_ed25519_verify_msg(sig, sizeof(sig), msg, sizeof(msg), &verified,
&key);
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
\endcode
\sa wc_ed25519ctx_verify_msg
\sa wc_ed25519ph_verify_hash
\sa wc_ed25519ph_verify_msg
\sa wc_ed25519_sign_msg
*/
int wc_ed25519_verify_msg(const byte* sig, word32 siglen, const byte* msg,
word32 msgLen, int* ret, ed25519_key* key);
/*!
\ingroup ED25519
\brief この関数はメッセージのED25519署名を確認して信頼性を確保します。文脈はデータ検証済みの一部として含まれています。RESを介して答えを返し、有効な署名に対応する1、無効な署名に対応する0を返します。
\return 0 署名検証と認証を正常に実行したときに返されます。
\return BAD_FUNC_ARG いずれかの入力パラメータがNULLに評価された場合、またはSIGLENが署名の実際の長さと一致しない場合に返されます。
\return SIG_VERIFY_E 検証が完了した場合は返されますが、生成された署名は提供された署名と一致しません。
\param [in] 検証するシグネチャを含むバッファへのSIGポインタ。
\param [in] 検証するシグネチャのシグレンの長さ。
\param [in] メッセージを含むバッファへのMSGポインタを確認する。
\param [in] 検証するメッセージのMSGlen長。
\param [out] 検証の結果へのRESポインタ。1メッセージが正常に検証されたことを示します。
\param [in] 署名を検証するためのPublic ED25519キーへのキーポインタ。
\param [in] メッセージが署名されたコンテキストを含むバッファへのコンテキストポインタ。
_Example_
\code
ed25519_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte msg[] = { initialize with message };
byte context[] = { initialize with context of signature };
// initialize key with received public key
ret = wc_ed25519ctx_verify_msg(sig, sizeof(sig), msg, sizeof(msg),
&verified, &key, );
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
\endcode
\sa wc_ed25519_verify_msg
\sa wc_ed25519ph_verify_hash
\sa wc_ed25519ph_verify_msg
\sa wc_ed25519_sign_msg
*/
int wc_ed25519ctx_verify_msg(const byte* sig, word32 siglen, const byte* msg,
word32 msgLen, int* ret, ed25519_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED25519
\brief この関数は、メッセージのダイジェストのED25519シグネチャを確認して、信頼性を確保します。文脈はデータ検証済みの一部として含まれています。ハッシュは、署名計算前のプリハッシュメッセージです。メッセージダイジェストを作成するために使用されるハッシュアルゴリズムはSHA-512でなければなりません。答えはRESを介して返され、有効な署名に対応する1、無効な署名に対応する0を返します。
\return 0 署名検証と認証を正常に実行したときに返されます。
\return BAD_FUNC_ARG いずれかの入力パラメータがNULLに評価された場合、またはSIGLENが署名の実際の長さと一致しない場合に返されます。
\return SIG_VERIFY_E 検証が完了した場合は返されますが、生成された署名は提供された署名と一致しません。
\param [in] 検証するシグネチャを含むバッファへのSIGポインタ。
\param [in] 検証するシグネチャのシグレンの長さ。
\param [in] 検証するメッセージのハッシュを含むバッファへのハッシュポインタ。
\param [in] 検証するハッシュのハッシュレン長。
\param [out] 検証の結果へのRESポインタ。1メッセージが正常に検証されたことを示します。
\param [in] 署名を検証するためのPublic ED25519キーへのキーポインタ。
\param [in] メッセージが署名されたコンテキストを含むバッファへのコンテキストポインタ。
_Example_
\code
ed25519_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte hash[] = { initialize with SHA-512 hash of message };
byte context[] = { initialize with context of signature };
// initialize key with received public key
ret = wc_ed25519ph_verify_hash(sig, sizeof(sig), msg, sizeof(msg),
&verified, &key, );
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
\endcode
\sa wc_ed25519_verify_msg
\sa wc_ed25519ctx_verify_msg
\sa wc_ed25519ph_verify_msg
\sa wc_ed25519_sign_msg
*/
int wc_ed25519ph_verify_hash(const byte* sig, word32 siglen, const byte* hash,
word32 hashLen, int* ret, ed25519_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED25519
\brief この関数はメッセージのED25519署名を確認して信頼性を確保します。文脈はデータ検証済みの一部として含まれています。検証前にメッセージがプリハッシュされています。RESを介して答えを返し、有効な署名に対応する1、無効な署名に対応する0を返します。
\return 0 署名検証と認証を正常に実行したときに返されます。
\return BAD_FUNC_ARG いずれかの入力パラメータがNULLに評価された場合、またはSIGLENが署名の実際の長さと一致しない場合に返されます。
\return SIG_VERIFY_E 検証が完了した場合は返されますが、生成された署名は提供された署名と一致しません。
\param [in] 検証するシグネチャを含むバッファへのSIGポインタ。
\param [in] 検証するシグネチャのシグレンの長さ。
\param [in] メッセージを含むバッファへのMSGポインタを確認する。
\param [in] 検証するメッセージのMSGlen長。
\param [out] 検証の結果へのRESポインタ。1メッセージが正常に検証されたことを示します。
\param [in] 署名を検証するためのPublic ED25519キーへのキーポインタ。
\param [in] メッセージが署名されたコンテキストを含むバッファへのコンテキストポインタ。
_Example_
\code
ed25519_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte msg[] = { initialize with message };
byte context[] = { initialize with context of signature };
// initialize key with received public key
ret = wc_ed25519ctx_verify_msg(sig, sizeof(sig), msg, sizeof(msg),
&verified, &key, );
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
\endcode
\sa wc_ed25519_verify_msg
\sa wc_ed25519ph_verify_hash
\sa wc_ed25519ph_verify_msg
\sa wc_ed25519_sign_msg
*/
int wc_ed25519ph_verify_msg(const byte* sig, word32 siglen, const byte* msg,
word32 msgLen, int* ret, ed25519_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED25519
\brief この関数は、メッセージ検証で将来の使用のためにED25519_Keyオブジェクトを初期化します。
\return 0 ED25519_Keyオブジェクトの初期化に成功したときに返されます。
\return BAD_FUNC_ARG キーがNULLの場合は返されます。
_Example_
\code
ed25519_key key;
wc_ed25519_init(&key);
\endcode
\sa wc_ed25519_make_key
\sa wc_ed25519_free
*/
int wc_ed25519_init(ed25519_key* key);
/*!
\ingroup ED25519
\brief この関数は、使用された後にED25519オブジェクトを解放します。
_Example_
\code
ed25519_key key;
// initialize key and perform secure exchanges
...
wc_ed25519_free(&key);
\endcode
\sa wc_ed25519_init
*/
void wc_ed25519_free(ed25519_key* key);
/*!
\ingroup ED25519
\brief この関数は、公開鍵を含むバッファからPublic ED25519_Keyペアをインポートします。この関数は圧縮キーと非圧縮キーの両方を処理します。
\return 0 ED25519_KEYのインポートに成功しました。
\return BAD_FUNC_ARG inまたはkeyがnullに評価された場合、またはInlenがED25519キーのサイズよりも小さい場合に返されます。
\param [in] 公開鍵を含むバッファへのポインタ。
\param [in] 公開鍵を含むバッファのインレル長。
_Example_
\code
int ret;
byte pub[] = { initialize Ed25519 public key };
ed_25519 key;
wc_ed25519_init_key(&key);
ret = wc_ed25519_import_public(pub, sizeof(pub), &key);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_ed25519_import_private_key
\sa wc_ed25519_export_public
*/
int wc_ed25519_import_public(const byte* in, word32 inLen, ed25519_key* key);
/*!
\ingroup ED25519
\brief この関数は、ed25519秘密鍵をバッファからのみインポートします。
\return 0 ED25519キーのインポートに成功しました。
\return BAD_FUNC_ARG INまたはKEYがNULLに評価された場合、またはPRIVSZがED25519_KEY_SIZEよりも小さい場合に返されます。
\param [in] 秘密鍵を含むバッファへのPRIVポインタ。
\param [in] 秘密鍵のPrivsz長さ。
\param [in] 公開鍵を含むバッファへのPubポインタ。
\param [in] 公開鍵のPubszの長さ。
_Example_
\code
int ret;
byte priv[] = { initialize with 32 byte private key };
ed25519_key key;
wc_ed25519_init_key(&key);
ret = wc_ed25519_import_private_key(priv, sizeof(priv), &key);
if (ret != 0) {
// error importing private key
}
\endcode
\sa wc_ed25519_import_public
\sa wc_ed25519_import_private_key
\sa wc_ed25519_export_private_only
*/
int wc_ed25519_import_private_only(const byte* priv, word32 privSz,
ed25519_key* key);
/*!
\ingroup ED25519
\brief この関数は、一対のバッファからパブリック/プライベートED25519キーペアをインポートします。この関数は圧縮キーと非圧縮キーの両方を処理します。
\return 0 ED25519_KEYのインポートに成功しました。
\return BAD_FUNC_ARG INまたはKEYがNULLに評価された場合、またはいずれかのPROVSZがED25519_SEY_SIZEまたはPUBSZよりも小さい場合は、ED25519_PUB_KEY_SIZEよりも小さい場合に返されます。
\param [in] 秘密鍵を含むバッファへのPRIVポインタ。
\param [in] 秘密鍵のPrivsz長さ。
\param [in] 公開鍵を含むバッファへのPubポインタ。
\param [in] 公開鍵のPubszの長さ。
_Example_
\code
int ret;
byte priv[] = { initialize with 32 byte private key };
byte pub[] = { initialize with the corresponding public key };
ed25519_key key;
wc_ed25519_init_key(&key);
ret = wc_ed25519_import_private_key(priv, sizeof(priv), pub, sizeof(pub),
&key);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_ed25519_import_public
\sa wc_ed25519_import_private_only
\sa wc_ed25519_export_private
*/
int wc_ed25519_import_private_key(const byte* priv, word32 privSz,
const byte* pub, word32 pubSz, ed25519_key* key);
/*!
\ingroup ED25519
\brief この関数は、秘密鍵をED25519_Key構造体からエクスポートします。公開鍵をバッファアウトに格納し、ounterenでこのバッファに書き込まれたバイトを設定します。
\return 0 公開鍵のエクスポートに成功したら返されます。
\return BAD_FUNC_ARG いずれかの入力値がNULLに評価された場合に返されます。
\return BUFFER_E 提供されたバッファーが秘密鍵を保存するのに十分な大きさでない場合に返されます。このエラーを返すと、outlenに必要なサイズを設定します。
\param [in] 公開鍵をエクスポートするためのED25519_Key構造体へのキーポインタ。
\param [out] 公開鍵を保存するバッファへのポインタ。
_Example_
\code
int ret;
ed25519_key key;
// initialize key, make key
char pub[32];
word32 pubSz = sizeof(pub);
ret = wc_ed25519_export_public(&key, pub, &pubSz);
if (ret != 0) {
// error exporting public key
}
\endcode
\sa wc_ed25519_import_public
\sa wc_ed25519_export_private_only
*/
int wc_ed25519_export_public(ed25519_key* key, byte* out, word32* outLen);
/*!
\ingroup ED25519
\brief この関数は、ED25519_Key構造体からの秘密鍵のみをエクスポートします。秘密鍵をバッファアウトに格納し、outlenにこのバッファに書き込まれたバイトを設定します。
\return 0 秘密鍵のエクスポートに成功したら返されます。
\return ECC_BAD_ARG_E いずれかの入力値がNULLに評価された場合に返されます。
\return BUFFER_E 提供されたバッファーが秘密鍵を保存するのに十分な大きさでない場合に返されます。
\param [in] 秘密鍵をエクスポートするためのED25519_Key構造体へのキーポインタ。
\param [out] 秘密鍵を保存するバッファへのポインタ。
_Example_
\code
int ret;
ed25519_key key;
// initialize key, make key
char priv[32]; // 32 bytes because only private key
word32 privSz = sizeof(priv);
ret = wc_ed25519_export_private_only(&key, priv, &privSz);
if (ret != 0) {
// error exporting private key
}
\endcode
\sa wc_ed25519_export_public
\sa wc_ed25519_import_private_key
*/
int wc_ed25519_export_private_only(ed25519_key* key, byte* out, word32* outLen);
/*!
\ingroup ED25519
\brief この関数は、ED25519_Key構造体からキーペアをエクスポートします。キーペアをバッファOUTに格納し、ounterenでこのバッファに書き込まれたバイトを設定します。
\return 0 キーペアのエクスポートに成功したら返されます。
\return ECC_BAD_ARG_E いずれかの入力値がNULLに評価された場合に返されます。
\return BUFFER_E 提供されているバッファーがキーペアを保存するのに十分な大きさでない場合に返されます。
\param [in] キーペアをエクスポートするためのED25519_Key構造体へのキーポインタ。
\param [out] キーペアを保存するバッファへのポインタ。
_Example_
\code
ed25519_key key;
wc_ed25519_init(&key);
WC_RNG rng;
wc_InitRng(&rng);
wc_ed25519_make_key(&rng, 32, &key); // initialize 32 byte Ed25519 key
byte out[64]; // out needs to be a sufficient buffer size
word32 outLen = sizeof(out);
int key_size = wc_ed25519_export_private(&key, out, &outLen);
if (key_size == BUFFER_E) {
// Check size of out compared to outLen to see if function reset outLen
}
\endcode
\sa wc_ed25519_import_private_key
\sa wc_ed25519_export_private_only
*/
int wc_ed25519_export_private(ed25519_key* key, byte* out, word32* outLen);
/*!
\ingroup ED25519
\brief この関数は、ED25519_KEY構造体とは別にプライベートキーと公開鍵をエクスポートします。秘密鍵をバッファーPrivに格納し、PRIVSZでこのバッファに書き込まれたバイトを設定します。公開鍵をバッファPUBに格納し、Pubszでこのバッファに書き込まれたバイトを設定します。
\return 0 キーペアのエクスポートに成功したら返されます。
\return ECC_BAD_ARG_E いずれかの入力値がNULLに評価された場合に返されます。
\return BUFFER_E 提供されているバッファーがキーペアを保存するのに十分な大きさでない場合に返されます。
\param [in] キーペアをエクスポートするためのED25519_Key構造体へのキーポインタ。
\param [out] 秘密鍵を保存するバッファへのPRIVポインタ。
\param [in,out] PRIVSZ PIVINSZポインタサイズが表示されているサイズを持つWord32オブジェクトへのポインタ。秘密鍵のエクスポート後に書き込まれたバイト数を設定します。
\param [out] パブリックキーを保存するバッファへのPub。
_Example_
\code
int ret;
ed25519_key key;
// initialize key, make key
char pub[32];
word32 pubSz = sizeof(pub);
char priv[32];
word32 privSz = sizeof(priv);
ret = wc_ed25519_export_key(&key, priv, &pubSz, pub, &pubSz);
if (ret != 0) {
// error exporting public key
}
\endcode
\sa wc_ed25519_export_private
\sa wc_ed25519_export_public
*/
int wc_ed25519_export_key(ed25519_key* key,
byte* priv, word32 *privSz,
byte* pub, word32 *pubSz);
/*!
\ingroup ED25519
\brief この関数は、ED25519_KEY構造体の公開鍵をチェックします。
\return 0 プライベートキーと公開鍵が一致した場合に返されます。
\return BAD_FUNC_ARGS 与えられたキーがNULLの場合に返されます。
_Example_
\code
int ret;
byte priv[] = { initialize with 57 byte private key };
byte pub[] = { initialize with the corresponding public key };
ed25519_key key;
wc_ed25519_init_key(&key);
wc_ed25519_import_private_key(priv, sizeof(priv), pub, sizeof(pub), &key);
ret = wc_ed25519_check_key(&key);
if (ret != 0) {
// error checking key
}
\endcode
\sa wc_ed25519_import_private_key
*/
int wc_ed25519_check_key(ed25519_key* key);
/*!
\ingroup ED25519
\brief この関数は、ED25519 - 32バイトのサイズを返します。
\return ED25519_KEY_SIZE 有効な秘密鍵のサイズ32バイト
\return BAD_FUNC_ARGS 与えられたキーがNULLの場合に返されます。
_Example_
\code
int keySz;
ed25519_key key;
// initialize key, make key
keySz = wc_ed25519_size(&key);
if (keySz == 0) {
// error determining key size
}
\endcode
\sa wc_ed25519_make_key
*/
int wc_ed25519_size(ed25519_key* key);
/*!
\ingroup ED25519
\brief この関数は、秘密鍵サイズsecret + publicをバイト単位で返します。
\return ED25519_PRV_KEY_SIZE 秘密鍵のサイズ64バイト
\return BAD_FUNC_ARG key引数がnullの場合に返されます。
_Example_
\code
ed25519_key key;
wc_ed25519_init(&key);
WC_RNG rng;
wc_InitRng(&rng);
wc_ed25519_make_key(&rng, 32, &key); // initialize 32 byte Ed25519 key
int key_size = wc_ed25519_priv_size(&key);
\endcode
\sa wc_ed25519_pub_size
*/
int wc_ed25519_priv_size(ed25519_key* key);
/*!
\ingroup ED25519
\brief この関数は圧縮鍵サイズをバイト単位で返します(公開鍵)。
\return ED25519_PUB_KEY_SIZE 圧縮公開鍵のサイズ32バイト
\return BAD_FUNC_ARG key引数がnullの場合は返します。
_Example_
\code
ed25519_key key;
wc_ed25519_init(&key);
WC_RNG rng;
wc_InitRng(&rng);
wc_ed25519_make_key(&rng, 32, &key); // initialize 32 byte Ed25519 key
int key_size = wc_ed25519_pub_size(&key);
\endcode
\sa wc_ed25519_priv_size
*/
int wc_ed25519_pub_size(ed25519_key* key);
/*!
\ingroup ED25519
\brief この関数は、ED25519シグネチャのサイズバイト数64を返します。
\return ED25519_SIG_SIZE ED25519シグネチャ64バイトのサイズ。
\return BAD_FUNC_ARG key引数がnullの場合は返します。
_Example_
\code
int sigSz;
ed25519_key key;
// initialize key, make key
sigSz = wc_ed25519_sig_size(&key);
if (sigSz == 0) {
// error determining sig size
}
\endcode
\sa wc_ed25519_sign_msg
*/
int wc_ed25519_sig_size(ed25519_key* key);

View File

@@ -0,0 +1,631 @@
/*!
\ingroup ED448
\brief この関数は、秘密鍵からED448公開鍵を生成します。公開鍵をバッファPubkeyに格納し、Pubkeyszでこのバッファに書き込まれたバイトを設定します。
\return 0 公開鍵の作成に成功したときに返されます。
\return BAD_FUNC_ARG IFIキーまたはPubKeyがNULLに評価された場合、または指定されたキーサイズが57バイトではない場合ED448には57バイトのキーがあります
\return MEMORY_E 関数の実行中にメモリを割り当てるエラーがある場合に返されます。
\param [in] キーを生成するED448_Keyへのキーポインタ。
\param [out] 公開鍵を保存するバッファへのポインタ。
_Example_
\code
int ret;
ed448_key key;
byte priv[] = { initialize with 57 byte private key };
byte pub[57];
word32 pubSz = sizeof(pub);
wc_ed448_init(&key);
wc_ed448_import_private_only(priv, sizeof(priv), &key);
ret = wc_ed448_make_public(&key, pub, &pubSz);
if (ret != 0) {
// error making public key
}
\endcode
\sa wc_ed448_init
\sa wc_ed448_import_private_only
\sa wc_ed448_make_key
*/
int wc_ed448_make_public(ed448_key* key, unsigned char* pubKey,
word32 pubKeySz);
/*!
\ingroup ED448
\brief この関数は新しいED448キーを生成し、それをキーに格納します。
\return 0 ED448_Keyを正常に作成したときに返されます。
\return BAD_FUNC_ARG RNGまたはKeyがNULLに評価された場合、または指定されたキーサイズが57バイトではない場合ED448には57バイトのキーがあります
\return MEMORY_E 関数の実行中にメモリを割り当てるエラーがある場合に返されます。
\param [in] RNGキーを生成する初期化されたRNGオブジェクトへのポインタ。
\param [in] keysize keyの長さを生成します。ED448の場合は常に57になります。
_Example_
\code
int ret;
WC_RNG rng;
ed448_key key;
wc_InitRng(&rng);
wc_ed448_init(&key);
ret = wc_ed448_make_key(&rng, 57, &key);
if (ret != 0) {
// error making key
}
\endcode
\sa wc_ed448_init
*/
int wc_ed448_make_key(WC_RNG* rng, int keysize, ed448_key* key);
/*!
\ingroup ED448
\brief この関数は、ED448_Keyオブジェクトを使用したメッセージに正解を保証します。
\return 0 メッセージの署名を正常に生成すると返されます。
\return BAD_FUNC_ARG 入力パラメータのいずれかがNULLに評価された場合、または出力バッファが小さすぎて生成された署名を保存する場合は返されます。
\return MEMORY_E 関数の実行中にメモリを割り当てるエラーがある場合に返されます。
\param [in] 署名するメッセージを含むバッファへのポインタ。
\param [in] 署名するメッセージのインレル長。
\param [out] 生成された署名を格納するためのバッファー。
\param [in,out] 出力バッファの最大長の範囲内。メッセージ署名の生成に成功したときに、書き込まれたバイトを保存します。
_Example_
\code
ed448_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[114]; // will hold generated signature
sigSz = sizeof(sig);
byte message[] = { initialize with message };
wc_InitRng(&rng); // initialize rng
wc_ed448_init(&key); // initialize key
wc_ed448_make_key(&rng, 57, &key); // make public/private key pair
ret = wc_ed448_sign_msg(message, sizeof(message), sig, &sigSz, &key);
if (ret != 0 ) {
// error generating message signature
}
\endcode
\sa wc_ed448ph_sign_hash
\sa wc_ed448ph_sign_msg
\sa wc_ed448_verify_msg
*/
int wc_ed448_sign_msg(const byte* in, word32 inlen, byte* out,
word32 *outlen, ed448_key* key);
/*!
\ingroup ED448
\brief この関数は、Ed448_Keyオブジェクトを使用してメッセージダイジェストに署名して信頼性を保証します。コンテキストは署名されたデータの一部として含まれています。ハッシュは、署名計算前のプリハッシュメッセージです。メッセージダイジェストを作成するために使用されるハッシュアルゴリズムはShake-256でなければなりません。
\return 0 メッセージダイジェストの署名を正常に生成すると返されます。
\return BAD_FUNC_ARG 返された入力パラメータはNULLに評価されます。出力バッファが小さすぎて生成された署名を保存するには小さすぎます。
\return MEMORY_E 関数の実行中にメモリを割り当てるエラーがある場合に返されます。
\param [in] サインへのメッセージのハッシュを含むバッファへのハッシュポインタ。
\param [in] サインへのメッセージのハッシュのハッシュの長さ。
\param [out] 生成された署名を格納するためのバッファー。
\param [in,out] 出力バッファの最大長の範囲内。メッセージ署名の生成に成功したときに、書き込まれたバイトを保存します。
\param [in] 署名を生成するためのプライベートED448_Keyへのキーポインタ。
\param [in] メッセージが署名されているコンテキストを含むバッファへのコンテキストポインタ。
_Example_
\code
ed448_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[114]; // will hold generated signature
sigSz = sizeof(sig);
byte hash[] = { initialize with SHAKE-256 hash of message };
byte context[] = { initialize with context of signing };
wc_InitRng(&rng); // initialize rng
wc_ed448_init(&key); // initialize key
wc_ed448_make_key(&rng, 57, &key); // make public/private key pair
ret = wc_ed448ph_sign_hash(hash, sizeof(hash), sig, &sigSz, &key,
context, sizeof(context));
if (ret != 0) {
// error generating message signature
}
\endcode
\sa wc_ed448_sign_msg
\sa wc_ed448ph_sign_msg
\sa wc_ed448ph_verify_hash
*/
int wc_ed448ph_sign_hash(const byte* hash, word32 hashLen, byte* out,
word32 *outLen, ed448_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED448
\brief この関数は、ED448_Keyオブジェクトを使用したメッセージに正解を保証します。コンテキストは署名されたデータの一部として含まれています。署名計算の前にメッセージは事前にハッシュされています。
\return 0 メッセージの署名を正常に生成すると返されます。
\return BAD_FUNC_ARG 返された入力パラメータはNULLに評価されます。出力バッファが小さすぎて生成された署名を保存するには小さすぎます。
\return MEMORY_E 関数の実行中にメモリを割り当てるエラーがある場合に返されます。
\param [in] 署名するメッセージを含むバッファへのポインタ。
\param [in] 署名するメッセージのインレル長。
\param [out] 生成された署名を格納するためのバッファー。
\param [in,out] 出力バッファの最大長の範囲内。メッセージ署名の生成に成功したときに、書き込まれたバイトを保存します。
\param [in] 署名を生成するためのプライベートED448_Keyへのキーポインタ。
\param [in] メッセージが署名されているコンテキストを含むバッファへのコンテキストポインタ。
_Example_
\code
ed448_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[114]; // will hold generated signature
sigSz = sizeof(sig);
byte message[] = { initialize with message };
byte context[] = { initialize with context of signing };
wc_InitRng(&rng); // initialize rng
wc_ed448_init(&key); // initialize key
wc_ed448_make_key(&rng, 57, &key); // make public/private key pair
ret = wc_ed448ph_sign_msg(message, sizeof(message), sig, &sigSz, &key,
context, sizeof(context));
if (ret != 0) {
// error generating message signature
}
\endcode
\sa wc_ed448_sign_msg
\sa wc_ed448ph_sign_hash
\sa wc_ed448ph_verify_msg
*/
int wc_ed448ph_sign_msg(const byte* in, word32 inLen, byte* out,
word32 *outLen, ed448_key* key, const byte* context,
byte contextLen);
/*!
\ingroup ED448
\brief この関数は、メッセージのED448署名を確認して信頼性を確保します。文脈はデータ検証済みの一部として含まれています。答えはRESを介して返され、有効な署名に対応する1、無効な署名に対応する0を返します。
\return 0 署名検証と認証を正常に実行したときに返されます。
\return BAD_FUNC_ARG いずれかの入力パラメータがNULLに評価された場合、またはSIGLENが署名の実際の長さと一致しない場合に返されます。
\return SIG_VERIFY_E 検証が完了した場合は返されますが、生成された署名は提供された署名と一致しません。
\param [in] 検証するシグネチャを含むバッファへのSIGポインタ。
\param [in] 検証するシグネチャのシグレンの長さ。
\param [in] メッセージを含むバッファへのMSGポインタを確認する。
\param [in] 検証するメッセージのMSGlen長。
\param [in] 署名を検証するためのパブリックED448キーへのキーポインタ。
\param [in] メッセージが署名されたコンテキストを含むバッファへのコンテキストポインタ。
_Example_
\code
ed448_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte msg[] = { initialize with message };
byte context[] = { initialize with context of signature };
// initialize key with received public key
ret = wc_ed448_verify_msg(sig, sizeof(sig), msg, sizeof(msg), &verified,
&key, context, sizeof(context));
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
\endcode
\sa wc_ed448ph_verify_hash
\sa wc_ed448ph_verify_msg
\sa wc_ed448_sign_msg
*/
int wc_ed448_verify_msg(const byte* sig, word32 siglen, const byte* msg,
word32 msgLen, int* res, ed448_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED448
\brief この関数は、メッセージのダイジェストのED448シグネチャを検証して、信頼性を確保します。文脈はデータ検証済みの一部として含まれています。ハッシュは、署名計算前のプリハッシュメッセージです。メッセージダイジェストを作成するために使用されるハッシュアルゴリズムはShake-256でなければなりません。答えはRESを介して返され、有効な署名に対応する1、無効な署名に対応する0を返します。
\return 0 署名検証と認証を正常に実行したときに返されます。
\return BAD_FUNC_ARG いずれかの入力パラメータがNULLに評価された場合、またはSIGLENが署名の実際の長さと一致しない場合に返されます。
\return SIG_VERIFY_E 検証が完了した場合は返されますが、生成された署名は提供された署名と一致しません。
\param [in] 検証するシグネチャを含むバッファへのSIGポインタ。
\param [in] 検証するシグネチャのシグレンの長さ。
\param [in] 検証するメッセージのハッシュを含むバッファへのハッシュポインタ。
\param [in] 検証するハッシュのハッシュレン長。
\param [in] 署名を検証するためのパブリックED448キーへのキーポインタ。
\param [in] メッセージが署名されたコンテキストを含むバッファへのコンテキストポインタ。
_Example_
\code
ed448_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte hash[] = { initialize with SHAKE-256 hash of message };
byte context[] = { initialize with context of signature };
// initialize key with received public key
ret = wc_ed448ph_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
&verified, &key, context, sizeof(context));
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
\endcode
\sa wc_ed448_verify_msg
\sa wc_ed448ph_verify_msg
\sa wc_ed448ph_sign_hash
*/
int wc_ed448ph_verify_hash(const byte* sig, word32 siglen, const byte* hash,
word32 hashlen, int* res, ed448_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED448
\brief この関数は、メッセージのED448署名を確認して信頼性を確保します。文脈はデータ検証済みの一部として含まれています。検証前にメッセージがプリハッシュされています。答えはRESを介して返され、有効な署名に対応する1、無効な署名に対応する0を返します。
\return 0 署名検証と認証を正常に実行したときに返されます。
\return BAD_FUNC_ARG いずれかの入力パラメータがNULLに評価された場合、またはSIGLENが署名の実際の長さと一致しない場合に返されます。
\return SIG_VERIFY_E 検証が完了した場合は返されますが、生成された署名は提供された署名と一致しません。
\param [in] 検証するシグネチャを含むバッファへのSIGポインタ。
\param [in] 検証するシグネチャのシグレンの長さ。
\param [in] メッセージを含むバッファへのMSGポインタを確認する。
\param [in] 検証するメッセージのMSGlen長。
\param [in] 署名を検証するためのパブリックED448キーへのキーポインタ。
\param [in] メッセージが署名されたコンテキストを含むバッファへのコンテキストポインタ。
_Example_
\code
ed448_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte msg[] = { initialize with message };
byte context[] = { initialize with context of signature };
// initialize key with received public key
ret = wc_ed448ph_verify_msg(sig, sizeof(sig), msg, sizeof(msg), &verified,
&key, context, sizeof(context));
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
\endcode
\sa wc_ed448_verify_msg
\sa wc_ed448ph_verify_hash
\sa wc_ed448ph_sign_msg
*/
int wc_ed448ph_verify_msg(const byte* sig, word32 siglen, const byte* msg,
word32 msgLen, int* res, ed448_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED448
\brief この関数は、メッセージ検証で将来の使用のためにED448_Keyオブジェクトを初期化します。
\return 0 ED448_Keyオブジェクトの初期化に成功したら返されます。
\return BAD_FUNC_ARG キーがNULLの場合は返されます。
_Example_
\code
ed448_key key;
wc_ed448_init(&key);
\endcode
\sa wc_ed448_make_key
\sa wc_ed448_free
*/
int wc_ed448_init(ed448_key* key);
/*!
\ingroup ED448
\brief この関数は、それが使用された後にED448オブジェクトを解放します。
_Example_
\code
ed448_key key;
// initialize key and perform secure exchanges
...
wc_ed448_free(&key);
\endcode
\sa wc_ed448_init
*/
void wc_ed448_free(ed448_key* key);
/*!
\ingroup ED448
\brief この関数は、公開鍵を含むバッファからPublic ED448_Keyペアをインポートします。この関数は圧縮キーと非圧縮キーの両方を処理します。
\return 0 ED448_Keyのインポートに成功しました。
\return BAD_FUNC_ARG INまたはKEYがNULLに評価されている場合、またはINLENがED448キーのサイズより小さい場合に返されます。
\param [in] 公開鍵を含むバッファへのポインタ。
\param [in] 公開鍵を含むバッファのインレル長。
_Example_
\code
int ret;
byte pub[] = { initialize Ed448 public key };
ed_448 key;
wc_ed448_init_key(&key);
ret = wc_ed448_import_public(pub, sizeof(pub), &key);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_ed448_import_private_key
\sa wc_ed448_export_public
*/
int wc_ed448_import_public(const byte* in, word32 inLen, ed448_key* key);
/*!
\ingroup ED448
\brief この関数は、ed448秘密鍵をバッファからのみインポートします。
\return 0 ED448秘密鍵のインポートに成功しました。
\return BAD_FUNC_ARG INまたはKEYがNULLに評価された場合、またはPRIVSZがED448_KEY_SIZEよりも小さい場合に返されます。
\param [in] 秘密鍵を含むバッファへのPRIVポインタ。
\param [in] 秘密鍵のPrivsz長さ。
_Example_
\code
int ret;
byte priv[] = { initialize with 57 byte private key };
ed448_key key;
wc_ed448_init_key(&key);
ret = wc_ed448_import_private_only(priv, sizeof(priv), &key);
if (ret != 0) {
// error importing private key
}
\endcode
\sa wc_ed448_import_public
\sa wc_ed448_import_private_key
\sa wc_ed448_export_private_only
*/
int wc_ed448_import_private_only(const byte* priv, word32 privSz,
ed448_key* key);
/*!
\ingroup ED448
\brief この関数は、一対のバッファからパブリック/プライベートED448キーペアをインポートします。この関数は圧縮キーと非圧縮キーの両方を処理します。
\return 0 ED448キーのインポートに成功しました。
\return BAD_FUNC_ARG INまたはKEYがNULLに評価された場合、またはPROVSZがED448_KEY_SIZEまたはPUBSZのいずれかがeD448_PUB_KEY_SIZEよりも小さい場合に返されます。
\param [in] 秘密鍵を含むバッファへのPRIVポインタ。
\param [in] 秘密鍵のPrivsz長さ。
\param [in] 公開鍵を含むバッファへのPubポインタ。
\param [in] 公開鍵のPubszの長さ。
_Example_
\code
int ret;
byte priv[] = { initialize with 57 byte private key };
byte pub[] = { initialize with the corresponding public key };
ed448_key key;
wc_ed448_init_key(&key);
ret = wc_ed448_import_private_key(priv, sizeof(priv), pub, sizeof(pub),
&key);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_ed448_import_public
\sa wc_ed448_import_private_only
\sa wc_ed448_export_private
*/
int wc_ed448_import_private_key(const byte* priv, word32 privSz,
const byte* pub, word32 pubSz, ed448_key* key);
/*!
\ingroup ED448
\brief この関数は、ED448_Key構造体から秘密鍵をエクスポートします。公開鍵をバッファアウトに格納し、ounterenでこのバッファに書き込まれたバイトを設定します。
\return 0 公開鍵のエクスポートに成功したら返されます。
\return BAD_FUNC_ARG いずれかの入力値がNULLに評価された場合に返されます。
\return BUFFER_E 提供されたバッファーが秘密鍵を保存するのに十分な大きさでない場合に返されます。このエラーを返すと、outlenに必要なサイズを設定します。
\param [in] 公開鍵をエクスポートするED448_Key構造体へのキーポインタ。
\param [out] 公開鍵を保存するバッファへのポインタ。
_Example_
\code
int ret;
ed448_key key;
// initialize key, make key
char pub[57];
word32 pubSz = sizeof(pub);
ret = wc_ed448_export_public(&key, pub, &pubSz);
if (ret != 0) {
// error exporting public key
}
\endcode
\sa wc_ed448_import_public
\sa wc_ed448_export_private_only
*/
int wc_ed448_export_public(ed448_key* key, byte* out, word32* outLen);
/*!
\ingroup ED448
\brief この関数は、ED448_Key構造体からの秘密鍵のみをエクスポートします。秘密鍵をバッファアウトに格納し、outlenにこのバッファに書き込まれたバイトを設定します。
\return 0 秘密鍵のエクスポートに成功したら返されます。
\return ECC_BAD_ARG_E いずれかの入力値がNULLに評価された場合に返されます。
\return BUFFER_E 提供されたバッファーが秘密鍵を保存するのに十分な大きさでない場合に返されます。
\param [in] 秘密鍵をエクスポートするED448_Key構造体へのキーポインタ。
\param [out] 秘密鍵を保存するバッファへのポインタ。
_Example_
\code
int ret;
ed448_key key;
// initialize key, make key
char priv[57]; // 57 bytes because only private key
word32 privSz = sizeof(priv);
ret = wc_ed448_export_private_only(&key, priv, &privSz);
if (ret != 0) {
// error exporting private key
}
\endcode
\sa wc_ed448_export_public
\sa wc_ed448_import_private_key
*/
int wc_ed448_export_private_only(ed448_key* key, byte* out, word32* outLen);
/*!
\ingroup ED448
\brief この関数は、ED448_Key構造体からキーペアをエクスポートします。キーペアをバッファOUTに格納し、ounterenでこのバッファに書き込まれたバイトを設定します。
\return 0 キーペアのエクスポートに成功したら返されます。
\return ECC_BAD_ARG_E いずれかの入力値がNULLに評価された場合に返されます。
\return BUFFER_E 提供されているバッファーがキーペアを保存するのに十分な大きさでない場合に返されます。
\param [in] キーペアをエクスポートするためのED448_Key構造体へのキーポインタ。
\param [out] キーペアを保存するバッファへのポインタ。
_Example_
\code
ed448_key key;
wc_ed448_init(&key);
WC_RNG rng;
wc_InitRng(&rng);
wc_ed448_make_key(&rng, 57, &key); // initialize 57 byte Ed448 key
byte out[114]; // out needs to be a sufficient buffer size
word32 outLen = sizeof(out);
int key_size = wc_ed448_export_private(&key, out, &outLen);
if (key_size == BUFFER_E) {
// Check size of out compared to outLen to see if function reset outLen
}
\endcode
\sa wc_ed448_import_private
\sa wc_ed448_export_private_only
*/
int wc_ed448_export_private(ed448_key* key, byte* out, word32* outLen);
/*!
\ingroup ED448
\brief この関数は、ED448_Key構造体とは別にプライベートキーと公開鍵をエクスポートします。秘密鍵をバッファーPrivに格納し、PRIVSZでこのバッファに書き込まれたバイトを設定します。公開鍵をバッファPUBに格納し、Pubszでこのバッファに書き込まれたバイトを設定します。
\return 0 キーペアのエクスポートに成功したら返されます。
\return ECC_BAD_ARG_E いずれかの入力値がNULLに評価された場合に返されます。
\return BUFFER_E 提供されているバッファーがキーペアを保存するのに十分な大きさでない場合に返されます。
\param [in] キーペアをエクスポートするためのED448_Key構造体へのキーポインタ。
\param [out] 秘密鍵を保存するバッファへのPRIVポインタ。
\param [in,out] PRIVSZ PIVINSZポインタサイズが表示されているサイズを持つWord32オブジェクトへのポインタ。秘密鍵のエクスポート後に書き込まれたバイト数を設定します。
\param [out] パブリックキーを保存するバッファへのPub。
_Example_
\code
int ret;
ed448_key key;
// initialize key, make key
char pub[57];
word32 pubSz = sizeof(pub);
char priv[57];
word32 privSz = sizeof(priv);
ret = wc_ed448_export_key(&key, priv, &pubSz, pub, &pubSz);
if (ret != 0) {
// error exporting private and public key
}
\endcode
\sa wc_ed448_export_private
\sa wc_ed448_export_public
*/
int wc_ed448_export_key(ed448_key* key,
byte* priv, word32 *privSz,
byte* pub, word32 *pubSz);
/*!
\ingroup ED448
\brief この関数は、ed448_key構造体の公開鍵をチェックします。
\return 0 プライベートキーと公開鍵が一致した場合に返されます。
\return BAD_FUNC_ARGS 与えられたキーがNULLの場合に返されます。
_Example_
\code
int ret;
byte priv[] = { initialize with 57 byte private key };
byte pub[] = { initialize with the corresponding public key };
ed448_key key;
wc_ed448_init_key(&key);
wc_ed448_import_private_key(priv, sizeof(priv), pub, sizeof(pub), &key);
ret = wc_ed448_check_key(&key);
if (ret != 0) {
// error checking key
}
\endcode
\sa wc_ed448_import_private_key
*/
int wc_ed448_check_key(ed448_key* key);
/*!
\ingroup ED448
\brief この関数は、ED448秘密鍵のサイズ - 57バイトを返します。
\return ED448_KEY_SIZE 有効な秘密鍵のサイズ57バイト
\return BAD_FUNC_ARGS 与えられたキーがNULLの場合に返されます。
_Example_
\code
int keySz;
ed448_key key;
// initialize key, make key
keySz = wc_ed448_size(&key);
if (keySz == 0) {
// error determining key size
}
\endcode
\sa wc_ed448_make_key
*/
int wc_ed448_size(ed448_key* key);
/*!
\ingroup ED448
\brief この関数は、秘密鍵サイズsecret + publicをバイト単位で返します。
\return ED448_PRV_KEY_SIZE 秘密鍵のサイズ114バイト
\return BAD_FUNC_ARG key引数がnullの場合は返します。
_Example_
\code
ed448_key key;
wc_ed448_init(&key);
WC_RNG rng;
wc_InitRng(&rng);
wc_ed448_make_key(&rng, 57, &key); // initialize 57 byte Ed448 key
int key_size = wc_ed448_priv_size(&key);
\endcode
\sa wc_ed448_pub_size
*/
int wc_ed448_priv_size(ed448_key* key);
/*!
\ingroup ED448
\brief この関数は圧縮鍵サイズをバイト単位で返します(公開鍵)。
\return ED448_PUB_KEY_SIZE 圧縮公開鍵のサイズ57バイト
\return BAD_FUNC_ARG key引数がnullの場合は返します。
_Example_
\code
ed448_key key;
wc_ed448_init(&key);
WC_RNG rng;
wc_InitRng(&rng);
wc_ed448_make_key(&rng, 57, &key); // initialize 57 byte Ed448 key
int key_size = wc_ed448_pub_size(&key);
\endcode
\sa wc_ed448_priv_size
*/
int wc_ed448_pub_size(ed448_key* key);
/*!
\ingroup ED448
\brief この関数は、ED448シグネチャのサイズバイト数114を返します。
\return ED448_SIG_SIZE ED448シグネチャ114バイトのサイズ。
\return BAD_FUNC_ARG key引数がnullの場合は返します。
_Example_
\code
int sigSz;
ed448_key key;
// initialize key, make key
sigSz = wc_ed448_sig_size(&key);
if (sigSz == 0) {
// error determining sig size
}
\endcode
\sa wc_ed448_sign_msg
*/
int wc_ed448_sig_size(ed448_key* key);

View File

@@ -0,0 +1,34 @@
/*!
\ingroup Error
\brief この関数は、特定のバッファ内の特定のエラーコードのエラー文字列を格納します。
\return none いいえ返します。
\param error 文字列を取得するためのエラーコード
_Example_
\code
char errorMsg[WOLFSSL_MAX_ERROR_SZ];
int err = wc_some_function();
if( err != 0) { // error occurred
wc_ErrorString(err, errorMsg);
}
\endcode
\sa wc_GetErrorString
*/
void wc_ErrorString(int err, char* buff);
/*!
\ingroup Error
\brief この関数は、特定のエラーコードのエラー文字列を返します。
\return string エラーコードのエラー文字列を文字列リテラルとして返します。
_Example_
\code
char * errorMsg;
int err = wc_some_function();
if( err != 0) { // error occurred
errorMsg = wc_GetErrorString(err);
}
\endcode
\sa wc_ErrorString
*/
const char* wc_GetErrorString(int error);

View File

@@ -0,0 +1,333 @@
/*!
\ingroup openSSL
\brief それぞれのwolfssl_evp_cipherポインタのゲッター関数。最初にプログラム内でwolfssl_evp_initを1回呼び出す必要があります。wolfssl_des_ecbマクロは、wolfssl_evp_des_ede3_ecbに対して定義する必要があります。
\return pointer DES EDE3操作のためのwolfssl_evp_cipherポインタを返します。
_Example_
\code
printf("block size des ede3 cbc = %d\n",
wolfSSL_EVP_CIPHER_block_size(wolfSSL_EVP_des_ede3_cbc()));
printf("block size des ede3 ecb = %d\n",
wolfSSL_EVP_CIPHER_block_size(wolfSSL_EVP_des_ede3_ecb()));
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_init
*/
const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_des_ede3_ecb(void);
/*!
\ingroup openSSL
\brief それぞれのwolfssl_evp_cipherポインタのゲッター関数。最初にプログラム内でwolfssl_evp_initを1回呼び出す必要があります。wolfssl_des_ecbマクロは、wolfssl_evp_des_ecbに対して定義する必要があります。
\return pointer DES操作のためのwolfssl_evp_cipherポインタを返します。
_Example_
\code
WOLFSSL_EVP_CIPHER* cipher;
cipher = wolfSSL_EVP_des_cbc();
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_init
*/
const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_des_cbc(void);
/*!
\ingroup openSSL
\brief wolfssl_evp_md_ctxを初期化する機能。この関数はwolfssl_engineがwolfssl_engineを使用しないため、wolfssl_evp_digestinitのラッパーです。
\return SSL_SUCCESS 正常に設定されている場合。
\return SSL_FAILURE 成功しなかった場合
\param ctx 初期化する構造
\param type SHAなどのハッシュの種類。
_Example_
\code
WOLFSSL_EVP_MD_CTX* md = NULL;
wolfCrypt_Init();
md = wolfSSL_EVP_MD_CTX_new();
if (md == NULL) {
printf("error setting md\n");
return -1;
}
printf("cipher md init ret = %d\n", wolfSSL_EVP_DigestInit_ex(md,
wolfSSL_EVP_sha1(), e));
//free resources
\endcode
\sa wolfSSL_EVP_MD_CTX_new
\sa wolfCrypt_Init
\sa wolfSSL_EVP_MD_CTX_free
*/
int wolfSSL_EVP_DigestInit_ex(WOLFSSL_EVP_MD_CTX* ctx,
const WOLFSSL_EVP_MD* type,
WOLFSSL_ENGINE *impl);
/*!
\ingroup openSSL
\brief wolfssl_evp_cipher_ctxを初期化する機能。この関数はwolfssl_engineがwolfssl_engineを使用しないため、wolfssl_ciphinitのラッパーです。
\return SSL_SUCCESS 正常に設定されている場合。
\return SSL_FAILURE 成功しなかった場合
\param ctx 初期化する構造
\param type AESなどの暗号化/復号化の種類。
\param impl 使用するエンジン。wolfsslのn / aは、nullになることができます。
\param key 設定するキー
\param iv アルゴリズムで必要な場合はIV。
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx = NULL;
WOLFSSL_ENGINE* e = NULL;
unsigned char key[16];
unsigned char iv[12];
wolfCrypt_Init();
ctx = wolfSSL_EVP_CIPHER_CTX_new();
if (ctx == NULL) {
printf("issue creating ctx\n");
return -1;
}
printf("cipher init ex error ret = %d\n", wolfSSL_EVP_CipherInit_ex(NULL,
EVP_aes_128_ cbc(), e, key, iv, 1));
printf("cipher init ex success ret = %d\n", wolfSSL_EVP_CipherInit_ex(ctx,
EVP_aes_128_c bc(), e, key, iv, 1));
// free resources
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
\sa wolfCrypt_Init
\sa wolfSSL_EVP_CIPHER_CTX_free
*/
int wolfSSL_EVP_CipherInit_ex(WOLFSSL_EVP_CIPHER_CTX* ctx,
const WOLFSSL_EVP_CIPHER* type,
WOLFSSL_ENGINE *impl,
const unsigned char* key,
const unsigned char* iv,
int enc);
/*!
\ingroup openSSL
\brief wolfssl_evp_cipher_ctxを初期化する機能。WolfSSLはWOLFSSL_ENGINEを使用しないため、この関数はwolfssl_evp_ciphinitのラッパーです。暗号化フラグを暗号化するように設定します。
\return SSL_SUCCESS 正常に設定されている場合。
\return SSL_FAILURE 成功しなかった場合
\param ctx 初期化する構造
\param type AESなどの暗号化の種類。
\param impl 使用するエンジン。wolfsslのn / aは、nullになることができます。
\param key 使用する鍵
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx = NULL;
wolfCrypt_Init();
ctx = wolfSSL_EVP_CIPHER_CTX_new();
if (ctx == NULL) {
printf("error setting ctx\n");
return -1;
}
printf("cipher ctx init ret = %d\n", wolfSSL_EVP_EncryptInit_ex(ctx,
wolfSSL_EVP_aes_128_cbc(), e, key, iv));
//free resources
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
\sa wolfCrypt_Init
\sa wolfSSL_EVP_CIPHER_CTX_free
*/
int wolfSSL_EVP_EncryptInit_ex(WOLFSSL_EVP_CIPHER_CTX* ctx,
const WOLFSSL_EVP_CIPHER* type,
WOLFSSL_ENGINE *impl,
const unsigned char* key,
const unsigned char* iv);
/*!
\ingroup openSSL
\brief wolfssl_evp_cipher_ctxを初期化する機能。WolfSSLはWOLFSSL_ENGINEを使用しないため、この関数はwolfssl_evp_ciphinitのラッパーです。暗号化フラグを復号化するように設定します。
\return SSL_SUCCESS 正常に設定されている場合。
\return SSL_FAILURE 成功しなかった場合
\param ctx 初期化する構造
\param type AESなどの暗号化/復号化の種類。
\param impl 使用するエンジン。wolfsslのn / aは、nullになることができます。
\param key 設定するキー
\param iv アルゴリズムで必要な場合はIV。
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx = NULL;
WOLFSSL_ENGINE* e = NULL;
unsigned char key[16];
unsigned char iv[12];
wolfCrypt_Init();
ctx = wolfSSL_EVP_CIPHER_CTX_new();
if (ctx == NULL) {
printf("issue creating ctx\n");
return -1;
}
printf("cipher init ex error ret = %d\n", wolfSSL_EVP_DecryptInit_ex(NULL,
EVP_aes_128_ cbc(), e, key, iv, 1));
printf("cipher init ex success ret = %d\n", wolfSSL_EVP_DecryptInit_ex(ctx,
EVP_aes_128_c bc(), e, key, iv, 1));
// free resources
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
\sa wolfCrypt_Init
\sa wolfSSL_EVP_CIPHER_CTX_free
*/
int wolfSSL_EVP_DecryptInit_ex(WOLFSSL_EVP_CIPHER_CTX* ctx,
const WOLFSSL_EVP_CIPHER* type,
WOLFSSL_ENGINE *impl,
const unsigned char* key,
const unsigned char* iv);
/*!
\ingroup openSSL
\brief データを暗号化/復号化する機能。バッファ内では暗号化または復号化され、OUTバッファが結果を保持します。OUTORは暗号化/復号化された情報の長さになります。
\return SSL_SUCCESS 成功した場合
\return SSL_FAILURE 成功しなかった場合
\param ctx から暗号化の種類を取得するための構造。
\param out 出力を保持するためのバッファ。
\param outl 出力のサイズになるように調整しました。
\param in 操作を実行するためのバッファー。
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx = NULL;
unsigned char out[100];
int outl;
unsigned char in[100];
int inl = 100;
ctx = wolfSSL_EVP_CIPHER_CTX_new();
// set up ctx
ret = wolfSSL_EVP_CipherUpdate(ctx, out, outl, in, inl);
// check ret value
// buffer out holds outl bytes of data
// free resources
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
\sa wolfCrypt_Init
\sa wolfSSL_EVP_CIPHER_CTX_free
*/
int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx,
unsigned char *out, int *outl,
const unsigned char *in, int inl);
/*!
\ingroup openSSL
\brief この関数は、パディングを追加する最終暗号化操作を実行します。wolfssl_evp_ciph_no_paddingフラグがwolfssl_evp_cipher_ctx構造に設定されている場合、1が返され、暗号化/復号化は行われません。PADDING FLAGがSETIパディングを追加して暗号化すると、暗号化にCTXが設定されていると、復号化されたときにパディング値がチェックされます。
\return 1 成功に戻りました。
\return 0 失敗に遭遇した場合
\param ctx 復号化/暗号化する構造。
\param out 最後の復号化/暗号化のためのバッファ。
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx;
int out1;
unsigned char out[64];
// create ctx
wolfSSL_EVP_CipherFinal(ctx, out, &out1);
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
*/
int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx,
unsigned char *out, int *outl);
/*!
\ingroup openSSL
\brief WolfSSL EVP_CIPHER_CTX構造キー長の設定機能
\return SSL_SUCCESS 正常に設定されている場合。
\return SSL_FAILURE キーの長さを設定できなかった場合。
\param ctx キーの長さを設定する構造
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx;
int keylen;
// create ctx
wolfSSL_EVP_CIPHER_CTX_set_key_length(ctx, keylen);
\endcode
\sa wolfSSL_EVP_CIPHER_flags
*/
int wolfSSL_EVP_CIPHER_CTX_set_key_length(WOLFSSL_EVP_CIPHER_CTX* ctx,
int keylen);
/*!
\ingroup openSSL
\brief これはCTXブロックサイズのGetter関数です。
\return size ctx-> block_sizeを返します。
_Example_
\code
const WOLFSSL_CVP_CIPHER_CTX* ctx;
//set up ctx
printf(“block size = %d\n”, wolfSSL_EVP_CIPHER_CTX_block_size(ctx));
\endcode
\sa wolfSSL_EVP_CIPHER_block_size
*/
int wolfSSL_EVP_CIPHER_CTX_block_size(const WOLFSSL_EVP_CIPHER_CTX *ctx);
/*!
\ingroup openSSL
\brief これは暗号のブロックサイズのゲッター関数です。
\return size ブロックサイズを返します。
_Example_
\code
printf(“block size = %d\n”,
wolfSSL_EVP_CIPHER_block_size(wolfSSL_EVP_aes_256_ecb()));
\endcode
\sa wolfSSL_EVP_aes_256_ctr
*/
int wolfSSL_EVP_CIPHER_block_size(const WOLFSSL_EVP_CIPHER *cipher);
/*!
\ingroup openSSL
\brief WolfSSL evp_cipher_ctx構造の設定機能
\return none いいえ返します。
\param ctx フラグを設定する構造
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx;
int flag;
// create ctx
wolfSSL_EVP_CIPHER_CTX_set_flags(ctx, flag);
\endcode
\sa wolfSSL_EVP_CIPHER_flags
\sa wolfSSL_EVP_CIPHER_CTX_flags
*/
void wolfSSL_EVP_CIPHER_CTX_set_flags(WOLFSSL_EVP_CIPHER_CTX *ctx, int flags);
/*!
\ingroup openSSL
\brief WolfSSL evp_cipher_ctx構造のクリア機能
\return none いいえ返します。
\param ctx フラグをクリアするための構造
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx;
int flag;
// create ctx
wolfSSL_EVP_CIPHER_CTX_clear_flags(ctx, flag);
\endcode
\sa wolfSSL_EVP_CIPHER_flags
\sa wolfSSL_EVP_CIPHER_CTX_flags
*/
void wolfSSL_EVP_CIPHER_CTX_clear_flags(WOLFSSL_EVP_CIPHER_CTX *ctx, int flags);
/*!
\ingroup openSSL
\brief wolfssl_evp_cipher_ctx構造のためのセッター機能パディングを使用する。
\return SSL_SUCCESS 正常に設定されている場合。
\return BAD_FUNC_ARG NULL引数が渡された場合。
\param ctx パディングフラグを設定する構造
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx;
// create ctx
wolfSSL_EVP_CIPHER_CTX_set_padding(ctx, 1);
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
*/
int wolfSSL_EVP_CIPHER_CTX_set_padding(WOLFSSL_EVP_CIPHER_CTX *c, int pad);
/*!
\ingroup openSSL
\brief wolfssl_evp_cipher_ctx構造のゲッター関数廃止予定のV1.1.0
\return unsigned フラグ/モードの長い。
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx;
unsigned long flags;
ctx = wolfSSL_EVP_CIPHER_CTX_new()
flags = wolfSSL_EVP_CIPHER_CTX_flags(ctx);
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
\sa wolfSSL_EVP_CIPHER_flags
*/
unsigned long wolfSSL_EVP_CIPHER_CTX_flags(const WOLFSSL_EVP_CIPHER_CTX *ctx);

View File

@@ -0,0 +1,171 @@
/*!
\ingroup wolfCrypt
\brief この関数は提供されたwc_hashtypeのOIDを返します。
\return OID 戻り値0を超えてください
\return HASH_TYPE_E ハッシュ型はサポートされていません。
\return BAD_FUNC_ARG 提供された引数の1つが正しくありません。
_Example_
\code
enum wc_HashType hash_type = WC_HASH_TYPE_SHA256;
int oid = wc_HashGetOID(hash_type);
if (oid > 0) {
// Success
}
\endcode
\sa wc_HashGetDigestSize
\sa wc_Hash
*/
int wc_HashGetOID(enum wc_HashType hash_type);
/*!
\ingroup wolfCrypt
\brief この関数は、hash_typeのダイジェスト出力のサイズを返します。返品サイズは、WC_HASHに提供される出力バッファが十分に大きいことを確認するために使用されます。
\return Success 正の戻り値は、ハッシュのダイジェストサイズを示します。
\return Error hash_typeがサポートされていない場合はhash_type_eを返します。
\return Failure 無効なhash_typeが使用された場合、bad_func_argを返します。
_Example_
\code
int hash_len = wc_HashGetDigestSize(hash_type);
if (hash_len <= 0) {
WOLFSSL_MSG("Invalid hash type/len");
return BAD_FUNC_ARG;
}
\endcode
\sa wc_Hash
*/
int wc_HashGetDigestSize(enum wc_HashType hash_type);
/*!
\ingroup wolfCrypt
\brief この関数は、提供されたデータバッファ上にハッシュを実行し、提供されたハッシュバッファにそれを返します。
\return 0 そうでなければ、それ以外の誤りbad_func_argやbuffer_eなど
\param hash_type "wc_hash_type_sha256"などの "enum wc_hashtype"からのハッシュ型。
\param data ハッシュへのデータを含むバッファへのポインタ。
\param data_len データバッファの長さ。
\param hash 最後のハッシュを出力するために使用されるバッファへのポインタ。
_Example_
\code
enum wc_HashType hash_type = WC_HASH_TYPE_SHA256;
int hash_len = wc_HashGetDigestSize(hash_type);
if (hash_len > 0) {
int ret = wc_Hash(hash_type, data, data_len, hash_data, hash_len);
if(ret == 0) {
// Success
}
}
\endcode
\sa wc_HashGetDigestSize
*/
int wc_Hash(enum wc_HashType hash_type,
const byte* data, word32 data_len,
byte* hash, word32 hash_len);
/*!
\ingroup MD5
\brief 利便性機能は、すべてのハッシュを処理し、その結果をハッシュに入れます。
\return 0 データを正常にハッシュしたときに返されます。
\return Memory_E メモリエラー、メモリを割り当てることができません。これは、小さなスタックオプションが有効になっているだけです。
\param data ハッシュへのデータ
\param len データの長さ
_Example_
\code
const byte* data;
word32 data_len;
byte* hash;
int ret;
...
ret = wc_Md5Hash(data, data_len, hash);
if (ret != 0) {
// Md5 Hash Failure Case.
}
\endcode
\sa wc_Md5Hash
\sa wc_Md5Final
\sa wc_InitMd5
*/
int wc_Md5Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief 利便性機能は、すべてのハッシュを処理し、その結果をハッシュに入れます。
\return 0 うまく返されました...。
\return Memory_E メモリエラー、メモリを割り当てることができません。これは、小さなスタックオプションが有効になっているだけです。
\param data ハッシュへのデータ
\param len データの長さ
_Example_
\code
none
\endcode
\sa wc_ShaHash
\sa wc_ShaFinal
\sa wc_InitSha
*/
int wc_ShaHash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief 利便性機能は、すべてのハッシュを処理し、その結果をハッシュに入れます。
\return 0 うまく返されました...
\return Memory_E メモリエラー、メモリを割り当てることができません。これは、小さなスタックオプションが有効になっているだけです。
\param data ハッシュへのデータ
\param len データの長さ
_Example_
\code
none
\endcode
\sa wc_Sha256Hash
\sa wc_Sha256Final
\sa wc_InitSha256
*/
int wc_Sha256Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief 利便性機能は、すべてのハッシュを処理し、その結果をハッシュに入れます。
\return 0 成功
\return <0 エラー
\param data ハッシュへのデータ
\param len データの長さ
_Example_
\code
none
\endcode
\sa wc_InitSha224
\sa wc_Sha224Update
\sa wc_Sha224Final
*/
int wc_Sha224Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief 利便性機能は、すべてのハッシュを処理し、その結果をハッシュに入れます。
\return 0 入力されたデータを正常にハッシュしたときに返されます
\return Memory_E メモリエラー、メモリを割り当てることができません。これは、小さなスタックオプションが有効になっているだけです。
\param data ハッシュへのデータ
\param len データの長さ
_Example_
\code
none
\endcode
\sa wc_Sha512Hash
\sa wc_Sha512Final
\sa wc_InitSha512
*/
int wc_Sha512Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief 利便性機能は、すべてのハッシュを処理し、その結果をハッシュに入れます。
\return 0 データを正常にハッシュしたときに返されます
\return Memory_E メモリエラー、メモリを割り当てることができません。これは、小さなスタックオプションが有効になっているだけです。
\param data ハッシュへのデータ
\param len データの長さ
_Example_
\code
none
\endcode
\sa wc_Sha384Hash
\sa wc_Sha384Final
\sa wc_InitSha384
*/
int wc_Sha384Hash(const byte* data, word32 len, byte* hash);

View File

@@ -0,0 +1,115 @@
/*!
\ingroup HMAC
\brief この関数はHMACオブジェクトを初期化し、その暗号化タイプ、キー、およびHMACの長さを設定します。
\return 0 HMACオブジェクトの初期化に成功しました
\return BAD_FUNC_ARG 入力タイプが無効な場合は返されます。有効なオプションは次のとおりです.MD5、SHA、SHA256、SHA384、SHA3-224、SHA3-256、SHA3-384、SHA3-512
\return MEMORY_E ハッシュに使用する構造体の割り当てメモリの割り当てがある場合
\return HMAC_MIN_KEYLEN_E FIPS実装を使用するときに返されることがあり、指定されたキー長は最小許容FIPS規格よりも短いです。
\param hmac 初期化するHMACオブジェクトへのポインタ
\param type HMACオブジェクトを使用する暗号化方式を指定します。有効なオプションは次のとおりです.MD5、SHA、SHA256、SHA384、SHA3-224、SHA3-256、SHA3-384、SHA3-512
\param key HMACオブジェクトを初期化するキーを含むバッファへのポインタ
_Example_
\code
Hmac hmac;
byte key[] = { // initialize with key to use for encryption };
if (wc_HmacSetKey(&hmac, MD5, key, sizeof(key)) != 0) {
// error initializing Hmac object
}
\endcode
\sa wc_HmacUpdate
\sa wc_HmacFinal
*/
int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 keySz);
/*!
\ingroup HMAC
\brief この関数は、HMACを使用して認証するメッセージを更新します。HMACオブジェクトがWC_HMACSETKEYで初期化された後に呼び出されるべきです。この関数は、ハッシュへのメッセージを更新するために複数回呼び出されることがあります。必要に応じてwc_hmacupdateを呼び出した後、最終認証済みメッセージタグを取得するためにwc_hmacfinalを呼び出す必要があります。
\return 0 認証するメッセージの更新に成功しました
\return MEMORY_E ハッシュアルゴリズムで使用するためにメモリを割り当てるエラーがある場合
\param hmac メッセージを更新するHMACオブジェクトへのポインタ
\param msg 追加するメッセージを含むバッファへのポインタ
_Example_
\code
Hmac hmac;
byte msg[] = { // initialize with message to authenticate };
byte msg2[] = { // initialize with second half of message };
// initialize hmac
if( wc_HmacUpdate(&hmac, msg, sizeof(msg)) != 0) {
// error updating message
}
if( wc_HmacUpdate(&hmac, msg2, sizeof(msg)) != 0) {
// error updating with second message
}
\endcode
\sa wc_HmacSetKey
\sa wc_HmacFinal
*/
int wc_HmacUpdate(Hmac* hmac, const byte* in, word32 sz);
/*!
\ingroup HMAC
\brief この関数は、HMACオブジェクトのメッセージの最終ハッシュを計算します。
\return 0 最後のハッシュの計算に成功した
\return MEMORY_E ハッシュアルゴリズムで使用するためにメモリを割り当てるエラーがある場合
\param hmac 最終ハッシュを計算するHMACオブジェクトへのポインタ
_Example_
\code
Hmac hmac;
byte hash[MD5_DIGEST_SIZE];
// initialize hmac with MD5 as type
// wc_HmacUpdate() with messages
if (wc_HmacFinal(&hmac, hash) != 0) {
// error computing hash
}
\endcode
\sa wc_HmacSetKey
\sa wc_HmacUpdate
*/
int wc_HmacFinal(Hmac* hmac, byte* out);
/*!
\ingroup HMAC
\brief この関数は、構成された暗号スイートに基づいて使用可能な最大のHMACダイジェストサイズを返します。
\return Success 設定された暗号スイートに基づいて使用可能な最大のHMACダイジェストサイズを返します
_Example_
\code
int maxDigestSz = wolfSSL_GetHmacMaxSize();
\endcode
\sa none
*/
int wolfSSL_GetHmacMaxSize(void);
/*!
\ingroup HMAC
\brief この関数は、HMACキー導出機能HKDFへのアクセスを提供します。HMACを利用して、任意のSALTとオプションの情報を派生したキーに変換します。0またはNULLが指定されている場合、ハッシュ型はデフォルトでMD5になります。
\return 0 与えられた入力でキーの生成に成功したら返されます
\return BAD_FUNC_ARG 無効なハッシュ型が引数として指定されている場合に返されます。有効な型は次のとおりです.MD5、SHA、SHA256、SHA384、SHA3-224、SHA3-256、SHA3-384、SHA3-512
\return MEMORY_E メモリの割り当て中にエラーが発生した場合に返されます
\return HMAC_MIN_KEYLEN_E FIPS実装を使用するときに返されることがあり、指定されたキー長は最小許容FIPS規格よりも短いです。
\param type HKDFに使用するハッシュタイプ。有効な型は次のとおりです.MD5、SHA、SHA256、SHA384、SHA3-224、SHA3-256、SHA3-384、SHA3-512
\param inKey KDFに使用するキーを含むバッファへのポインタ
\param inKeySz 入力キーの長さ
\param salt 任意の塩を含む緩衝液へのポインタ。塩を使用しない場合は代わりにNULLを使用してください
\param saltSz 塩の長さ。塩を使用しない場合は0を使用してください
\param info オプションの追加情報を含むバッファへのポインタ。追加情報を追加していない場合はNULLを使用してください
\param infoSz 追加情報の長さ追加情報を使用しない場合は0を使用してください
\param out 派生キーを保存するバッファへのポインタ
_Example_
\code
byte key[] = { // initialize with key };
byte salt[] = { // initialize with salt };
byte derivedKey[MAX_DIGEST_SIZE];
int ret = wc_HKDF(SHA512, key, sizeof(key), salt, sizeof(salt),
NULL, 0, derivedKey, sizeof(derivedKey));
if ( ret != 0 ) {
// error generating derived key
}
\endcode
\sa wc_HmacSetKey
*/
int wc_HKDF(int type, const byte* inKey, word32 inKeySz,
const byte* salt, word32 saltSz,
const byte* info, word32 infoSz,
byte* out, word32 outSz);

View File

@@ -0,0 +1,352 @@
/*!
\ingroup IoTSafe
\brief この関数は与えられたコンテキストでのIoTセーフサポートを有効にします。
\param ctx IOTセーフサポートを有効にする必要があるWOLFSSL_CTXオブジェクトへのポインタ
\return 0 成功した
_Example_
\code
WOLFSSL_CTX *ctx;
ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
if (!ctx)
return NULL;
wolfSSL_CTX_iotsafe_enable(ctx);
\endcode
\sa wolfSSL_iotsafe_on
\sa wolfIoTSafe_SetCSIM_read_cb
\sa wolfIoTSafe_SetCSIM_write_cb
*/
int wolfSSL_CTX_iotsafe_enable(WOLFSSL_CTX *ctx);
/*!
\ingroup IoTSafe
\brief この関数は、IOT-SAFE TLSコールバックを特定のSSLセッションに接続します。
\brief スロットのIDが1バイトの長さの場合、SSLセッションをIoT-Safeアプレットに接続するように呼び出す必要があります。IOTセーフスロットのIDが2バイト以上の場合、\ REF WOLFSSL_IOTSAFE_ON_EX「WOLFSSL_IOTSAFE_ON_EX」を使用する必要があります。
\param ssl コールバックが有効になるWolfSSLオブジェクトへのポインタ
\param privkey_id ホストの秘密鍵を含むIOTセーフなアプレットスロットのID
\param ecdh_keypair_slot ECDH鍵ペアを保存するためのIoT安全アプレットスロットのID
\param peer_pubkey_slot ECDH用の他のエンドポイントの公開鍵を保存するためのIOT-SAFEアプレットスロットのID
\param peer_cert_slot 検証のための他のエンドポイントの公開鍵を保存するためのIOTセーフなアプレットスロットのID
\return 0 成功すると
\return NOT_COMPILED_IN habe_pk_callbacksが無効になっている場合
_Example_
\code
// Define key ids for IoT-Safe
#define PRIVKEY_ID 0x02
#define ECDH_KEYPAIR_ID 0x03
#define PEER_PUBKEY_ID 0x04
#define PEER_CERT_ID 0x05
// Create new ssl session
WOLFSSL *ssl;
ssl = wolfSSL_new(ctx);
if (!ssl)
return NULL;
// Enable IoT-Safe and associate key slots
ret = wolfSSL_CTX_iotsafe_enable(ctx);
if (ret == 0) {
ret = wolfSSL_iotsafe_on(ssl, PRIVKEY_ID, ECDH_KEYPAIR_ID, PEER_PUBKEY_ID, PEER_CERT_ID);
}
\endcode
\sa wolfSSL_iotsafe_on_ex
\sa wolfSSL_CTX_iotsafe_enable
*/
int wolfSSL_iotsafe_on(WOLFSSL *ssl, byte privkey_id,
byte ecdh_keypair_slot, byte peer_pubkey_slot, byte peer_cert_slot);
/*!
\ingroup IoTSafe
\brief この関数は、IOT-SAFE TLSコールバックを特定のSSLセッションに接続します。これは、IOTセーフスロットのIDを参照で渡すことができ、IDフィールドの長さをパラメータ "id_size"で指定できます。
\param ssl コールバックが有効になるWolfSSLオブジェクトへのポインタ
\param privkey_id ホストの秘密鍵を含むIoTセーフアプレットスロットのIDへのポインタ
\param ecdh_keypair_slot ECDH鍵ペアを保存するIOT-SafeアプレットスロットのIDへのポインタ
\param peer_pubkey_slot ECDH用の他のエンドポイントの公開鍵を保存するIOTセーフアプレットスロットのIDへのポインタ
\param peer_cert_slot 検証のために他のエンドポイントの公開鍵を保存するためのIOT-SAFEアプレットスロットのIDへのポインタ
\param id_size 各スロットIDのサイズ
\return 0 成功すると
\return NOT_COMPILED_IN habe_pk_callbacksが無効になっている場合
_Example_
\code
// Define key ids for IoT-Safe (16 bit, little endian)
#define PRIVKEY_ID 0x0201
#define ECDH_KEYPAIR_ID 0x0301
#define PEER_PUBKEY_ID 0x0401
#define PEER_CERT_ID 0x0501
#define ID_SIZE (sizeof(word16))
word16 privkey = PRIVKEY_ID,
ecdh_keypair = ECDH_KEYPAIR_ID,
peer_pubkey = PEER_PUBKEY_ID,
peer_cert = PEER_CERT_ID;
// Create new ssl session
WOLFSSL *ssl;
ssl = wolfSSL_new(ctx);
if (!ssl)
return NULL;
// Enable IoT-Safe and associate key slots
ret = wolfSSL_CTX_iotsafe_enable(ctx);
if (ret == 0) {
ret = wolfSSL_CTX_iotsafe_on_ex(ssl, &privkey, &ecdh_keypair, &peer_pubkey, &peer_cert, ID_SIZE);
}
\endcode
\sa wolfSSL_iotsafe_on
\sa wolfSSL_CTX_iotsafe_enable
*/
int wolfSSL_iotsafe_on_ex(WOLFSSL *ssl, byte *privkey_id,
byte *ecdh_keypair_slot, byte *peer_pubkey_slot, byte *peer_cert_slot, word16 id_size);
/*!
\ingroup IoTSafe
\brief AT + CSIMコマンドのリードコールバックを関連付けます。この入力関数は通常、モデムと通信するUARTチャネルの読み取りイベントに関連付けられています。読み取りコールバックが関連付けられているのは、同時にIoT-Safeサポートを使用するすべてのコンテキストのグローバルと変更です。
_Example_
\code
// USART read function, defined elsewhere
int usart_read(char *buf, int len);
wolfIoTSafe_SetCSIM_read_cb(usart_read);
\endcode
\sa wolfIoTSafe_SetCSIM_write_cb
*/
void wolfIoTSafe_SetCSIM_read_cb(wolfSSL_IOTSafe_CSIM_read_cb rf);
/*!
\ingroup IoTSafe
\brief AT + CSIMコマンドの書き込みコールバックを関連付けます。この出力関数は通常、モデムと通信するUARTチャネル上のライトイベントに関連付けられています。Write Callbackが関連付けられているのは、同時にIoT-Safeサポートを使用するすべてのコンテキストのグローバルと変更です。
_Example_
\code
// USART write function, defined elsewhere
int usart_write(const char *buf, int len);
wolfIoTSafe_SetCSIM_write_cb(usart_write);
\endcode
\sa wolfIoTSafe_SetCSIM_read_cb
*/
void wolfIoTSafe_SetCSIM_write_cb(wolfSSL_IOTSafe_CSIM_write_cb wf);
/*!
\ingroup IoTSafe
\brief IOTセーフ機能getrandomを使用して、指定されたサイズのランダムなバッファを生成します。この関数は、WolfCrypt RNGオブジェクトによって自動的に使用されます。
\param out ランダムなバイトシーケンスが格納されているバッファ。
\param sz 生成するランダムシーケンスのサイズ(バイト単位)
*/
int wolfIoTSafe_GetRandom(unsigned char* out, word32 sz);
/*!
\ingroup IoTSafe
\brief IOT-Safeアプレット上のファイルに保存されている証明書をインポートし、ローカルにメモリに保存します。1バイトのファイルIDフィールドで動作します。
\param id 証明書が保存されているIOTセーフ・アプレットのファイルID
\param output 証明書がインポートされるバッファー
\param sz バッファ出力で使用可能な最大サイズ
\return the 輸入された証明書の長さ
_Example_
\code
#define CRT_CLIENT_FILE_ID 0x03
unsigned char cert_buffer[2048];
// Get the certificate into the buffer
cert_buffer_size = wolfIoTSafe_GetCert(CRT_CLIENT_FILE_ID, cert_buffer, 2048);
if (cert_buffer_size < 1) {
printf("Bad cli cert\n");
return -1;
}
printf("Loaded Client certificate from IoT-Safe, size = %lu\n", cert_buffer_size);
// Use the certificate buffer as identity for the TLS client context
if (wolfSSL_CTX_use_certificate_buffer(cli_ctx, cert_buffer,
cert_buffer_size, SSL_FILETYPE_ASN1) != SSL_SUCCESS) {
printf("Cannot load client cert\n");
return -1;
}
printf("Client certificate successfully imported.\n");
\endcode
*/
int wolfIoTSafe_GetCert(uint8_t id, unsigned char *output, unsigned long sz);
/*!
\ingroup IoTSafe
\brief IOT-Safeアプレット上のファイルに保存されている証明書をインポートし、ローカルにメモリに保存します。\ ref wolfiotsafe_getcert "wolfiotsafe_getcert"と同等です。ただし、2バイト以上のファイルIDで呼び出すことができます。
\param id 証明書が保存されているIOT-SAFEアプレットのファイルIDへのポインタ
\param id_sz ファイルIDのサイズバイト数
\param output 証明書がインポートされるバッファー
\param sz バッファ出力で使用可能な最大サイズ
\return the 輸入された証明書の長さ
_Example_
\code
#define CRT_CLIENT_FILE_ID 0x0302
#define ID_SIZE (sizeof(word16))
unsigned char cert_buffer[2048];
word16 client_file_id = CRT_CLIENT_FILE_ID;
// Get the certificate into the buffer
cert_buffer_size = wolfIoTSafe_GetCert_ex(&client_file_id, ID_SIZE, cert_buffer, 2048);
if (cert_buffer_size < 1) {
printf("Bad cli cert\n");
return -1;
}
printf("Loaded Client certificate from IoT-Safe, size = %lu\n", cert_buffer_size);
// Use the certificate buffer as identity for the TLS client context
if (wolfSSL_CTX_use_certificate_buffer(cli_ctx, cert_buffer,
cert_buffer_size, SSL_FILETYPE_ASN1) != SSL_SUCCESS) {
printf("Cannot load client cert\n");
return -1;
}
printf("Client certificate successfully imported.\n");
\endcode
*/
int wolfIoTSafe_GetCert_ex(uint8_t *id, uint16_t id_sz, unsigned char *output, unsigned long sz);
/*!
\ingroup IoTSafe
\brief IOTセーフアプレットに格納されているECC 256ビットの公開鍵をECC_Keyオブジェクトにインポートします。
\param key IOT-SAFEアプレットからインポートされたキーを含むECC_KEYオブジェクト
\param id 公開鍵が保存されているIOTセーフアプレットのキーID
\return 0 成功すると
\sa wc_iotsafe_ecc_export_public
\sa wc_iotsafe_ecc_export_private
*/
int wc_iotsafe_ecc_import_public(ecc_key *key, byte key_id);
/*!
\ingroup IoTSafe
\brief ECC_KEYオブジェクトからIOT-SAFEアプレットへの書き込み可能なパブリックキースロットにECC 256ビット公開鍵をエクスポートします。
\param key エクスポートする鍵を含むecc_keyオブジェクト
\param id 公開鍵が保存されているIOTセーフアプレットのキーID
\return 0 成功すると
\sa wc_iotsafe_ecc_import_public_ex
\sa wc_iotsafe_ecc_export_private
*/
int wc_iotsafe_ecc_export_public(ecc_key *key, byte key_id);
/*!
\ingroup IoTSafe
\brief ECC_KEYオブジェクトからIOT-SAFEアプレットへの書き込み可能なパブリックキースロットにECC 256ビット公開鍵をエクスポートします。\ ref WC_IOTSAFE_ECC_IMPORT_PUBLIC「WC_IOTSAFE_ECC_IMPORT_PUBLIC」と同等のものは、2バイト以上のキーIDで呼び出すことができる点を除きます。
\param key エクスポートする鍵を含むecc_keyオブジェクト
\param id 公開鍵が保存されるIOTセーフアプレットのキーIDへのポインタ
\param id_size キーIDサイズ
\return 0 成功すると
\sa wc_iotsafe_ecc_import_public
\sa wc_iotsafe_ecc_export_private
*/
int wc_iotsafe_ecc_import_public_ex(ecc_key *key, byte *key_id, word16 id_size);
/*!
\ingroup IoTSafe
\brief ECC 256ビットキーをECC_KEYオブジェクトからIOTセーフアプレットに書き込み可能なプライベートキースロットにエクスポートします。
\param key エクスポートする鍵を含むecc_keyオブジェクト
\param id 秘密鍵が保存されるIOTセーフアプレットのキーID
\return 0 成功すると
\sa wc_iotsafe_ecc_export_private_ex
\sa wc_iotsafe_ecc_import_public
\sa wc_iotsafe_ecc_export_public
*/
int wc_iotsafe_ecc_export_private(ecc_key *key, byte key_id);
/*!
\ingroup IoTSafe
\brief ECC 256ビットキーをECC_KEYオブジェクトからIOTセーフアプレットに書き込み可能なプライベートキースロットにエクスポートします。\ ref WC_IOTSAFE_ECC_EXPORT_PRIVATE「WC_IOTSAFE_ECC_EXPORT_PRIVATE」を除き、2バイト以上のキーIDを呼び出すことができる点を除き、
\param key エクスポートする鍵を含むecc_keyオブジェクト
\param id 秘密鍵が保存されるIOTセーフアプレットのキーIDへのポインタ
\param id_size キーIDサイズ
\return 0 成功すると
\sa wc_iotsafe_ecc_export_private
\sa wc_iotsafe_ecc_import_public
\sa wc_iotsafe_ecc_export_public
*/
int wc_iotsafe_ecc_export_private_ex(ecc_key *key, byte *key_id, word16 id_size);
/*!
\ingroup IoTSafe
\brief 事前計算された256ビットハッシュに署名して、IOT-SAFEアプレットに、以前に保存されたプライベートキー、またはプリプロビジョニングされています。
\param in サインするメッセージハッシュを含むバッファへのポインタ
\param inlen 署名するメッセージの長さ
\param out 生成された署名を保存するためのバッファ
\param outlen 出力バッファの最大長。バイトを保存します
\param id メッセージ署名の生成に成功したときに書き込まれたペイロードに署名するための秘密鍵を含むスロットのIOTセーフアプレットのキーID
\return 0 成功すると
\sa wc_iotsafe_ecc_sign_hash_ex
\sa wc_iotsafe_ecc_verify_hash
\sa wc_iotsafe_ecc_gen_k
*/
int wc_iotsafe_ecc_sign_hash(byte *in, word32 inlen, byte *out, word32 *outlen, byte key_id);
/*!
\ingroup IoTSafe
\brief 事前計算された256ビットハッシュに署名して、IOT-SAFEアプレットに、以前に保存されたプライベートキー、またはプリプロビジョニングされています。\ ref wc_iotsafe_ecc_sign_hash "wc_iotsafe_ecc_sign_hash"と同等です。ただし、2バイト以上のキーIDで呼び出すことができます。
\param in サインするメッセージハッシュを含むバッファへのポインタ
\param inlen 署名するメッセージの長さ
\param out 生成された署名を保存するためのバッファ
\param outlen 出力バッファの最大長。バイトを保存します
\param id 秘密鍵を含むスロットのIOT-SAFEアプレットのキーIDへのポインタメッセージ署名の生成に成功したときに書き込まれるペイロードに署名する
\param id_size キーIDサイズ
\return 0 成功すると
\sa wc_iotsafe_ecc_sign_hash
\sa wc_iotsafe_ecc_verify_hash
\sa wc_iotsafe_ecc_gen_k
*/
int wc_iotsafe_ecc_sign_hash_ex(byte *in, word32 inlen, byte *out, word32 *outlen, byte *key_id, word16 id_size);
/*!
\ingroup IoTSafe
\brief 予め計算された256ビットハッシュに対するECCシグネチャを、IOT-SAFEアプレット内のプリプロビジョニング、またはプロビジョニングされたプリプロビジョニングを使用します。結果はRESに書き込まれます。1が有効で、0が無効です。注有効なテストに戻り値を使用しないでください。Resのみを使用してください。
\return 0 成功すると(署名が無効であっても)
\return < 故障の場合は0
\param sig 検証する署名を含むバッファ
\param hash 署名されたハッシュ(メッセージダイジェスト)
\param hashlen ハッシュの長さ(オクテット)
\param res 署名の結果、1 ==有効、0 ==無効
\sa wc_iotsafe_ecc_verify_hash_ex
\sa wc_iotsafe_ecc_sign_hash
\sa wc_iotsafe_ecc_gen_k
*/
int wc_iotsafe_ecc_verify_hash(byte *sig, word32 siglen, byte *hash, word32 hashlen, int *res, byte key_id);
/*!
\ingroup IoTSafe
\brief 予め計算された256ビットハッシュに対するECCシグネチャを、IOT-SAFEアプレット内のプリプロビジョニング、またはプロビジョニングされたプリプロビジョニングを使用します。結果はRESに書き込まれます。1が有効で、0が無効です。注有効なテストに戻り値を使用しないでください。Resのみを使用してください。\ ref WC_IOTSAFE_ECC_VERIFY_HASH "WC_IOTSAFE_ECC_VERIFY_HASH"を除き、2バイト以上のキーIDで呼び出すことができる点を除きます。
\return 0 成功すると(署名が無効であっても)
\return < 故障の場合は0
\param sig 検証する署名を含むバッファ
\param hash 署名されたハッシュ(メッセージダイジェスト)
\param hashlen ハッシュの長さ(オクテット)
\param res 署名の結果、1 ==有効、0 ==無効
\param key_id パブリックECCキーがIOTセーフアプレットに保存されているスロットのID
\sa wc_iotsafe_ecc_verify_hash
\sa wc_iotsafe_ecc_sign_hash
\sa wc_iotsafe_ecc_gen_k
*/
int wc_iotsafe_ecc_verify_hash_ex(byte *sig, word32 siglen, byte *hash, word32 hashlen, int *res, byte *key_id, word16 id_size);
/*!
\ingroup IoTSafe
\brief ECC 256ビットのキーペアを生成し、それを書き込み可能なスロットにIOTセーフなアプレットに保存します。
\param key_id ECCキーペアがIOTセーフアプレットに格納されているスロットのID。
\return 0 成功すると
\sa wc_iotsafe_ecc_gen_k_ex
\sa wc_iotsafe_ecc_sign_hash
\sa wc_iotsafe_ecc_verify_hash
*/
int wc_iotsafe_ecc_gen_k(byte key_id);
/*!
\ingroup IoTSafe
\brief ECC 256ビットのキーペアを生成し、それを書き込み可能なスロットにIOTセーフなアプレットに保存します。\ ref wc_iotsafe_ecc_gen_k "wc_iotsafe_ecc_gen_k"と同等です。ただし、2バイト以上のキーIDで呼び出すことができます。
\param key_id ECCキーペアがIOTセーフアプレットに格納されているスロットのID。
\param id_size キーIDサイズ
\return 0 成功すると
\sa wc_iotsafe_ecc_gen_k
\sa wc_iotsafe_ecc_sign_hash_ex
\sa wc_iotsafe_ecc_verify_hash_ex
*/
int wc_iotsafe_ecc_gen_k(byte key_id);

View File

@@ -0,0 +1,51 @@
/*!
\ingroup Logging
\brief この関数は、WolfSSLログメッセージを処理するために使用されるロギングコールバックを登録します。デフォルトでは、システムがIT fprintfをSTDERRにサポートしている場合は、この関数を使用することによって、ユーザーによって何でも実行できます。
\return Success 成功した場合、この関数は0を返します。
\return BAD_FUNC_ARG 関数ポインタが提供されていない場合に返されるエラーです。
_Example_
\code
int ret = 0;
// Logging callback prototype
void MyLoggingCallback(const int logLevel, const char* const logMessage);
// Register the custom logging callback with wolfSSL
ret = wolfSSL_SetLoggingCb(MyLoggingCallback);
if (ret != 0) {
// failed to set logging callback
}
void MyLoggingCallback(const int logLevel, const char* const logMessage)
{
// custom logging function
}
\endcode
\sa wolfSSL_Debugging_ON
\sa wolfSSL_Debugging_OFF
*/
int wolfSSL_SetLoggingCb(wolfSSL_Logging_cb log_function);
/*!
\ingroup Debug
\brief ビルド時にロギングが有効になっている場合、この関数は実行時にロギングをオンにします。ビルド時にログ記録を有効にするには--enable-debugまたはdebug_wolfsslを定義します。
\return 0 成功すると。
\return NOT_COMPILED_IN このビルドに対してロギングが有効になっていない場合は返されるエラーです。
_Example_
\code
wolfSSL_Debugging_ON();
\endcode
\sa wolfSSL_Debugging_OFF
\sa wolfSSL_SetLoggingCb
*/
int wolfSSL_Debugging_ON(void);
/*!
\ingroup Debug
\brief この関数はランタイムロギングメッセージをオフにします。彼らがすでに消えている場合は、行動はとられません。
\return none いいえ返します。
_Example_
\code
wolfSSL_Debugging_OFF();
\endcode
\sa wolfSSL_Debugging_ON
\sa wolfSSL_SetLoggingCb
*/
void wolfSSL_Debugging_OFF(void);

View File

@@ -0,0 +1,88 @@
/*!
\ingroup MD2
\brief この関数はMD2を初期化します。これはWC_MD2HASHによって自動的に呼び出されます。
\return 0 初期化に成功したときに返されます
_Example_
\code
md2 md2[1];
if ((ret = wc_InitMd2(md2)) != 0) {
WOLFSSL_MSG("wc_Initmd2 failed");
}
else {
wc_Md2Update(md2, data, len);
wc_Md2Final(md2, hash);
}
\endcode
\sa wc_Md2Hash
\sa wc_Md2Update
\sa wc_Md2Final
*/
void wc_InitMd2(Md2*);
/*!
\ingroup MD2
\brief 長さLENの提供されたバイト配列を絶えずハッシュするように呼び出すことができます。
\return 0 データをダイジェストに正常に追加すると返されます。
\param md2 暗号化に使用するMD2構造へのポインタ
\param data ハッシュするデータ
_Example_
\code
md2 md2[1];
byte data[] = { }; // Data to be hashed
word32 len = sizeof(data);
if ((ret = wc_InitMd2(md2)) != 0) {
WOLFSSL_MSG("wc_Initmd2 failed");
}
else {
wc_Md2Update(md2, data, len);
wc_Md2Final(md2, hash);
}
\endcode
\sa wc_Md2Hash
\sa wc_Md2Final
\sa wc_InitMd2
*/
void wc_Md2Update(Md2* md2, const byte* data, word32 len);
/*!
\ingroup MD2
\brief データのハッシュを確定します。結果はハッシュに入れられます。
\return 0 ファイナライズに成功したときに返されます。
\param md2 暗号化に使用するMD2構造へのポインタ
_Example_
\code
md2 md2[1];
byte data[] = { }; // Data to be hashed
word32 len = sizeof(data);
if ((ret = wc_InitMd2(md2)) != 0) {
WOLFSSL_MSG("wc_Initmd2 failed");
}
else {
wc_Md2Update(md2, data, len);
wc_Md2Final(md2, hash);
}
\endcode
\sa wc_Md2Hash
\sa wc_Md2Final
\sa wc_InitMd2
*/
void wc_Md2Final(Md2* md2, byte* hash);
/*!
\ingroup MD2
\brief 利便性機能は、すべてのハッシュを処理し、その結果をハッシュに入れます。
\return 0 データを正常にハッシュしたときに返されます。
\return Memory_E メモリエラー、メモリを割り当てることができません。これは、小さなスタックオプションが有効になっているだけです。
\param data ハッシュへのデータ
\param len データの長さ
_Example_
\code
none
\endcode
\sa wc_Md2Hash
\sa wc_Md2Final
\sa wc_InitMd2
*/
int wc_Md2Hash(const byte* data, word32 len, byte* hash);

View File

@@ -0,0 +1,68 @@
/*!
\ingroup MD4
\brief この関数はMD4を初期化します。これはWC_MD4HASHによって自動的に呼び出されます。
\return 0 初期化に成功したときに返されます
_Example_
\code
md4 md4[1];
if ((ret = wc_InitMd4(md4)) != 0) {
WOLFSSL_MSG("wc_Initmd4 failed");
}
else {
wc_Md4Update(md4, data, len);
wc_Md4Final(md4, hash);
}
\endcode
\sa wc_Md4Hash
\sa wc_Md4Update
\sa wc_Md4Final
*/
void wc_InitMd4(Md4*);
/*!
\ingroup MD4
\brief 長さLENの提供されたバイト配列を絶えずハッシュするように呼び出すことができます。
\return 0 データをダイジェストに正常に追加すると返されます。
\param md4 暗号化に使用するMD4構造へのポインタ
\param data ハッシュするデータ
_Example_
\code
md4 md4[1];
byte data[] = { }; // Data to be hashed
word32 len = sizeof(data);
if ((ret = wc_InitMd4(md4)) != 0) {
WOLFSSL_MSG("wc_Initmd4 failed");
}
else {
wc_Md4Update(md4, data, len);
wc_Md4Final(md4, hash);
}
\endcode
\sa wc_Md4Hash
\sa wc_Md4Final
\sa wc_InitMd4
*/
void wc_Md4Update(Md4* md4, const byte* data, word32 len);
/*!
\ingroup MD4
\brief データのハッシュを確定します。結果はハッシュに入れられます。
\return 0 ファイナライズに成功したときに返されます。
\param md4 暗号化に使用するMD4構造へのポインタ
_Example_
\code
md4 md4[1];
if ((ret = wc_InitMd4(md4)) != 0) {
WOLFSSL_MSG("wc_Initmd4 failed");
}
else {
wc_Md4Update(md4, data, len);
wc_Md4Final(md4, hash);
}
\endcode
\sa wc_Md4Hash
\sa wc_Md4Final
\sa wc_InitMd4
*/
void wc_Md4Final(Md4* md4, byte* hash);

View File

@@ -0,0 +1,140 @@
/*!
\ingroup MD5
\brief この関数はMD5を初期化します。これはWC_MD5HASHによって自動的に呼び出されます。
\return 0 初期化に成功したときに返されます。
\return BAD_FUNC_ARG MD5構造がNULL値として渡された場合に返されます。
_Example_
\code
Md5 md5;
byte* hash;
if ((ret = wc_InitMd5(&md5)) != 0) {
WOLFSSL_MSG("wc_Initmd5 failed");
}
else {
ret = wc_Md5Update(&md5, data, len);
if (ret != 0) {
// Md5 Update Failure Case.
}
ret = wc_Md5Final(&md5, hash);
if (ret != 0) {
// Md5 Final Failure Case.
}
}
\endcode
\sa wc_Md5Hash
\sa wc_Md5Update
\sa wc_Md5Final
*/
int wc_InitMd5(wc_Md5*);
/*!
\ingroup MD5
\brief 長さLENの提供されたバイト配列を絶えずハッシュするように呼び出すことができます。
\return 0 データをダイジェストに正常に追加すると返されます。
\return BAD_FUNC_ARG MD5構造がNULLの場合、またはデータがNULLで、LENがゼロより大きい場合に返されます。DATAパラメーターがNULLでLENがゼロの場合、関数はエラーを返してはいけません。
\param md5 暗号化に使用するMD5構造へのポインタ
\param data ハッシュするデータ
_Example_
\code
Md5 md5;
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitMd5(&md5)) != 0) {
WOLFSSL_MSG("wc_Initmd5 failed");
}
else {
ret = wc_Md5Update(&md5, data, len);
if (ret != 0) {
// Md5 Update Error Case.
}
ret = wc_Md5Final(&md5, hash);
if (ret != 0) {
// Md5 Final Error Case.
}
}
\endcode
\sa wc_Md5Hash
\sa wc_Md5Final
\sa wc_InitMd5
*/
int wc_Md5Update(wc_Md5* md5, const byte* data, word32 len);
/*!
\ingroup MD5
\brief データのハッシュを確定します。結果はハッシュに入れられます。MD5構造体がリセットされます。注この関数は、habe_intel_qaが定義されている場合にintelqasymmd5を呼び出す結果も返します。
\return 0 ファイナライズに成功したときに返されます。
\return BAD_FUNC_ARG MD5構造またはハッシュポインタがNULLで渡された場合に返されます。
\param md5 暗号化に使用するMD5構造へのポインタ
_Example_
\code
md5 md5[1];
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitMd5(md5)) != 0) {
WOLFSSL_MSG("wc_Initmd5 failed");
}
else {
ret = wc_Md5Update(md5, data, len);
if (ret != 0) {
// Md5 Update Failure Case.
}
ret = wc_Md5Final(md5, hash);
if (ret != 0) {
// Md5 Final Failure Case.
}
}
\endcode
\sa wc_Md5Hash
\sa wc_InitMd5
\sa wc_Md5GetHash
*/
int wc_Md5Final(wc_Md5* md5, byte* hash);
/*!
\ingroup MD5
\brief MD5構造をリセットします。注これは、wolfssl_ti_hashが定義されている場合にのみサポートされています。
\return none いいえ返します。
_Example_
\code
Md5 md5;
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitMd5(&md5)) != 0) {
WOLFSSL_MSG("wc_InitMd5 failed");
}
else {
wc_Md5Update(&md5, data, len);
wc_Md5Final(&md5, hash);
wc_Md5Free(&md5);
}
\endcode
\sa wc_InitMd5
\sa wc_Md5Update
\sa wc_Md5Final
*/
void wc_Md5Free(wc_Md5*);
/*!
\ingroup MD5
\brief ハッシュデータを取得します。結果はハッシュに入れられます。MD5構造はリセットされません。
\return none いいえリターン
\param md5 暗号化に使用するMD5構造へのポインタ。
_Example_
\code
md5 md5[1];
if ((ret = wc_InitMd5(md5)) != 0) {
WOLFSSL_MSG("wc_Initmd5 failed");
}
else {
wc_Md5Update(md5, data, len);
wc_Md5GetHash(md5, hash);
}
\endcode
\sa wc_Md5Hash
\sa wc_Md5Final
\sa wc_InitMd5
*/
int wc_Md5GetHash(wc_Md5* md5, byte* hash);

View File

@@ -0,0 +1,145 @@
/*!
\ingroup Memory
\brief この関数はmallocと似ていますが、WolfSSLが使用するように構成されているメモリ割り当て関数を呼び出します。デフォルトでは、WolfSSLはmallocを使用します。これは、WolfSSLメモリ抽象化レイヤを使用して変更できます - wolfssl_setAllocatorを参照してください。注WOLFSSL_MALLOCは、WOLFSSLによって直接呼び出されませんが、代わりにMacro XMallocによって呼び出されます。デフォルトのビルドの場合、size引数のみが存在します。wolfssl_static_memoryビルドを使用する場合は、ヒープとタイプ引数が含まれます。
\return pointer 成功した場合、この関数は割り当てられたメモリへのポインタを返します。
\return error エラーがある場合は、NULLが返されます。
\param size 割り当てるメモリのサイズ(バイト)
\param heap メモリに使用するヒントヒント。nullになることができます
_Example_
\code
int* tenInts = (int*)wolfSSL_Malloc(sizeof(int)*10);
\endcode
\sa wolfSSL_Free
\sa wolfSSL_Realloc
\sa wolfSSL_SetAllocators
\sa XMALLOC
\sa XFREE
\sa XREALLOC
*/
void* wolfSSL_Malloc(size_t size, void* heap, int type);
/*!
\ingroup Memory
\brief この関数はfreeと似ていますが、WolfSSLが使用するように構成されているメモリフリー機能を呼び出します。デフォルトでは、WolfSSLはfreeを使用します。これは、WolfSSLメモリ抽象化レイヤを使用して変更できます - wolfssl_setAllocatorを参照してください。注WOLFSSL_FREEはWOLFSSLによって直接呼び出されませんが、代わりにマクロXFreeによって呼び出されます。デフォルトのビルドの場合、PTR引数のみが存在します。wolfssl_static_memoryビルドを使用する場合は、ヒープとタイプ引数が含まれます。
\return none いいえ返します。
\param ptr 解放されるメモリへのポインタ。
\param heap メモリに使用するヒントヒント。nullになることができます
_Example_
\code
int* tenInts = (int*)wolfSSL_Malloc(sizeof(int)*10);
// process data as desired
...
if(tenInts) {
wolfSSL_Free(tenInts);
}
\endcode
\sa wolfSSL_Alloc
\sa wolfSSL_Realloc
\sa wolfSSL_SetAllocators
\sa XMALLOC
\sa XFREE
\sa XREALLOC
*/
void wolfSSL_Free(void *ptr, void* heap, int type);
/*!
\ingroup Memory
\brief この関数はREALLOCと似ていますが、WolfSSLが使用するように構成されているメモリ再割り当て機能を呼び出します。デフォルトでは、WolfSSLはRealLocを使用します。これは、WolfSSLメモリ抽象化レイヤを使用して変更できます - wolfssl_setAllocatorを参照してください。注WOLFSSL_REALLOCはWOLFSSLによって直接呼び出されませんが、代わりにマクロXreallocによって呼び出されます。デフォルトのビルドの場合、size引数のみが存在します。wolfssl_static_memoryビルドを使用する場合は、ヒープとタイプ引数が含まれます。
\return pointer 成功した場合、この関数はマイポイントを再割り当てするためのポインタを返します。これはPTRと同じポインタ、または新しいポインタの場所であり得る。
\return Null エラーがある場合は、NULLが返されます。
\param ptr 再割り当てされているメモリへのポインタ。
\param size 割り当てるバイト数。
\param heap メモリに使用するヒントヒント。nullになることができます
_Example_
\code
int* tenInts = (int*)wolfSSL_Malloc(sizeof(int)*10);
int* twentyInts = (int*)wolfSSL_Realloc(tenInts, sizeof(int)*20);
\endcode
\sa wolfSSL_Free
\sa wolfSSL_Malloc
\sa wolfSSL_SetAllocators
\sa XMALLOC
\sa XFREE
\sa XREALLOC
*/
void* wolfSSL_Realloc(void *ptr, size_t size, void* heap, int type);
/*!
\ingroup Memory
\brief この機能は、WolfSSLが使用する割り当て関数を登録します。デフォルトでは、システムがそれをサポートしている場合、Malloc / FreeとRealLocが使用されます。この機能を使用すると、実行時にユーザーは独自のメモリハンドラをインストールできます。
\return Success 成功した場合、この関数は0を返します。
\return BAD_FUNC_ARG 関数ポインタが提供されていない場合に返されるエラーです。
\param malloc_function 使用するWolfSSLのメモリ割り当て機能関数署名は、上記のwolfssl_malloc_cbプロトタイプと一致する必要があります。
\param free_function 使用するWolfSSLのメモリフリー機能関数シグネチャは、上記のwolfssl_free_cbプロトタイプと一致する必要があります。
_Example_
\code
static void* MyMalloc(size_t size)
{
// custom malloc function
}
static void MyFree(void* ptr)
{
// custom free function
}
static void* MyRealloc(void* ptr, size_t size)
{
// custom realloc function
}
// Register custom memory functions with wolfSSL
int ret = wolfSSL_SetAllocators(MyMalloc, MyFree, MyRealloc);
if (ret != 0) {
// failed to set memory functions
}
\endcode
\sa none
*/
int wolfSSL_SetAllocators(wolfSSL_Malloc_cb,
wolfSSL_Free_cb,
wolfSSL_Realloc_cb);
/*!
\ingroup Memory
\brief この機能は、静的メモリ機能が使用されている場合(--enable-staticMemoryの場合に使用できます。メモリの「バケット」に最適なバッファサイズを示します。これにより、パーティション化された後に追加の未使用のメモリが終了しないように、バッファサイズを計算する方法が可能になります。返された値は、正の場合、使用するコンピュータのバッファサイズです。
\return Success バッファサイズ計算を正常に完了すると、正の値が返されます。この返された値は最適なバッファサイズです。
\return Failure すべての負の値はエラーの場合と見なされます。
\param buffer バッファへのポインタ
\param size バッファのサイズ
_Example_
\code
byte buffer[1000];
word32 size = sizeof(buffer);
int optimum;
optimum = wolfSSL_StaticBufferSz(buffer, size, WOLFMEM_GENERAL);
if (optimum < 0) { //handle error case }
printf(“The optimum buffer size to make use of all memory is %d\n”,
optimum);
...
\endcode
\sa wolfSSL_Malloc
\sa wolfSSL_Free
*/
int wolfSSL_StaticBufferSz(byte* buffer, word32 sz, int flag);
/*!
\ingroup Memory
\brief この機能は、静的メモリ機能が使用されている場合(--enable-staticMemoryの場合に使用できます。メモリの各パーティションに必要なパディングのサイズを示します。このパディングサイズは、メモリアライメントのために追加のメモリ管理構造を含む必要があるサイズになります。
\return On 正常なメモリパディング計算戻り値は正の値になります
\return All 負の値はエラーケースと見なされます。
_Example_
\code
int padding;
padding = wolfSSL_MemoryPaddingSz();
if (padding < 0) { //handle error case }
printf(“The padding size needed for each \”bucket\” of memory is %d\n”,
padding);
// calculation of buffer for IO POOL size is number of buckets
// times (padding + WOLFMEM_IO_SZ)
...
\endcode
\sa wolfSSL_Malloc
\sa wolfSSL_Free
*/
int wolfSSL_MemoryPaddingSz(void);

View File

@@ -0,0 +1,27 @@
/*!
\ingroup openSSL
\brief この関数は、PEM形式のwolfssl_bio構造体にキーを書き込みます。
\return SSL_SUCCESS 成功すると。
\return SSL_FAILURE 失敗すると。
\param bio wolfssl_bio構造体からPEMバッファを取得します。
\param key PEM形式に変換するためのキー。
\param cipher EVP暗号構造
\param passwd パスワード。
\param len パスワードの長さ
\param cb パスワードコールバック
_Example_
\code
WOLFSSL_BIO* bio;
WOLFSSL_EVP_PKEY* key;
int ret;
// create bio and setup key
ret = wolfSSL_PEM_write_bio_PrivateKey(bio, key, NULL, NULL, 0, NULL, NULL);
//check ret value
\endcode
\sa wolfSSL_PEM_read_bio_X509_AUX
*/
int wolfSSL_PEM_write_bio_PrivateKey(WOLFSSL_BIO* bio, WOLFSSL_EVP_PKEY* key,
const WOLFSSL_EVP_CIPHER* cipher,
unsigned char* passwd, int len,
wc_pem_password_cb* cb, void* arg);

View File

@@ -0,0 +1,35 @@
/*!
*/
int wc_Pkcs11_Initialize(Pkcs11Dev* dev, const char* library,
void* heap);
/*!
*/
void wc_Pkcs11_Finalize(Pkcs11Dev* dev);
/*!
*/
int wc_Pkcs11Token_Init(Pkcs11Token* token, Pkcs11Dev* dev,
int slotId, const char* tokenName, const unsigned char *userPin,
int userPinSz);
/*!
*/
void wc_Pkcs11Token_Final(Pkcs11Token* token);
/*!
*/
int wc_Pkcs11Token_Open(Pkcs11Token* token, int readWrite);
/*!
*/
void wc_Pkcs11Token_Close(Pkcs11Token* token);
/*!
*/
int wc_Pkcs11StoreKey(Pkcs11Token* token, int type, int clear,
/*!
*/
int wc_Pkcs11_CryptoDevCb(int devId, wc_CryptoInfo* info,
void* ctx);

View File

@@ -0,0 +1,428 @@
/*!
\ingroup PKCS7
\brief この関数は、DERフォーマットの証明書を使用してPKCS7構造を初期化します。空のPKCS7構造を初期化するには、NULL CERTとCERTSZの場合は0を渡すことができます。
\return 0 PKCS7構造の初期化に成功しました
\return MEMORY_E xmallocでメモリを割り当てるエラーがある場合
\return ASN_PARSE_E 証明書ヘッダーの解析中にエラーがある場合
\return ASN_OBJECT_ID_E 証明書から暗号化タイプの解析中にエラーがある場合に返されます
\return ASN_EXPECT_0_E CERTファイルの暗号化仕様にフォーマットエラーがある場合
\return ASN_BEFORE_DATE_E 日付が証明書開始日以前の場合返却
\return ASN_AFTER_DATE_E 日付が証明書の有効期限の後にある場合に返されます
\return ASN_BITSTR_E 証明書からビット文字列を解析したエラーがある場合に返されます。
\return ECC_CURVE_OID_E 証明書からECCキーの解析中にエラーがある場合
\return ASN_UNKNOWN_OID_E 証明書が不明なキーオブジェクトIDを使用している場合に返されます
\return ASN_VERSION_E allow_v1_extensionsオプションが定義されておらず、証明書がV1またはV2の証明書の場合に返されます。
\return BAD_FUNC_ARG 証明書拡張機能の処理中にエラーがある場合
\return ASN_CRIT_EXT_E 証明書の処理中になじみのない重要な拡張機能が発生した場合に返されます。
\return ASN_SIG_OID_E 署名暗号化タイプが提供されたファイル内の証明書の暗号化タイプと同じでない場合に返されます。
\return ASN_SIG_CONFIRM_E 認証署名が失敗したことを確認した場合に返されます
\return ASN_NAME_INVALID_E 証明書の名前がCA名制約によって許可されていない場合に返されます。
\return ASN_NO_SIGNER_E 証明書の真正性を確認するためのCA署名者がない場合に返されました
\param pkcs7 デコードされた証明書を保存するPKCS7構造へのポインタ
\param cert PKCS7構造を初期化するためのDERフォーマットのASN.1証明書を含むバッファへのポインタ
_Example_
\code
PKCS7 pkcs7;
byte derBuff[] = { }; // initialize with DER-encoded certificate
if ( wc_PKCS7_InitWithCert(&pkcs7, derBuff, sizeof(derBuff)) != 0 ) {
// error parsing certificate into pkcs7 format
}
\endcode
\sa wc_PKCS7_Free
*/
int wc_PKCS7_InitWithCert(PKCS7* pkcs7, byte* cert, word32 certSz);
/*!
\ingroup PKCS7
\brief この関数は、PKCS7の初期化装置によって割り当てられたメモリを解放します。
\return none いいえ返します。
_Example_
\code
PKCS7 pkcs7;
// initialize and use PKCS7 object
wc_PKCS7_Free(pkcs7);
\endcode
\sa wc_PKCS7_InitWithCert
*/
void wc_PKCS7_Free(PKCS7* pkcs7);
/*!
\ingroup PKCS7
\brief この関数はPKCS7データコンテンツタイプを構築し、PKCS7構造をパーセル可能なPKCS7データパケットを含むバッファにエンコードします。
\return Success PKCS7データをバッファに正常にエンコードすると、PKCS7構造内の索引を返します。このインデックスは、出力バッファに書き込まれたバイトにも対応しています。
\return BUFFER_E 指定されたバッファがエンコードされた証明書を保持するのに十分な大きさでない場合に返されます
\param pkcs7 符号化するPKCS7構造へのポインタ
\param output エンコードされた証明書を保存するバッファへのポインタ
_Example_
\code
PKCS7 pkcs7;
int ret;
byte derBuff[] = { }; // initialize with DER-encoded certificate
byte pkcs7Buff[FOURK_BUF];
wc_PKCS7_InitWithCert(&pkcs7, derBuff, sizeof(derBuff));
// update message and data to encode
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
pkcs7.content = data;
pkcs7.contentSz = dataSz;
... etc.
ret = wc_PKCS7_EncodeData(&pkcs7, pkcs7Buff, sizeof(pkcs7Buff));
if ( ret != 0 ) {
// error encoding into output buffer
}
\endcode
\sa wc_PKCS7_InitWithCert
*/
int wc_PKCS7_EncodeData(PKCS7* pkcs7, byte* output,
word32 outputSz);
/*!
\ingroup PKCS7
\brief この関数はPKCS7署名付きデータコンテンツタイプを構築し、PKCS7構造をPARSable PKCS7署名付きデータパケットを含むバッファにエンコードします。
\return Success PKCS7データをバッファに正常にエンコードすると、PKCS7構造内の索引を返します。このインデックスは、出力バッファに書き込まれたバイトにも対応しています。
\return BAD_FUNC_ARG PKCS7構造が署名付きデータパケットを生成するための1つ以上の要求要素が欠落している場合に返されます。
\return MEMORY_E メモリの割り当て中にエラーが発生した場合に返されます
\return PUBLIC_KEY_E 公開鍵の解析中にエラーがある場合
\return RSA_BUFFER_E バッファエラーが発生した場合は、小さすぎたり入力が大きすぎたりし過ぎました
\return BUFFER_E 指定されたバッファがエンコードされた証明書を保持するのに十分な大きさでない場合に返されます
\return MP_INIT_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_READ_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_CMP_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_INVMOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_EXPTMOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MUL_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_ADD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MULMOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_TO_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MEM 署名を生成するエラーがある場合は返却される可能性があります
\param pkcs7 符号化するPKCS7構造へのポインタ
\param output エンコードされた証明書を保存するバッファへのポインタ
_Example_
\code
PKCS7 pkcs7;
int ret;
byte data[] = {}; // initialize with data to sign
byte derBuff[] = { }; // initialize with DER-encoded certificate
byte pkcs7Buff[FOURK_BUF];
wc_PKCS7_InitWithCert(&pkcs7, derBuff, sizeof(derBuff));
// update message and data to encode
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
pkcs7.content = data;
pkcs7.contentSz = dataSz;
pkcs7.hashOID = SHAh;
pkcs7.rng = &rng;
... etc.
ret = wc_PKCS7_EncodeSignedData(&pkcs7, pkcs7Buff, sizeof(pkcs7Buff));
if ( ret != 0 ) {
// error encoding into output buffer
}
wc_PKCS7_Free(&pkcs7);
\endcode
\sa wc_PKCS7_InitWithCert
\sa wc_PKCS7_VerifySignedData
*/
int wc_PKCS7_EncodeSignedData(PKCS7* pkcs7,
byte* output, word32 outputSz);
/*!
\ingroup PKCS7
\brief この関数は、PKCS7の署名付きデータコンテンツタイプを構築し、PKCS7構造をエンコードし、Parsable PKCS7署名付きデータパケットを含むヘッダーおよびフッターバッファにエンコードします。これにはコンテンツは含まれません。ハッシュを計算してデータに提供する必要があります
\return 0=Success
\return BAD_FUNC_ARG PKCS7構造が署名付きデータパケットを生成するための1つ以上の要求要素が欠落している場合に返されます。
\return MEMORY_E メモリの割り当て中にエラーが発生した場合に返されます
\return PUBLIC_KEY_E 公開鍵の解析中にエラーがある場合
\return RSA_BUFFER_E バッファエラーが発生した場合は、小さすぎたり入力が大きすぎたりし過ぎました
\return BUFFER_E 指定されたバッファがエンコードされた証明書を保持するのに十分な大きさでない場合に返されます
\return MP_INIT_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_READ_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_CMP_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_INVMOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_EXPTMOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MUL_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_ADD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MULMOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_TO_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MEM 署名を生成するエラーがある場合は返却される可能性があります
\param pkcs7 符号化するPKCS7構造へのポインタ
\param hashBuf コンテンツデータの計算ハッシュへのポインタ
\param hashSz ダイジェストのサイズ
\param outputHead エンコードされた証明書ヘッダーを保存するバッファへのポインタ
\param outputHeadSz 出力ヘッダーバッファのサイズが入力され、実際のサイズを返します。
\param outputFoot エンコードされた証明書フッターを保存するバッファへのポインタ
_Example_
\code
PKCS7 pkcs7;
int ret;
byte derBuff[] = { }; // initialize with DER-encoded certificate
byte data[] = {}; // initialize with data to sign
byte pkcs7HeadBuff[FOURK_BUF/2];
byte pkcs7FootBuff[FOURK_BUF/2];
word32 pkcs7HeadSz = (word32)sizeof(pkcs7HeadBuff);
word32 pkcs7FootSz = (word32)sizeof(pkcs7HeadBuff);
enum wc_HashType hashType = WC_HASH_TYPE_SHA;
byte hashBuf[WC_MAX_DIGEST_SIZE];
word32 hashSz = wc_HashGetDigestSize(hashType);
wc_PKCS7_InitWithCert(&pkcs7, derBuff, sizeof(derBuff));
// update message and data to encode
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
pkcs7.content = NULL;
pkcs7.contentSz = dataSz;
pkcs7.hashOID = SHAh;
pkcs7.rng = &rng;
... etc.
// calculate hash for content
ret = wc_HashInit(&hash, hashType);
if (ret == 0) {
ret = wc_HashUpdate(&hash, hashType, data, sizeof(data));
if (ret == 0) {
ret = wc_HashFinal(&hash, hashType, hashBuf);
}
wc_HashFree(&hash, hashType);
}
ret = wc_PKCS7_EncodeSignedData_ex(&pkcs7, hashBuf, hashSz, pkcs7HeadBuff,
&pkcs7HeadSz, pkcs7FootBuff, &pkcs7FootSz);
if ( ret != 0 ) {
// error encoding into output buffer
}
wc_PKCS7_Free(&pkcs7);
\endcode
\sa wc_PKCS7_InitWithCert
\sa wc_PKCS7_VerifySignedData_ex
*/
int wc_PKCS7_EncodeSignedData_ex(PKCS7* pkcs7, const byte* hashBuf,
word32 hashSz, byte* outputHead, word32* outputHeadSz, byte* outputFoot,
word32* outputFootSz);
/*!
\ingroup PKCS7
\brief この関数は、送信されたPKCS7の署名付きデータメッセージを取り、証明書リストと証明書失効リストを抽出してから署名を検証します。与えられたPKCS7構造に抽出されたコンテンツを格納します。
\return 0 メッセージから情報を抽出することに成功しました
\return BAD_FUNC_ARG 入力パラメータの1つが無効な場合は返されます
\return ASN_PARSE_E 与えられたPKIMSGから解析中のエラーがある場合に返されます
\return PKCS7_OID_E 与えられたPKIMSGが署名付きデータ型ではない場合に返されます
\return ASN_VERSION_E PKCS7署名者情報がバージョン1ではない場合に返されます
\return MEMORY_E メモリの割り当て中にエラーが発生した場合に返されます
\return PUBLIC_KEY_E 公開鍵の解析中にエラーがある場合
\return RSA_BUFFER_E バッファエラーが発生した場合は、小さすぎたり入力が大きすぎたりし過ぎません
\return BUFFER_E 指定されたバッファがエンコードされた証明書を保持するのに十分な大きさでない場合に返されます
\return MP_INIT_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_READ_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_CMP_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_INVMOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_EXPTMOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MUL_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_ADD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MULMOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_TO_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MEM 署名を生成するエラーがある場合は返却される可能性があります
\param pkcs7 解析された証明書を保存するPKCS7構造へのポインタ
\param pkiMsg 署名されたメッセージを含むバッファへのポインタを検証および復号化する
_Example_
\code
PKCS7 pkcs7;
int ret;
byte pkcs7Buff[] = {}; // the PKCS7 signature
wc_PKCS7_InitWithCert(&pkcs7, NULL, 0);
// update message and data to encode
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
pkcs7.content = data;
pkcs7.contentSz = dataSz;
... etc.
ret = wc_PKCS7_VerifySignedData(&pkcs7, pkcs7Buff, sizeof(pkcs7Buff));
if ( ret != 0 ) {
// error encoding into output buffer
}
wc_PKCS7_Free(&pkcs7);
\endcode
\sa wc_PKCS7_InitWithCert
\sa wc_PKCS7_EncodeSignedData
*/
int wc_PKCS7_VerifySignedData(PKCS7* pkcs7,
byte* pkiMsg, word32 pkiMsgSz);
/*!
\ingroup PKCS7
\brief この機能は、送信されたPKCS7署名付きデータメッセージをHASH /ヘッダー/フッターとして取り出してから、証明書リストと証明書失効リストを抽出してから、署名を検証します。与えられたPKCS7構造に抽出されたコンテンツを格納します。
\return 0 メッセージから情報を抽出することに成功しました
\return BAD_FUNC_ARG 入力パラメータの1つが無効な場合は返されます
\return ASN_PARSE_E 与えられたPKIMSGから解析中のエラーがある場合に返されます
\return PKCS7_OID_E 与えられたPKIMSGが署名付きデータ型ではない場合に返されます
\return ASN_VERSION_E PKCS7署名者情報がバージョン1ではない場合に返されます
\return MEMORY_E メモリの割り当て中にエラーが発生した場合に返されます
\return PUBLIC_KEY_E 公開鍵の解析中にエラーがある場合
\return RSA_BUFFER_E バッファエラーが発生した場合は、小さすぎたり入力が大きすぎたりし過ぎません
\return BUFFER_E 指定されたバッファがエンコードされた証明書を保持するのに十分な大きさでない場合に返されます
\return MP_INIT_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_READ_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_CMP_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_INVMOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_EXPTMOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MUL_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_ADD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MULMOD_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_TO_E 署名を生成するエラーがある場合は返却される可能性があります
\return MP_MEM 署名を生成するエラーがある場合は返却される可能性があります
\param pkcs7 解析された証明書を保存するPKCS7構造へのポインタ
\param hashBuf コンテンツデータの計算ハッシュへのポインタ
\param hashSz ダイジェストのサイズ
\param pkiMsgHead 署名されたメッセージヘッダーを含むバッファへのポインタを検証およびデコードする
\param pkiMsgHeadSz 署名付きメッセージヘッダーのサイズ
\param pkiMsgFoot 署名されたメッセージフッターを含むバッファへのポインタを検証してデコードする
_Example_
\code
PKCS7 pkcs7;
int ret;
byte data[] = {}; // initialize with data to sign
byte pkcs7HeadBuff[] = {}; // initialize with PKCS7 header
byte pkcs7FootBuff[] = {}; // initialize with PKCS7 footer
enum wc_HashType hashType = WC_HASH_TYPE_SHA;
byte hashBuf[WC_MAX_DIGEST_SIZE];
word32 hashSz = wc_HashGetDigestSize(hashType);
wc_PKCS7_InitWithCert(&pkcs7, NULL, 0);
// update message and data to encode
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
pkcs7.content = NULL;
pkcs7.contentSz = dataSz;
pkcs7.rng = &rng;
... etc.
// calculate hash for content
ret = wc_HashInit(&hash, hashType);
if (ret == 0) {
ret = wc_HashUpdate(&hash, hashType, data, sizeof(data));
if (ret == 0) {
ret = wc_HashFinal(&hash, hashType, hashBuf);
}
wc_HashFree(&hash, hashType);
}
ret = wc_PKCS7_VerifySignedData_ex(&pkcs7, hashBuf, hashSz, pkcs7HeadBuff,
sizeof(pkcs7HeadBuff), pkcs7FootBuff, sizeof(pkcs7FootBuff));
if ( ret != 0 ) {
// error encoding into output buffer
}
wc_PKCS7_Free(&pkcs7);
\endcode
\sa wc_PKCS7_InitWithCert
\sa wc_PKCS7_EncodeSignedData_ex
*/
int wc_PKCS7_VerifySignedData_ex(PKCS7* pkcs7, const byte* hashBuf,
word32 hashSz, byte* pkiMsgHead, word32 pkiMsgHeadSz, byte* pkiMsgFoot,
word32 pkiMsgFootSz);
/*!
\ingroup PKCS7
\brief この関数は、PKCS7構造を編集し、PKCS7構造を符号化し、Parsable PKCS7エンベロープデータパケットを含むバッファに編集します。
\return Success エンベロープデータ形式でメッセージを正常にエンコードする上で返信され、出力バッファに書き込まれたサイズを返します。
\return BAD_FUNC_ARG: 入力パラメータの1つが無効な場合、またはPKCS7構造が必要な要素を欠落している場合
\return ALGO_ID_E pkcs7構造がサポートされていないアルゴリズムタイプを使用している場合に返されます。現在、DESBとDES3Bのみがサポートされています
\return BUFFER_E 与えられた出力バッファが小さすぎて出力データを保存する場合に返されます
\return MEMORY_E メモリの割り当て中にエラーが発生した場合に返されます
\return RNG_FAILURE_E 暗号化の乱数発生器の初期化中にエラーがある場合
\return DRBG_FAILED 暗号化に使用される乱数発生器を使用して数字を生成するエラーが発生した場合
\param pkcs7 符号化するPKCS7構造へのポインタ
\param output エンコードされた証明書を保存するバッファへのポインタ
_Example_
\code
PKCS7 pkcs7;
int ret;
byte derBuff[] = { }; // initialize with DER-encoded certificate
byte pkcs7Buff[FOURK_BUF];
wc_PKCS7_InitWithCert(&pkcs7, derBuff, sizeof(derBuff));
// update message and data to encode
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
pkcs7.content = data;
pkcs7.contentSz = dataSz;
... etc.
ret = wc_PKCS7_EncodeEnvelopedData(&pkcs7, pkcs7Buff, sizeof(pkcs7Buff));
if ( ret != 0 ) {
// error encoding into output buffer
}
\endcode
\sa wc_PKCS7_InitWithCert
\sa wc_PKCS7_DecodeEnvelopedData
*/
int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7,
byte* output, word32 outputSz);
/*!
\ingroup PKCS7
\brief この関数はPKCS7エンベロープデータコンテンツタイプをアントラップして復号化し、メッセージを出力にデコードします。渡されたPKCS7オブジェクトの秘密鍵を使用してメッセージを復号化します。
\return On メッセージから情報を抽出するには、出力に書き込まれたバイト数を返します。
\return BAD_FUNC_ARG 入力パラメータの1つが無効な場合は返されます
\return ASN_PARSE_E 与えられたPKIMSGから解析中のエラーがある場合に返されます
\return PKCS7_OID_E 与えられたPKIMSGがエンベロープデータ型ではない場合に返されます
\return ASN_VERSION_E PKCS7署名者情報がバージョン0ではない場合に返されます
\return MEMORY_E メモリの割り当て中にエラーが発生した場合に返されます
\return ALGO_ID_E pkcs7構造がサポートされていないアルゴリズムタイプを使用している場合に返されます。現在、Signature Generation for Signature GenerationのRSAKを使用して、DESBとDES3Bのみが暗号化でサポートされています。
\return PKCS7_RECIP_E 提供された受信者と一致するエンベロープデータに受信者が見つからない場合
\return RSA_BUFFER_E バッファエラーが原因でRSAシグネチャ検証中にエラーがある場合は、小さすぎたり入力が大きすぎたりすると元に戻されます。
\return MP_INIT_E 署名検証中にエラーがある場合は返却される可能性があります
\return MP_READ_E 署名検証中にエラーがある場合は返却される可能性があります
\return MP_CMP_E 署名検証中にエラーがある場合は返却される可能性があります
\return MP_INVMOD_E 署名検証中にエラーがある場合は返却される可能性があります
\return MP_EXPTMOD_E 署名検証中にエラーがある場合は返却される可能性があります
\return MP_MOD_E 署名検証中にエラーがある場合は返却される可能性があります
\return MP_MUL_E 署名検証中にエラーがある場合は返却される可能性があります
\return MP_ADD_E 署名検証中にエラーがある場合は返却される可能性があります
\return MP_MULMOD_E 署名検証中にエラーがある場合は返却される可能性があります
\return MP_TO_E 署名検証中にエラーがある場合は返却される可能性があります
\return MP_MEM 署名検証中にエラーがある場合は返却される可能性があります
\param pkcs7 エンベロープデータパッケージをデコードする秘密鍵を含むPKCS7構造へのポインタ
\param pkiMsg エンベロープデータパッケージを含むバッファへのポインタ
\param pkiMsgSz 包み込まれたデータパッケージのサイズ
\param output デコードされたメッセージを保存するバッファへのポインタ
_Example_
\code
PKCS7 pkcs7;
byte received[] = { }; // initialize with received enveloped message
byte decoded[FOURK_BUF];
int decodedSz;
// initialize pkcs7 with certificate
// update key
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
decodedSz = wc_PKCS7_DecodeEnvelopedData(&pkcs7, received,
sizeof(received),decoded, sizeof(decoded));
if ( decodedSz != 0 ) {
// error decoding message
}
\endcode
\sa wc_PKCS7_InitWithCert
\sa wc_PKCS7_EncodeEnvelopedData
*/
int wc_PKCS7_DecodeEnvelopedData(PKCS7* pkcs7, byte* pkiMsg,
word32 pkiMsgSz, byte* output,
word32 outputSz);

View File

@@ -0,0 +1,101 @@
/*!
\ingroup Poly1305
\brief この関数は、Poly1305コンテキスト構造のキーを設定し、ハッシュに初期化します。注セキュリティを確保するために、WC_POLY1305FINALでメッセージハッシュを生成した後に新しいキーを設定する必要があります。
\return 0 キーを正常に設定し、Poly1305構造の初期化
\return BAD_FUNC_ARG 与えられたキーが32バイトの長さでない場合、またはPoly1305コンテキストがNULLの場合
\param ctx 初期化するためのPoly1305構造へのポインタ
\param key ハッシュに使用する鍵を含むバッファへのポインタ
_Example_
\code
Poly1305 enc;
byte key[] = { initialize with 32 byte key to use for hashing };
wc_Poly1305SetKey(&enc, key, sizeof(key));
\endcode
\sa wc_Poly1305Update
\sa wc_Poly1305Final
*/
int wc_Poly1305SetKey(Poly1305* poly1305, const byte* key,
word32 kySz);
/*!
\ingroup Poly1305
\brief この関数は、Poly1305構造を持つハッシュにメッセージを更新します。
\return 0 ハッシュへのメッセージの更新に成功しました
\return BAD_FUNC_ARG Poly1305構造がNULLの場合に返されます
\param ctx HASHにメッセージを更新するためのPoly1305構造へのポインタ
\param m ハッシュに追加する必要があるメッセージを含むバッファへのポインタ
_Example_
\code
Poly1305 enc;
byte key[] = { }; // initialize with 32 byte key to use for encryption
byte msg[] = { }; // initialize with message to hash
wc_Poly1305SetKey(&enc, key, sizeof(key));
if( wc_Poly1305Update(key, msg, sizeof(msg)) != 0 ) {
// error updating message to hash
}
\endcode
\sa wc_Poly1305SetKey
\sa wc_Poly1305Final
*/
int wc_Poly1305Update(Poly1305* poly1305, const byte* m, word32 bytes);
/*!
\ingroup Poly1305
\brief この関数は入力メッセージのハッシュを計算し、結果をMACに格納します。この後、キーをリセットする必要があります。
\return 0 最後のMacの計算に成功した
\return BAD_FUNC_ARG Poly1305構造がNULLの場合に返されます
\param ctx MACを生成するためのPoly1305構造へのポインタ
_Example_
\code
Poly1305 enc;
byte mac[POLY1305_DIGEST_SIZE]; // space for a 16 byte mac
byte key[] = { }; // initialize with 32 byte key to use for encryption
byte msg[] = { }; // initialize with message to hash
wc_Poly1305SetKey(&enc, key, sizeof(key));
wc_Poly1305Update(key, msg, sizeof(msg));
if ( wc_Poly1305Final(&enc, mac) != 0 ) {
// error computing final MAC
}
\endcode
\sa wc_Poly1305SetKey
\sa wc_Poly1305Update
*/
int wc_Poly1305Final(Poly1305* poly1305, byte* tag);
/*!
\ingroup Poly1305
\brief 鍵がロードされ、最近のTLS AEADパディング方式を使用してMACタグを作成する初期化されたPoly1305構造体を取ります。
\return 0 成功
\return BAD_FUNC_ARG CTX、INPUT、またはTAGがNULLの場合、または追加がNULLで、ADDSZが0より大きい場合、またはTAGSZがWC_POLY1305_MAC_SZより小さい場合に返されます。
\param ctx 初期化されたPoly1305構造物
\param additional 使用する追加データ
\param addSz 追加バッファのサイズ
\param input からタグを作成するための入力バッファ
\param sz 入力バッファのサイズ
\param tag 作成したタグを保持するためのバッファー
_Example_
\code
Poly1305 ctx;
byte key[] = { }; // initialize with 32 byte key to use for hashing
byte additional[] = { }; // initialize with additional data
byte msg[] = { }; // initialize with message
byte tag[16];
wc_Poly1305SetKey(&ctx, key, sizeof(key));
if(wc_Poly1305_MAC(&ctx, additional, sizeof(additional), (byte*)msg,
sizeof(msg), tag, sizeof(tag)) != 0)
{
// Handle the error
}
\endcode
\sa wc_Poly1305SetKey
\sa wc_Poly1305Update
\sa wcPoly1305Final
*/
int wc_Poly1305_MAC(Poly1305* ctx, byte* additional, word32 addSz,
byte* input, word32 sz, byte* tag, word32 tagSz);

View File

@@ -0,0 +1,75 @@
/*!
\ingroup PSA
\brief この関数は、与えられたコンテキストでのPSAサポートを可能にします。
\param ctx PSAサポートを有効にする必要があるWOLFSSL_CTXオブジェクトへのポインタ
\return WOLFSSL_SUCCESS 成功した
_Example_
\code
WOLFSSL_CTX *ctx;
ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
if (!ctx)
return NULL;
ret = wolfSSL_CTX_psa_enable(ctx);
if (ret != WOLFSSL_SUCCESS)
printf("can't enable PSA on ctx");
\endcode
\sa wolfSSL_set_psa_ctx
*/
int wolfSSL_CTX_psa_enable(WOLFSSL_CTX *ctx);
/*!
\ingroup PSA
\brief 与えられたSSLセッションのPSAコンテキストを設定する機能
\param ssl CTXが有効になるWolfSSLへのポインタ
\param ctx Struct PSA_SSL_CTXへのポインタSSLセッションに固有である必要があります
\return WOLFSSL_SUCCESS 成功した
_Example_
\code
// Create new ssl session
WOLFSSL *ssl;
struct psa_ssl_ctx psa_ctx = { 0 };
ssl = wolfSSL_new(ctx);
if (!ssl)
return NULL;
// setup PSA context
ret = wolfSSL_set_psa_ctx(ssl, ctx);
\endcode
\sa wolfSSL_psa_set_private_key_id
\sa wolfSSL_psa_free_psa_ctx
*/
int wolfSSL_set_psa_ctx(WOLFSSL *ssl, struct psa_ssl_ctx *ctx);
/*!
\ingroup PSA
\brief この関数はPSAコンテキストによって使用されるリソースを解放します
\sa wolfSSL_set_psa_ctx
*/
void wolfSSL_free_psa_ctx(struct psa_ssl_ctx *ctx);
/*!
\ingroup PSA
\brief この関数は、SSLセッションによって使用される秘密鍵を設定します
\param ctx 構造体PSA_SSL_CTXへのポインタ
_Example_
\code
// Create new ssl session
WOLFSSL *ssl;
struct psa_ssl_ctx psa_ctx = { 0 };
psa_key_id_t key_id;
// key provisioning already done
get_private_key_id(&key_id);
ssl = wolfSSL_new(ctx);
if (!ssl)
return NULL;
wolfSSL_psa_set_private_key_id(&psa_ctx, key_id);
wolfSSL_set_psa_ctx(ssl, ctx);
\endcode
\sa wolfSSL_set_psa_ctx
*/
int wolfSSL_psa_set_private_key_id(struct psa_ssl_ctx *ctx,
psa_key_id_t id);

View File

@@ -0,0 +1,110 @@
/*!
\ingroup Password
\brief この機能はパスワードベースの鍵導出機能1PBKDF1を実装し、入力パスワードを連結塩と共により安全な鍵に変換し、出力に記憶する。これにより、HASH関数としてSHAとMD5を選択できます。
\return 0 入力パスワードからキーの派生に正常に戻された
\return BAD_FUNC_ARG 与えられた無効なハッシュタイプがある場合有効なタイプはMD5とSHA、反復は1未満、または要求されたキーの長さKlenは提供されたハッシュのハッシュ長よりも大きいです。
\return MEMORY_E SHAまたはMD5オブジェクトにメモリを割り当てるエラーがある場合は返されます。
\param output 生成されたキーを保存するバッファへのポインタ。少なくともklen longになるべきです
\param passwd キーの派生に使用するパスワードを含むバッファへのポインタ
\param pLen キーの派生に使用するパスワードの長さ
\param salt 鍵由来に使用する塩を含む緩衝液へのポインター
\param sLen 塩の長さ
\param iterations ハッシュを処理するための回数
\param kLen 派生キーの希望の長さ。選択したハッシュのダイジェストサイズより長くしてはいけません
_Example_
\code
int ret;
byte key[MD5_DIGEST_SIZE];
byte pass[] = { }; // initialize with password
byte salt[] = { }; // initialize with salt
ret = wc_PBKDF1(key, pass, sizeof(pass), salt, sizeof(salt), 1000,
sizeof(key), MD5);
if ( ret != 0 ) {
// error deriving key from password
}
\endcode
\sa wc_PBKDF2
\sa wc_PKCS12_PBKDF
*/
int wc_PBKDF1(byte* output, const byte* passwd, int pLen,
const byte* salt, int sLen, int iterations, int kLen,
int typeH);
/*!
\ingroup Password
\brief この機能はパスワードベースのキー導出機能2PBKDF2を実装し、入力パスワードを連結された塩とともにより安全なキーに変換し、出力に記憶されています。これにより、MD5、SHA、SHA256、SHA384、SHA512、およびBLAKE2Bなど、サポートされているHMACハッシュ関数のいずれかを選択できます。
\return 0 入力パスワードからキーの派生に正常に戻された
\return BAD_FUNC_ARG 無効なハッシュタイプがある場合、または反復が1未満の場合は返されます。
\return MEMORY_E HMACオブジェクトに割り振りメモリがある場合
\param output 生成されたキーを保存するバッファへのポインタ。klen longにするべきです
\param passwd キーの派生に使用するパスワードを含むバッファへのポインタ
\param pLen キーの派生に使用するパスワードの長さ
\param salt 鍵由来に使用する塩を含む緩衝液へのポインター
\param sLen 塩の長さ
\param iterations ハッシュを処理するための回数
\param kLen 派生鍵の望ましい長さ
_Example_
\code
int ret;
byte key[64];
byte pass[] = { }; // initialize with password
byte salt[] = { }; // initialize with salt
ret = wc_PBKDF2(key, pass, sizeof(pass), salt, sizeof(salt), 2048, sizeof(key),
SHA512);
if ( ret != 0 ) {
// error deriving key from password
}
\endcode
\sa wc_PBKDF1
\sa wc_PKCS12_PBKDF
*/
int wc_PBKDF2(byte* output, const byte* passwd, int pLen,
const byte* salt, int sLen, int iterations, int kLen,
int typeH);
/*!
\ingroup Password
\brief この関数は、RFC 7292付録Bに記載されているパスワードベースのキー導出機能PBKDFを実装しています。この関数は、入力パスワードを連結塩でより安全なキーに変換します。それは、MD5、SHA、SHA256、SHA384、SHA512、およびBLAKE2Bを含む、ユーザーはサポートされているHMACハッシュ関数のいずれかを選択できます。
\return 0 入力パスワードからキーの派生に正常に戻された
\return BAD_FUNC_ARG 返された無効なハッシュタイプが与えられた場合、繰り返しは1未満、または要求されたキーの長さklenが提供されたハッシュのハッシュ長よりも大きいです。
\return MEMORY_E 割り当てメモリがある場合は返されます
\return MP_INIT_E キー生成中にエラーがある場合は返却される可能性があります
\return MP_READ_E キー生成中にエラーがある場合は返却される可能性があります
\return MP_CMP_E キー生成中にエラーがある場合は返却される可能性があります
\return MP_INVMOD_E キー生成中にエラーがある場合は返却される可能性があります
\return MP_EXPTMOD_E キー生成中にエラーがある場合は返却される可能性があります
\return MP_MOD_E キー生成中にエラーがある場合は返却される可能性があります
\return MP_MUL_E キー生成中にエラーがある場合は返却される可能性があります
\return MP_ADD_E キー生成中にエラーがある場合は返却される可能性があります
\return MP_MULMOD_E キー生成中にエラーがある場合は返却される可能性があります
\return MP_TO_E キー生成中にエラーがある場合は返却される可能性があります
\return MP_MEM キー生成中にエラーがある場合は返却される可能性があります
\param output 生成されたキーを保存するバッファへのポインタ。klen longにするべきです
\param passwd キーの派生に使用するパスワードを含むバッファへのポインタ
\param pLen キーの派生に使用するパスワードの長さ
\param salt 鍵由来に使用する塩を含む緩衝液へのポインター
\param sLen 塩の長さ
\param iterations ハッシュを処理するための回数
\param kLen 派生鍵の望ましい長さ
\param hashType 使用するハッシュアルゴリズム有効な選択肢は次のとおりです.MD5、SHA、SHA256、SHA384、SHA512、およびBLAKE2B
_Example_
\code
int ret;
byte key[64];
byte pass[] = { }; // initialize with password
byte salt[] = { }; // initialize with salt
ret = wc_PKCS512_PBKDF(key, pass, sizeof(pass), salt, sizeof(salt), 2048,
sizeof(key), SHA512, 1);
if ( ret != 0 ) {
// error deriving key from password
}
\endcode
\sa wc_PBKDF1
\sa wc_PBKDF2
*/
int wc_PKCS12_PBKDF(byte* output, const byte* passwd, int pLen,
const byte* salt, int sLen, int iterations,
int kLen, int typeH, int purpose);

View File

@@ -0,0 +1,258 @@
/*!
\ingroup Random
\brief Init Global WhiteWood Netrandomのコンテキスト
\return 0 成功
\return BAD_FUNC_ARG configfileがnullまたはタイムアウトのどちらかが否定的です。
\return RNG_FAILURE_E RNGの初期化に失敗しました。
\param configFile 設定ファイルへのパス
\param hmac_cb HMACコールバックを作成するにはオプションです。
_Example_
\code
char* config = "path/to/config/example.conf";
int time = // Some sufficient timeout value;
if (wc_InitNetRandom(config, NULL, time) != 0)
{
// Some error occurred
}
\endcode
\sa wc_FreeNetRandom
*/
int wc_InitNetRandom(const char* configFile, wnr_hmac_key hmac_cb, int timeout);
/*!
\ingroup Random
\brief 無料のGlobal WhiteWood Netrandomコンテキスト。
\return 0 成功
\return BAD_MUTEX_E Wnr_Mutexでミューテックスをロックするエラー
_Example_
\code
int ret = wc_FreeNetRandom();
if(ret != 0)
{
// Handle the error
}
\endcode
\sa wc_InitNetRandom
*/
int wc_FreeNetRandom(void);
/*!
\ingroup Random
\brief RNGのシードOSからとキー暗号を取得します。割り当てられたRNG-> DRBG決定論的ランダムビットジェネレータが割り当てられますWC_FREERNGで割り当てられている必要があります。これはブロッキング操作です。
\return 0 成功しています。
\return MEMORY_E XMallocに失敗しました
\return WINCRYPT_E WC_GENERATSEEDコンテキストの取得に失敗しました
\return CRYPTGEN_E WC_GENERATSEEDランダムになりました
\return BAD_FUNC_ARG WC_RNG_GenerateBlock入力はNULLまたはSZがMAX_REQUEST_LENを超えています
\return DRBG_CONT_FIPS_E wc_rng_generateblockhash_genはdrbg_cont_failureを返しました
\return RNG_FAILURE_E wc_rng_generateBlockデフォルトエラーです。RNGのステータスはもともとOKではなく、drbg_failedに設定されています
_Example_
\code
RNG rng;
int ret;
#ifdef HAVE_CAVIUM
ret = wc_InitRngCavium(&rng, CAVIUM_DEV_ID);
if (ret != 0){
printf(“RNG Nitrox init for device: %d failed”, CAVIUM_DEV_ID);
return -1;
}
#endif
ret = wc_InitRng(&rng);
if (ret != 0){
printf(“RNG init failed”);
return -1;
}
\endcode
\sa wc_InitRngCavium
\sa wc_RNG_GenerateBlock
\sa wc_RNG_GenerateByte
\sa wc_FreeRng
\sa wc_RNG_HealthTest
*/
int wc_InitRng(WC_RNG*);
/*!
\ingroup Random
\brief 疑似ランダムデータのSZバイトを出力にコピーします。必要に応じてRNGブロッキングします。
\return 0 成功した
\return BAD_FUNC_ARG 入力はNULLまたはSZがMAX_REQUEST_LENを超えています
\return DRBG_CONT_FIPS_E hash_genはdrbg_cont_failureを返しました
\return RNG_FAILURE_E デフォルトのエラーRNGのステータスはもともとOKではなく、drbg_failedに設定されています
\param rng 乱数発生器はWC_INITRNGで初期化された
\param output ブロックがコピーされるバッファ
_Example_
\code
RNG rng;
int sz = 32;
byte block[sz];
int ret = wc_InitRng(&rng);
if (ret != 0) {
return -1; //init of rng failed!
}
ret = wc_RNG_GenerateBlock(&rng, block, sz);
if (ret != 0) {
return -1; //generating block failed!
}
\endcode
\sa wc_InitRngCavium, wc_InitRng
\sa wc_RNG_GenerateByte
\sa wc_FreeRng
\sa wc_RNG_HealthTest
*/
int wc_RNG_GenerateBlock(WC_RNG* rng, byte* b, word32 sz);
/*!
\ingroup Random
\brief 新しいWC_RNG構造を作成します。
\return WC_RNG 成功の構造
\return NULL 誤りに
\param heap ヒープ識別子へのポインタ
\param nonce nonceを含むバッファへのポインタ
_Example_
\code
RNG rng;
byte nonce[] = { initialize nonce };
word32 nonceSz = sizeof(nonce);
wc_rng_new(&nonce, nonceSz, &heap);
\endcode
\sa wc_InitRng
\sa wc_rng_free
\sa wc_FreeRng
\sa wc_RNG_HealthTest
*/
WC_RNG* wc_rng_new(byte* nonce, word32 nonceSz, void* heap)
/*!
\ingroup Random
\brief wc_rng_generateBlockを呼び出して、疑似ランダムデータのバイトをbにコピーします。必要に応じてRNGが再販されます。
\return 0 成功した
\return BAD_FUNC_ARG 入力はNULLまたはSZがMAX_REQUEST_LENを超えています
\return DRBG_CONT_FIPS_E hash_genはdrbg_cont_failureを返しました
\return RNG_FAILURE_E デフォルトのエラーRNGのステータスはもともとOKではなく、drbg_failedに設定されています
\param rng: 乱数発生器はWC_INITRNGで初期化された
_Example_
\code
RNG rng;
int sz = 32;
byte b[1];
int ret = wc_InitRng(&rng);
if (ret != 0) {
return -1; //init of rng failed!
}
ret = wc_RNG_GenerateByte(&rng, b);
if (ret != 0) {
return -1; //generating block failed!
}
\endcode
\sa wc_InitRngCavium
\sa wc_InitRng
\sa wc_RNG_GenerateBlock
\sa wc_FreeRng
\sa wc_RNG_HealthTest
*/
int wc_RNG_GenerateByte(WC_RNG* rng, byte* b);
/*!
\ingroup Random
\brief RNGがDRGBを安全に解放するために必要なときに呼び出されるべきです。ゼロとXfrees RNG-DRBG。
\return 0 成功した
\return BAD_FUNC_ARG RNGまたはRNG-> DRGB NULL
\return RNG_FAILURE_E DRBGの割り当て解除に失敗しました
_Example_
\code
RNG rng;
int ret = wc_InitRng(&rng);
if (ret != 0) {
return -1; //init of rng failed!
}
int ret = wc_FreeRng(&rng);
if (ret != 0) {
return -1; //free of rng failed!
}
\endcode
\sa wc_InitRngCavium
\sa wc_InitRng
\sa wc_RNG_GenerateBlock
\sa wc_RNG_GenerateByte,
\sa wc_RNG_HealthTest
*/
int wc_FreeRng(WC_RNG*);
/*!
\ingroup Random
\brief RNGを安全に自由に解放するためにRNGが不要になったときに呼び出されるべきです。
_Example_
\code
RNG rng;
byte nonce[] = { initialize nonce };
word32 nonceSz = sizeof(nonce);
rng = wc_rng_new(&nonce, nonceSz, &heap);
// use rng
wc_rng_free(&rng);
\endcode
\sa wc_InitRng
\sa wc_rng_new
\sa wc_FreeRng
\sa wc_RNG_HealthTest
*/
WC_RNG* wc_rng_free(WC_RNG* rng);
/*!
\ingroup Random
\brief DRBGの機能を作成しテストします。
\return 0 成功した
\return BAD_FUNC_ARG ELTOPYAと出力はNULLにしないでください。Reseed Set EntropybがNULLでなければならない場合
\return -1 テスト失敗
\param int RESEED設定されている場合は、Reseed機能をテストします
\param entropyA: DRGBをインスタンス化するエントロピー
\param entropyASz: バイト数のエントロピヤのサイズ
\param entropyB: Reseed Setを設定した場合、DRBGはEntropybでリサイードされます
\param entropyBSz: バイト単位のEntropybのサイズ
\param output: SEADRANDOMが設定されている場合は、Entropybに播種されたランダムなデータに初期化され、それ以外の場合はEntropya
_Example_
\code
byte output[SHA256_DIGEST_SIZE * 4];
const byte test1EntropyB[] = ....; // test input for reseed false
const byte test1Output[] = ....; // testvector: expected output of
// reseed false
ret = wc_RNG_HealthTest(0, test1Entropy, sizeof(test1Entropy), NULL, 0,
output, sizeof(output));
if (ret != 0)
return -1;//healthtest without reseed failed
if (XMEMCMP(test1Output, output, sizeof(output)) != 0)
return -1; //compare to testvector failed: unexpected output
const byte test2EntropyB[] = ....; // test input for reseed
const byte test2Output[] = ....; // testvector expected output of reseed
ret = wc_RNG_HealthTest(1, test2EntropyA, sizeof(test2EntropyA),
test2EntropyB, sizeof(test2EntropyB),
output, sizeof(output));
if (XMEMCMP(test2Output, output, sizeof(output)) != 0)
return -1; //compare to testvector failed
\endcode
\sa wc_InitRngCavium
\sa wc_InitRng
\sa wc_RNG_GenerateBlock
\sa wc_RNG_GenerateByte
\sa wc_FreeRng
*/
int wc_RNG_HealthTest(int reseed,
const byte* entropyA, word32 entropyASz,
const byte* entropyB, word32 entropyBSz,
byte* output, word32 outputSz);

View File

@@ -0,0 +1,70 @@
/*!
\ingroup RIPEMD
\brief この関数は、RIPemdのダイジェスト、バッファ、LOLEN ,HILENを初期化することによってRIPemd構造を初期化します。
\return 0 機能の実行に成功したことに戻ります。RIPEMD構造が初期化されます。
\return BAD_FUNC_ARG RIPEMD構造がNULLの場合に返されます。
_Example_
\code
RipeMd md;
int ret;
ret = wc_InitRipeMd(&md);
if (ret != 0) {
// Failure case.
}
\endcode
\sa wc_RipeMdUpdate
\sa wc_RipeMdFinal
*/
int wc_InitRipeMd(RipeMd*);
/*!
\ingroup RIPEMD
\brief この関数はデータ入力のRIPemdダイジェストを生成し、結果をRIPemd-> Digestバッファに格納します。WC_RIPEMDUPDATEを実行した後、生成されたRIPemd-> Digestを既知の認証タグに比較してメッセージの信頼性を比較する必要があります。
\return 0 機能の実行に成功したことに戻ります。
\return BAD_FUNC_ARG RIPEMD構造がNULLの場合、またはデータがNULLで、LENがゼロでない場合に返されます。データがNULLであり、LENが0の場合、この関数は実行されるはずです。
\param ripemd: WC_INTRIPEMDで初期化されるRIPEMD構造へのポインタ
\param data ハッシュするデータ
_Example_
\code
const byte* data; // The data to be hashed
....
RipeMd md;
int ret;
ret = wc_InitRipeMd(&md);
if (ret == 0) {
ret = wc_RipeMdUpdate(&md, plain, sizeof(plain));
if (ret != 0) {
// Failure case …
\endcode
\sa wc_InitRipeMd
\sa wc_RipeMdFinal
*/
int wc_RipeMdUpdate(RipeMd* ripemd, const byte* data, word32 len);
/*!
\ingroup RIPEMD
\brief この関数は計算されたダイジェストをハッシュにコピーします。無傷のブロックがある場合、この方法ではブロックを0Sでパッケージし、ハッシュにコピーする前にそのブロックのラウンドをダイジェストに含めます。RIPEMDの状態がリセットされます。
\return 0 機能の実行に成功したことに戻ります。RIPEMD構造の状態がリセットされました。
\return BAD_FUNC_ARG RIPEMD構造体またはハッシュパラメータがNULLの場合に返されます。
\param ripemd WC_INITRIPEMDで初期化するRIPEMD構造へのポインタ、およびWC_RIPEMDUPDATEからハッシュを含む。状態はリセットされます
_Example_
\code
RipeMd md;
int ret;
byte digest[RIPEMD_DIGEST_SIZE];
const byte* data; // The data to be hashed
...
ret = wc_InitRipeMd(&md);
if (ret == 0) {
ret = wc_RipeMdUpdate(&md, plain, sizeof(plain));
if (ret != 0) {
// RipeMd Update Failure Case.
}
ret = wc_RipeMdFinal(&md, digest);
if (ret != 0) {
// RipeMd Final Failure Case.
}...
\endcode
\sa none
*/
int wc_RipeMdFinal(RipeMd* ripemd, byte* hash);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,114 @@
/*!
*/
int wc_InitSakkeKey(SakkeKey* key, void* heap, int devId);
/*!
*/
int wc_InitSakkeKey_ex(SakkeKey* key, int keySize, int curveId,
void* heap, int devId);
/*!
*/
void wc_FreeSakkeKey(SakkeKey* key);
/*!
*/
int wc_MakeSakkeKey(SakkeKey* key, WC_RNG* rng);
/*!
*/
int wc_MakeSakkePublicKey(SakkeKey* key, ecc_point* pub);
/*!
*/
int wc_MakeSakkeRsk(SakkeKey* key, const byte* id, word16 idSz,
ecc_point* rsk);
/*!
*/
int wc_ValidateSakkeRsk(SakkeKey* key, const byte* id, word16 idSz,
ecc_point* rsk, int* valid);
/*!
*/
int wc_GenerateSakkeRskTable(const SakkeKey* key,
const ecc_point* rsk, byte* table, word32* len);
/*!
*/
int wc_ExportSakkeKey(SakkeKey* key, byte* data, word32* sz);
/*!
*/
int wc_ImportSakkeKey(SakkeKey* key, const byte* data, word32 sz);
/*!
*/
int wc_ExportSakkePrivateKey(SakkeKey* key, byte* data, word32* sz);
/*!
*/
int wc_ImportSakkePrivateKey(SakkeKey* key, const byte* data,
word32 sz);
/*!
*/
int wc_EncodeSakkeRsk(const SakkeKey* key, ecc_point* rsk,
byte* out, word32* sz, int raw);
/*!
*/
int wc_DecodeSakkeRsk(const SakkeKey* key, const byte* data,
word32 sz, ecc_point* rsk);
/*!
*/
int wc_ImportSakkeRsk(SakkeKey* key, const byte* data, word32 sz);
/*!
*/
int wc_ExportSakkePublicKey(SakkeKey* key, byte* data,
word32* sz, int raw);
/*!
*/
int wc_ImportSakkePublicKey(SakkeKey* key, const byte* data,
word32 sz, int trusted);
/*!
*/
int wc_GetSakkeAuthSize(SakkeKey* key, word16* authSz);
/*!
*/
int wc_SetSakkeIdentity(SakkeKey* key, const byte* id, word16 idSz);
/*!
*/
int wc_MakeSakkePointI(SakkeKey* key, const byte* id, word16 idSz);
/*!
*/
int wc_GetSakkePointI(SakkeKey* key, byte* data, word32* sz);
/*!
*/
int wc_SetSakkePointI(SakkeKey* key, const byte* id, word16 idSz,
const byte* data, word32 sz);
/*!
*/
int wc_GenerateSakkePointITable(SakkeKey* key, byte* table,
word32* len);
/*!
*/
int wc_SetSakkePointITable(SakkeKey* key, byte* table, word32 len);
/*!
*/
int wc_ClearSakkePointITable(SakkeKey* key);
/*!
*/
int wc_MakeSakkeEncapsulatedSSV(SakkeKey* key,
enum wc_HashType hashType, byte* ssv, word16 ssvSz, byte* auth,
word16* authSz);
/*!
*/
int wc_GenerateSakkeSSV(SakkeKey* key, WC_RNG* rng, byte* ssv,
word16* ssvSz);
/*!
*/
int wc_SetSakkeRsk(SakkeKey* key, const ecc_point* rsk, byte* table,
word32 len);
/*!
*/
int wc_DeriveSakkeSSV(SakkeKey* key, enum wc_HashType hashType,
byte* ssv, word16 ssvSz, const byte* auth,
word16 authSz);

View File

@@ -0,0 +1,110 @@
/*!
\ingroup SHA
\brief この関数はSHAを初期化します。これは自動的にWC_Shahashによって呼び出されます。
\return 0 初期化に成功したときに返されます
_Example_
\code
Sha sha[1];
if ((ret = wc_InitSha(sha)) != 0) {
WOLFSSL_MSG("wc_InitSha failed");
}
else {
wc_ShaUpdate(sha, data, len);
wc_ShaFinal(sha, hash);
}
\endcode
\sa wc_ShaHash
\sa wc_ShaUpdate
\sa wc_ShaFinal
*/
int wc_InitSha(wc_Sha*);
/*!
\ingroup SHA
\brief 長さLENの提供されたバイト配列を絶えずハッシュするように呼び出すことができます。
\return 0 データをダイジェストに正常に追加すると返されます。
\param sha 暗号化に使用するSHA構造へのポインタ
\param data ハッシュするデータ
_Example_
\code
Sha sha[1];
byte data[] = { // Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha(sha)) != 0) {
WOLFSSL_MSG("wc_InitSha failed");
}
else {
wc_ShaUpdate(sha, data, len);
wc_ShaFinal(sha, hash);
}
\endcode
\sa wc_ShaHash
\sa wc_ShaFinal
\sa wc_InitSha
*/
int wc_ShaUpdate(wc_Sha* sha, const byte* data, word32 len);
/*!
\ingroup SHA
\brief データのハッシュを確定します。結果はハッシュに入れられます。SHA構造体の状態をリセットします。
\return 0 ファイナライズに成功したときに返されます。
\param sha 暗号化に使用するSHA構造へのポインタ
_Example_
\code
Sha sha[1];
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha(sha)) != 0) {
WOLFSSL_MSG("wc_InitSha failed");
}
else {
wc_ShaUpdate(sha, data, len);
wc_ShaFinal(sha, hash);
}
\endcode
\sa wc_ShaHash
\sa wc_InitSha
\sa wc_ShaGetHash
*/
int wc_ShaFinal(wc_Sha* sha, byte* hash);
/*!
\ingroup SHA
\brief 初期化されたSHA構造体によって使用されるメモリをクリーンアップするために使用されます。注これは、wolfssl_ti_hashが定義されている場合にのみサポートされています。
\return No 戻り値。
_Example_
\code
Sha sha;
wc_InitSha(&sha);
// Use sha
wc_ShaFree(&sha);
\endcode
\sa wc_InitSha
\sa wc_ShaUpdate
\sa wc_ShaFinal
*/
void wc_ShaFree(wc_Sha*);
/*!
\ingroup SHA
\brief ハッシュデータを取得します。結果はハッシュに入れられます。SHA構造体の状態をリセットしません。
\return 0 ファイナライズに成功したときに返されます。
\param sha 暗号化に使用するSHA構造へのポインタ
_Example_
\code
Sha sha[1];
if ((ret = wc_InitSha(sha)) != 0) {
WOLFSSL_MSG("wc_InitSha failed");
}
else {
wc_ShaUpdate(sha, data, len);
wc_ShaGetHash(sha, hash);
}
\endcode
\sa wc_ShaHash
\sa wc_ShaFinal
\sa wc_InitSha
*/
int wc_ShaGetHash(wc_Sha* sha, byte* hash);

View File

@@ -0,0 +1,191 @@
/*!
\ingroup SHA
\brief この関数はSHA256を初期化します。これはWC_SHA256HASHによって自動的に呼び出されます。
\return 0 初期化に成功したときに返されます
_Example_
\code
Sha256 sha256[1];
if ((ret = wc_InitSha256(sha256)) != 0) {
WOLFSSL_MSG("wc_InitSha256 failed");
}
else {
wc_Sha256Update(sha256, data, len);
wc_Sha256Final(sha256, hash);
}
\endcode
\sa wc_Sha256Hash
\sa wc_Sha256Update
\sa wc_Sha256Final
*/
int wc_InitSha256(wc_Sha256*);
/*!
\ingroup SHA
\brief 長さLENの提供されたバイト配列を絶えずハッシュするように呼び出すことができます。
\return 0 データをダイジェストに正常に追加すると返されます。
\param sha256 暗号化に使用するSHA256構造へのポインタ
\param data ハッシュするデータ
_Example_
\code
Sha256 sha256[1];
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha256(sha256)) != 0) {
WOLFSSL_MSG("wc_InitSha256 failed");
}
else {
wc_Sha256Update(sha256, data, len);
wc_Sha256Final(sha256, hash);
}
\endcode
\sa wc_Sha256Hash
\sa wc_Sha256Final
\sa wc_InitSha256
*/
int wc_Sha256Update(wc_Sha256* sha, const byte* data, word32 len);
/*!
\ingroup SHA
\brief データのハッシュを確定します。結果はハッシュに入れられます。SHA256構造体の状態をリセットします。
\return 0 ファイナライズに成功したときに返されます。
\param sha256 暗号化に使用するSHA256構造へのポインタ
_Example_
\code
Sha256 sha256[1];
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha256(sha256)) != 0) {
WOLFSSL_MSG("wc_InitSha256 failed");
}
else {
wc_Sha256Update(sha256, data, len);
wc_Sha256Final(sha256, hash);
}
\endcode
\sa wc_Sha256Hash
\sa wc_Sha256GetHash
\sa wc_InitSha256
*/
int wc_Sha256Final(wc_Sha256* sha256, byte* hash);
/*!
\ingroup SHA
\brief SHA256構造をリセットします。注これは、wolfssl_ti_hashが定義されている場合にのみサポートされています。
\return none いいえ返します。
_Example_
\code
Sha256 sha256;
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha256(&sha256)) != 0) {
WOLFSSL_MSG("wc_InitSha256 failed");
}
else {
wc_Sha256Update(&sha256, data, len);
wc_Sha256Final(&sha256, hash);
wc_Sha256Free(&sha256);
}
\endcode
\sa wc_InitSha256
\sa wc_Sha256Update
\sa wc_Sha256Final
*/
void wc_Sha256Free(wc_Sha256*);
/*!
\ingroup SHA
\brief ハッシュデータを取得します。結果はハッシュに入れられます。SHA256構造体の状態をリセットしません。
\return 0 ファイナライズに成功したときに返されます。
\param sha256 暗号化に使用するSHA256構造へのポインタ
_Example_
\code
Sha256 sha256[1];
if ((ret = wc_InitSha256(sha256)) != 0) {
WOLFSSL_MSG("wc_InitSha256 failed");
}
else {
wc_Sha256Update(sha256, data, len);
wc_Sha256GetHash(sha256, hash);
}
\endcode
\sa wc_Sha256Hash
\sa wc_Sha256Final
\sa wc_InitSha256
*/
int wc_Sha256GetHash(wc_Sha256* sha256, byte* hash);
/*!
\ingroup SHA
\brief SHA224構造を初期化するために使用されます。
\return 0 成功
\return 1 SHA224がNULLなので、エラーが返されました。
_Example_
\code
Sha224 sha224;
if(wc_InitSha224(&sha224) != 0)
{
// Handle error
}
\endcode
\sa wc_Sha224Hash
\sa wc_Sha224Update
\sa wc_Sha224Final
*/
int wc_InitSha224(wc_Sha224*);
/*!
\ingroup SHA
\brief 長さLENの提供されたバイト配列を絶えずハッシュするように呼び出すことができます。
\return 0 成功
\return 1 関数が失敗した場合はエラーが返されます。
\return BAD_FUNC_ARG SHA224またはデータがNULLの場合、エラーが返されます。
\param sha224 暗号化に使用するSHA224構造へのポインタ。
\param data ハッシュするデータ。
_Example_
\code
Sha224 sha224;
byte data[] = { /* Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha224(&sha224)) != 0) {
WOLFSSL_MSG("wc_InitSha224 failed");
}
else {
wc_Sha224Update(&sha224, data, len);
wc_Sha224Final(&sha224, hash);
}
\endcode
\sa wc_InitSha224
\sa wc_Sha224Final
\sa wc_Sha224Hash
*/
int wc_Sha224Update(wc_Sha224* sha224, const byte* data, word32 len);
/*!
\ingroup SHA
\brief データのハッシュを確定します。結果はハッシュに入れられます。SHA224構造体の状態をリセットします。
\return 0 成功
\return <0 エラー
\param sha224 暗号化に使用するSHA224構造へのポインタ
_Example_
\code
Sha224 sha224;
byte data[] = { /* Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha224(&sha224)) != 0) {
WOLFSSL_MSG("wc_InitSha224 failed");
}
else {
wc_Sha224Update(&sha224, data, len);
wc_Sha224Final(&sha224, hash);
}
\endcode
\sa wc_InitSha224
\sa wc_Sha224Hash
\sa wc_Sha224Update
*/
int wc_Sha224Final(wc_Sha224* sha224, byte* hash);

View File

@@ -0,0 +1,143 @@
/*!
\ingroup SHA
\brief この関数はSHA512を初期化します。これはWC_SHA512HASHによって自動的に呼び出されます。
\return 0 初期化に成功したときに返されます
_Example_
\code
Sha512 sha512[1];
if ((ret = wc_InitSha512(sha512)) != 0) {
WOLFSSL_MSG("wc_InitSha512 failed");
}
else {
wc_Sha512Update(sha512, data, len);
wc_Sha512Final(sha512, hash);
}
\endcode
\sa wc_Sha512Hash
\sa wc_Sha512Update
\sa wc_Sha512Final
*/
int wc_InitSha512(wc_Sha512*);
/*!
\ingroup SHA
\brief 長さLENの提供されたバイト配列を絶えずハッシュするように呼び出すことができます。
\return 0 データをダイジェストに正常に追加すると返されます。
\param sha512 暗号化に使用するSHA512構造へのポインタ
\param data ハッシュするデータ
_Example_
\code
Sha512 sha512[1];
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha512(sha512)) != 0) {
WOLFSSL_MSG("wc_InitSha512 failed");
}
else {
wc_Sha512Update(sha512, data, len);
wc_Sha512Final(sha512, hash);
}
\endcode
\sa wc_Sha512Hash
\sa wc_Sha512Final
\sa wc_InitSha512
*/
int wc_Sha512Update(wc_Sha512* sha, const byte* data, word32 len);
/*!
\ingroup SHA
\brief データのハッシュを確定します。結果はハッシュに入れられます。
\return 0 ハッシュを確定するとうまく返されました。
\param sha512 暗号化に使用するSHA512構造へのポインタ
_Example_
\code
Sha512 sha512[1];
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha512(sha512)) != 0) {
WOLFSSL_MSG("wc_InitSha512 failed");
}
else {
wc_Sha512Update(sha512, data, len);
wc_Sha512Final(sha512, hash);
}
\endcode
\sa wc_Sha512Hash
\sa wc_Sha512Final
\sa wc_InitSha512
*/
int wc_Sha512Final(wc_Sha512* sha512, byte* hash);
/*!
\ingroup SHA
\brief この関数はSHA384を初期化します。これはWC_SHA384HASHによって自動的に呼び出されます。
\return 0 初期化に成功したときに返されます
_Example_
\code
Sha384 sha384[1];
if ((ret = wc_InitSha384(sha384)) != 0) {
WOLFSSL_MSG("wc_InitSha384 failed");
}
else {
wc_Sha384Update(sha384, data, len);
wc_Sha384Final(sha384, hash);
}
\endcode
\sa wc_Sha384Hash
\sa wc_Sha384Update
\sa wc_Sha384Final
*/
int wc_InitSha384(wc_Sha384*);
/*!
\ingroup SHA
\brief 長さLENの提供されたバイト配列を絶えずハッシュするように呼び出すことができます。
\return 0 データをダイジェストに正常に追加すると返されます。
\param sha384 暗号化に使用するSHA384構造へのポインタ
\param data ハッシュするデータ
_Example_
\code
Sha384 sha384[1];
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha384(sha384)) != 0) {
WOLFSSL_MSG("wc_InitSha384 failed");
}
else {
wc_Sha384Update(sha384, data, len);
wc_Sha384Final(sha384, hash);
}
\endcode
\sa wc_Sha384Hash
\sa wc_Sha384Final
\sa wc_InitSha384
*/
int wc_Sha384Update(wc_Sha384* sha, const byte* data, word32 len);
/*!
\ingroup SHA
\brief データのハッシュを確定します。結果はハッシュに入れられます。
\return 0 ファイナライズに成功したときに返されます。
\param sha384 暗号化に使用するSHA384構造へのポインタ
_Example_
\code
Sha384 sha384[1];
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha384(sha384)) != 0) {
WOLFSSL_MSG("wc_InitSha384 failed");
}
else {
wc_Sha384Update(sha384, data, len);
wc_Sha384Final(sha384, hash);
}
\endcode
\sa wc_Sha384Hash
\sa wc_Sha384Final
\sa wc_InitSha384
*/
int wc_Sha384Final(wc_Sha384* sha384, byte* hash);

View File

@@ -0,0 +1,120 @@
/*!
\ingroup Signature
\brief この関数は、結果のシグネチャの最大サイズを返します。
\return Returns sig_type_e sig_typeがサポートされていない場合sig_typeが無効な場合はbad_func_argを返します。正の戻り値は、署名の最大サイズを示します。
\param sig_type wc_signature_type_eccまたはwc_signature_type_rsaなどの署名型列挙型値。
\param key ECC_KEYやRSAKEYなどのキー構造へのポインタ。
_Example_
\code
// Get signature length
enum wc_SignatureType sig_type = WC_SIGNATURE_TYPE_ECC;
ecc_key eccKey;
word32 sigLen;
wc_ecc_init(&eccKey);
sigLen = wc_SignatureGetSize(sig_type, &eccKey, sizeof(eccKey));
if (sigLen > 0) {
// Success
}
\endcode
\sa wc_HashGetDigestSize
\sa wc_SignatureGenerate
\sa wc_SignatureVerify
*/
int wc_SignatureGetSize(enum wc_SignatureType sig_type,
const void* key, word32 key_len);
/*!
\ingroup Signature
\brief この関数は、データをハッシュし、結果のハッシュとキーを使用して署名を使用して署名を使用して署名を検証します。
\return 0 成功
\return SIG_TYPE_E -231、署名タイプが有効/利用可能です
\return BAD_FUNC_ARG -173、関数の不良引数が提供されています
\return BUFFER_E -132、出力バッファが小さすぎたり入力が大きすぎたりします。
\param hash_type "wc_hash_type_sha256"などの "enum wc_hashtype"からのハッシュ型。
\param sig_type wc_signature_type_eccまたはwc_signature_type_rsaなどの署名型列挙型値。
\param data ハッシュへのデータを含むバッファへのポインタ。
\param data_len データバッファの長さ。
\param sig 署名を出力するためのバッファへのポインタ。
\param sig_len シグネチャ出力バッファの長さ。
\param key ECC_KEYやRSAKEYなどのキー構造へのポインタ。
_Example_
\code
int ret;
ecc_key eccKey;
// Import the public key
wc_ecc_init(&eccKey);
ret = wc_ecc_import_x963(eccPubKeyBuf, eccPubKeyLen, &eccKey);
// Perform signature verification using public key
ret = wc_SignatureVerify(
WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
fileBuf, fileLen,
sigBuf, sigLen,
&eccKey, sizeof(eccKey));
printf("Signature Verification: %s
(%d)\n", (ret == 0) ? "Pass" : "Fail", ret);
wc_ecc_free(&eccKey);
\endcode
\sa wc_SignatureGetSize
\sa wc_SignatureGenerate
*/
int wc_SignatureVerify(
enum wc_HashType hash_type, enum wc_SignatureType sig_type,
const byte* data, word32 data_len,
const byte* sig, word32 sig_len,
const void* key, word32 key_len);
/*!
\ingroup Signature
\brief この関数は、キーを使用してデータから署名を生成します。まずデータのハッシュを作成し、キーを使用してハッシュに署名します。
\return 0 成功
\return SIG_TYPE_E -231、署名タイプが有効/利用可能です
\return BAD_FUNC_ARG -173、関数の不良引数が提供されています
\return BUFFER_E -132、出力バッファが小さすぎたり入力が大きすぎたりします。
\param hash_type "wc_hash_type_sha256"などの "enum wc_hashtype"からのハッシュ型。
\param sig_type wc_signature_type_eccまたはwc_signature_type_rsaなどの署名型列挙型値。
\param data ハッシュへのデータを含むバッファへのポインタ。
\param data_len データバッファの長さ。
\param sig 署名を出力するためのバッファへのポインタ。
\param sig_len シグネチャ出力バッファの長さ。
\param key ECC_KEYやRSAKEYなどのキー構造へのポインタ。
\param key_len キー構造のサイズ
_Example_
\code
int ret;
WC_RNG rng;
ecc_key eccKey;
wc_InitRng(&rng);
wc_ecc_init(&eccKey);
// Generate key
ret = wc_ecc_make_key(&rng, 32, &eccKey);
// Get signature length and allocate buffer
sigLen = wc_SignatureGetSize(sig_type, &eccKey, sizeof(eccKey));
sigBuf = malloc(sigLen);
// Perform signature verification using public key
ret = wc_SignatureGenerate(
WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
fileBuf, fileLen,
sigBuf, &sigLen,
&eccKey, sizeof(eccKey),
&rng);
printf("Signature Generation: %s
(%d)\n", (ret == 0) ? "Pass" : "Fail", ret);
free(sigBuf);
wc_ecc_free(&eccKey);
wc_FreeRng(&rng);
\endcode
\sa wc_SignatureGetSize
\sa wc_SignatureVerify
*/
int wc_SignatureGenerate(
enum wc_HashType hash_type, enum wc_SignatureType sig_type,
const byte* data, word32 data_len,
byte* sig, word32 *sig_len,
const void* key, word32 key_len,
WC_RNG* rng);

View File

@@ -0,0 +1,124 @@
/*!
\ingroup SipHash
\brief この関数は、MacサイズのキーでSiphashを初期化します。
\return 0 初期化に成功したときに返されます
\return BAD_FUNC_ARG SiphashまたはキーがNULLのときに返されます
\return BAD_FUNC_ARG OUTSZが8でも16でもない場合に返されます
\param siphash Macingに使用するサイプハッシュ構造へのポインタ
\param key 16バイト配列へのポインタ
_Example_
\code
SipHash siphash[1];
unsigned char key[16] = { ... };
byte macSz = 8; // 8 or 16
if ((ret = wc_InitSipHash(siphash, key, macSz)) != 0) {
WOLFSSL_MSG("wc_InitSipHash failed");
}
else if ((ret = wc_SipHashUpdate(siphash, data, len)) != 0) {
WOLFSSL_MSG("wc_SipHashUpdate failed");
}
else if ((ret = wc_SipHashFinal(siphash, mac, macSz)) != 0) {
WOLFSSL_MSG("wc_SipHashFinal failed");
}
\endcode
\sa wc_SipHash
\sa wc_SipHashUpdate
\sa wc_SipHashFinal
*/
int wc_InitSipHash(SipHash* siphash, const unsigned char* key,
unsigned char outSz);
/*!
\ingroup SipHash
\brief 長さLENの提供されたバイト配列を絶えずハッシュするように呼び出すことができます。
\return 0 Macにデータを追加したら、返されます
\return BAD_FUNC_ARG Siphashがnullのとき返されました
\return BAD_FUNC_ARG inneがnullのとき返され、Inszはゼロではありません
\param siphash Macingに使用するサイプハッシュ構造へのポインタ
\param in マイートするデータ
_Example_
\code
SipHash siphash[1];
byte data[] = { Data to be MACed };
word32 len = sizeof(data);
if ((ret = wc_InitSipHash(siphash, key, macSz)) != 0) {
WOLFSSL_MSG("wc_InitSipHash failed");
}
else if ((ret = wc_SipHashUpdate(siphash, data, len)) != 0) {
WOLFSSL_MSG("wc_SipHashUpdate failed");
}
else if ((ret = wc_SipHashFinal(siphash, mac, macSz)) != 0) {
WOLFSSL_MSG("wc_SipHashFinal failed");
}
\endcode
\sa wc_SipHash
\sa wc_InitSipHash
\sa wc_SipHashFinal
*/
int wc_SipHashUpdate(SipHash* siphash, const unsigned char* in,
word32 inSz);
/*!
\ingroup SipHash
\brief データのMacingを確定します。結果が出入りする。
\return 0 ファイナライズに成功したときに返されます。
\return BAD_FUNC_ARG SiphashのOUTがNULLのときに返されます
\return BAD_FUNC_ARG OUTSZが初期化された値と同じではない場合に返されます
\param siphash Macingに使用するサイプハッシュ構造へのポインタ
\param out MAC値を保持するためのバイト配列
_Example_
\code
SipHash siphash[1];
byte mac[8] = { ... }; // 8 or 16 bytes
byte macSz = sizeof(mac);
if ((ret = wc_InitSipHash(siphash, key, macSz)) != 0) {
WOLFSSL_MSG("wc_InitSipHash failed");
}
else if ((ret = wc_SipHashUpdate(siphash, data, len)) != 0) {
WOLFSSL_MSG("wc_SipHashUpdate failed");
}
else if ((ret = wc_SipHashFinal(siphash, mac, macSz)) != 0) {
WOLFSSL_MSG("wc_SipHashFinal failed");
}
\endcode
\sa wc_SipHash
\sa wc_InitSipHash
\sa wc_SipHashUpdate
*/
int wc_SipHashFinal(SipHash* siphash, unsigned char* out,
unsigned char outSz);
/*!
\ingroup SipHash
\brief この機能はSiphashを使用してデータを1ショットして、キーに基づいてMACを計算します。
\return 0 Macingに成功したときに返されました
\return BAD_FUNC_ARG キーまたはOUTがNULLのときに返されます
\return BAD_FUNC_ARG inneがnullのとき返され、Inszはゼロではありません
\return BAD_FUNC_ARG OUTSZが8でも16でもない場合に返されます
\param key 16バイト配列へのポインタ
\param in マイートするデータ
\param inSz マイクされるデータのサイズ
\param out MAC値を保持するためのバイト配列
_Example_
\code
unsigned char key[16] = { ... };
byte data[] = { Data to be MACed };
word32 len = sizeof(data);
byte mac[8] = { ... }; // 8 or 16 bytes
byte macSz = sizeof(mac);
if ((ret = wc_SipHash(key, data, len, mac, macSz)) != 0) {
WOLFSSL_MSG("wc_SipHash failed");
}
\endcode
\sa wc_InitSipHash
\sa wc_SipHashUpdate
\sa wc_SipHashFinal
*/
int wc_SipHash(const unsigned char* key, const unsigned char* in,
word32 inSz, unsigned char* out, unsigned char outSz);

View File

@@ -0,0 +1,399 @@
/*!
\ingroup SRP
\brief 使用方法のためにSRP構造体を初期化します。
\return 0 成功しています。
\return BAD_FUNC_ARG SRPなどの引数がNULLまたはSRPSIDEの問題がある場合は、SRP_CLIENT_SIESまたはSRP_SERVER_SIEDでは問題がある場合に返します。
\return NOT_COMPILED_IN タイプが引数として渡されたが、WolfCryptビルドに設定されていない場合。
\return <0 エラー時に。
\param srp 初期化されるSRP構造。
\param type 使用するハッシュ型。
_Example_
\code
Srp srp;
if (wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE) != 0)
{
// Initialization error
}
else
{
wc_SrpTerm(&srp);
}
\endcode
\sa wc_SrpTerm
\sa wc_SrpSetUsername
*/
int wc_SrpInit(Srp* srp, SrpType type, SrpSide side);
/*!
\ingroup SRP
\brief 使用後にSRP構造リソースを解放します。
\return none いいえ返します。
_Example_
\code
Srp srp;
wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE);
// Use srp
wc_SrpTerm(&srp)
\endcode
\sa wc_SrpInit
*/
void wc_SrpTerm(Srp* srp);
/*!
\ingroup SRP
\brief ユーザー名を設定します。この関数は、wc_srpinitの後に呼び出す必要があります。
\return 0 ユーザー名は正常に設定されました。
\return BAD_FUNC_ARG: srpまたはusernameがnullの場合に返します。
\return MEMORY_E: SRP->ユーザーにメモリを割り当てる問題がある場合
\return < 0エラー。
\param srp SRP構造
\param username ユーザー名を含むバッファ。
_Example_
\code
Srp srp;
byte username[] = "user";
word32 usernameSize = 4;
wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE);
if(wc_SrpSetUsername(&srp, username, usernameSize) != 0)
{
// Error occurred setting username.
}
wc_SrpTerm(&srp);
\endcode
\sa wc_SrpInit
\sa wc_SrpSetParams
\sa wc_SrpTerm
*/
int wc_SrpSetUsername(Srp* srp, const byte* username, word32 size);
/*!
\ingroup SRP
\brief ユーザー名に基づいてSRPパラメータを設定します.. wc_srpsetuserNameの後に呼び出す必要があります。
\return 0 成功
\return BAD_FUNC_ARG SRP、N、G、またはSALTがNULLの場合、またはNSZ <GSZの場合は返します。
\return SRP_CALL_ORDER_E wc_srpsetuserNameの前にwc_srpsetparamsが呼び出された場合、返します。
\return <0 エラー
\param srp SRP構造
\param N 弾性率n = 2q + 1、[q、n]はプリムです。
\param nSz nサイズをバイト単位で。
\param g ジェネレータモジュロN.
\param gSz バイト数のGサイズ
\param salt 小さいランダムな塩。各ユーザー名に特有のものです。
_Example_
\code
Srp srp;
byte username[] = "user";
word32 usernameSize = 4;
byte N[] = { }; // Contents of byte array N
byte g[] = { }; // Contents of byte array g
byte salt[] = { }; // Contents of byte array salt
wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE);
wc_SrpSetUsername(&srp, username, usernameSize);
if(wc_SrpSetParams(&srp, N, sizeof(N), g, sizeof(g), salt,
sizeof(salt)) != 0)
{
// Error setting params
}
wc_SrpTerm(&srp);
\endcode
\sa wc_SrpInit
\sa wc_SrpSetUsername
\sa wc_SrpTerm
*/
int wc_SrpSetParams(Srp* srp, const byte* N, word32 nSz,
const byte* g, word32 gSz,
const byte* salt, word32 saltSz);
/*!
\ingroup SRP
\brief パスワードを設定します。パスワードを設定しても、SRP構造内のパスワードデータが消去されません。クライアントは、x = hsalt + huserpswdを計算し、それを認証フィールドに格納します。この関数は、wc_srpsetparamsの後に呼び出されなければならず、クライアント側のみです。
\return 0 成功
\return BAD_FUNC_ARG srpまたはpasswordがnullの場合、またはsrp-> sideがsrp_client_sideに設定されていない場合。
\return SRP_CALL_ORDER_E WC_SRPSETPASSWORDが順不同で呼び出されたときに戻ります。
\return <0 エラー
\param srp SRP構造
\param password パスワードを含むバッファ。
_Example_
\code
Srp srp;
byte username[] = "user";
word32 usernameSize = 4;
byte password[] = "password";
word32 passwordSize = 8;
byte N[] = { }; // Contents of byte array N
byte g[] = { }; // Contents of byte array g
byte salt[] = { }; // Contents of byte array salt
wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE);
wc_SrpSetUsername(&srp, username, usernameSize);
wc_SrpSetParams(&srp, N, sizeof(N), g, sizeof(g), salt, sizeof(salt));
if(wc_SrpSetPassword(&srp, password, passwordSize) != 0)
{
// Error setting password
}
wc_SrpTerm(&srp);
\endcode
\sa wc_SrpInit
\sa wc_SrpSetUsername
\sa wc_SrpSetParams
*/
int wc_SrpSetPassword(Srp* srp, const byte* password, word32 size);
/*!
\ingroup SRP
\brief 検証者を設定します。この関数は、wc_srpsetparamsの後に呼び出され、サーバー側のみです。
\return 0 成功
\return BAD_FUNC_ARG SRPまたはVerifierがNULLまたはSRP-> ISの場合、SRP_SERVER_SIEDではなく返されます。
\return <0 エラー
\param srp SRP構造
\param verifier 検証者を含む構造体。
_Example_
\code
Srp srp;
byte username[] = "user";
word32 usernameSize = 4;
byte N[] = { }; // Contents of byte array N
byte g[] = { }; // Contents of byte array g
byte salt[] = { }; // Contents of byte array salt
wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_SERVER_SIDE);
wc_SrpSetUsername(&srp, username, usernameSize);
wc_SrpSetParams(&srp, N, sizeof(N), g, sizeof(g), salt, sizeof(salt))
byte verifier[] = { }; // Contents of some verifier
if(wc_SrpSetVerifier(&srp, verifier, sizeof(verifier)) != 0)
{
// Error setting verifier
}
wc_SrpTerm(&srp);
\endcode
\sa wc_SrpInit
\sa wc_SrpSetParams
\sa wc_SrpGetVerifier
*/
int wc_SrpSetVerifier(Srp* srp, const byte* verifier, word32 size);
/*!
\ingroup SRP
\brief 検証者を取得します。クライアントはV = g ^ xNで検証者を計算します。この関数は、wc_srpsetpasswordの後に呼び出され、クライアント側のみです。
\return 0 成功
\return BAD_FUNC_ARG SRP、Verifier、またはSizeがNULLの場合、またはSRP-> SIDEがSRP_CLIENT_SIEDではない場合に返されます。
\return SRP_CALL_ORDER_E WC_SRPGetverifierが順不同で呼び出された場合に返されます。
\return <0 エラー
\param srp SRP構造
\param verifier 検証者を書き込むためのバッファー。
_Example_
\code
Srp srp;
byte username[] = "user";
word32 usernameSize = 4;
byte password[] = "password";
word32 passwordSize = 8;
byte N[] = { }; // Contents of byte array N
byte g[] = { }; // Contents of byte array g
byte salt[] = { }; // Contents of byte array salt
byte v[64];
word32 vSz = 0;
vSz = sizeof(v);
wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE);
wc_SrpSetUsername(&srp, username, usernameSize);
wc_SrpSetParams(&srp, N, sizeof(N), g, sizeof(g), salt, sizeof(salt))
wc_SrpSetPassword(&srp, password, passwordSize)
if( wc_SrpGetVerifier(&srp, v, &vSz ) != 0)
{
// Error getting verifier
}
wc_SrpTerm(&srp);
\endcode
\sa wc_SrpSetVerifier
\sa wc_SrpSetPassword
*/
int wc_SrpGetVerifier(Srp* srp, byte* verifier, word32* size);
/*!
\ingroup SRP
\brief プライベートのエフェラル値を設定します。プライベートの一時的な値は、クライアント側のAとして知られています。サーバー側のand randomb。b = randomこの関数は、ユニットテストケース、または開発者が外部ランダムソースを使用してエフェメラル値を設定したい場合は便利です。この関数は、WC_SRPGetPublicの前に呼び出されることがあります。
\return 0 成功
\return BAD_FUNC_ARG SRP、Private、またはSizeがNULLの場合に返されます。
\return SRP_CALL_ORDER_E WC_SRPSetPrivateが順不同で呼び出された場合に返されます。
\return <0 エラー
\param srp SRP構造
\param priv 一時的な値。
_Example_
\code
Srp srp;
byte username[] = "user";
word32 usernameSize = 4;
byte N[] = { }; // Contents of byte array N
byte g[] = { }; // Contents of byte array g
byte salt[] = { }; // Contents of byte array salt
byte verifier = { }; // Contents of some verifier
wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_SERVER_SIDE);
wc_SrpSetUsername(&srp, username, usernameSize);
wc_SrpSetParams(&srp, N, sizeof(N), g, sizeof(g), salt, sizeof(salt))
wc_SrpSetVerifier(&srp, verifier, sizeof(verifier))
byte b[] = { }; // Some ephemeral value
if( wc_SrpSetPrivate(&srp, b, sizeof(b)) != 0)
{
// Error setting private ephemeral
}
wc_SrpTerm(&srp);
\endcode
\sa wc_SrpGetPublic
*/
int wc_SrpSetPrivate(Srp* srp, const byte* priv, word32 size);
/*!
\ingroup SRP
\brief 公共の一時的な値を取得します。公共の一時的な値は、クライアント側のAとして知られています。サーバ側のA = g ^ An b。B =k * v +g bnn wc_srpsetpasswordまたはwc_srpsetverifierの後に呼び出す必要があります。関数WC_SRPSetPrivateは、WC_SRPGetPublicの前に呼び出されることがあります。
\return 0 成功
\return BAD_FUNC_ARG srp、pub、またはsizeがnullの場合に返されます。
\return SRP_CALL_ORDER_E WC_SRPGetPublicが順不同で呼び出された場合に返されます。
\return BUFFER_E サイズ<srp.nの場合は返しました。
\return <0 エラー
\param srp SRP構造
\param pub パブリックエフェラル値を書き込むためのバッファ。
_Example_
\code
Srp srp;
byte username[] = "user";
word32 usernameSize = 4;
byte password[] = "password";
word32 passwordSize = 8;
byte N[] = { }; // Contents of byte array N
byte g[] = { }; // Contents of byte array g
byte salt[] = { }; // Contents of byte array salt
wc_SrpInit(&srp, SRP_TYPE_SHA, SRP_CLIENT_SIDE);
wc_SrpSetUsername(&srp, username, usernameSize);
wc_SrpSetParams(&srp, N, sizeof(N), g, sizeof(g), salt, sizeof(salt));
wc_SrpSetPassword(&srp, password, passwordSize)
byte public[64];
word32 publicSz = 0;
if( wc_SrpGetPublic(&srp, public, &publicSz) != 0)
{
// Error getting public ephemeral
}
wc_SrpTerm(&srp);
\endcode
\sa wc_SrpSetPrivate
\sa wc_SrpSetPassword
\sa wc_SrpSetVerifier
*/
int wc_SrpGetPublic(Srp* srp, byte* pub, word32* size);
/*!
\ingroup SRP
\brief セッションキーを計算します。成功後にSRP->キーでキーをアクセスできます。
\return 0 成功
\return BAD_FUNC_ARG SRP、ClientPubKey、またはServerPubKeyの場合、またはClientPubkeyszまたはServerPubKeyszが0の場合に返されます。
\return SRP_CALL_ORDER_E WC_SRPComputeKeyが順不同で呼び出された場合に返されます。
\return <0 エラー
\param srp SRP構造
\param clientPubKey クライアントの公共の一時的な価値。
\param clientPubKeySz クライアントの公共の一時的な値のサイズ。
\param serverPubKey サーバーの一般の一時的な値。
_Example_
\code
Srp server;
byte username[] = "user";
word32 usernameSize = 4;
byte password[] = "password";
word32 passwordSize = 8;
byte N[] = { }; // Contents of byte array N
byte g[] = { }; // Contents of byte array g
byte salt[] = { }; // Contents of byte array salt
byte verifier[] = { }; // Contents of some verifier
byte serverPubKey[] = { }; // Contents of server pub key
word32 serverPubKeySize = sizeof(serverPubKey);
byte clientPubKey[64];
word32 clientPubKeySize = 64;
wc_SrpInit(&server, SRP_TYPE_SHA, SRP_SERVER_SIDE);
wc_SrpSetUsername(&server, username, usernameSize);
wc_SrpSetParams(&server, N, sizeof(N), g, sizeof(g), salt, sizeof(salt));
wc_SrpSetVerifier(&server, verifier, sizeof(verifier));
wc_SrpGetPublic(&server, serverPubKey, &serverPubKeySize);
wc_SrpComputeKey(&server, clientPubKey, clientPubKeySz,
serverPubKey, serverPubKeySize)
wc_SrpTerm(&server);
\endcode
\sa wc_SrpGetPublic
*/
int wc_SrpComputeKey(Srp* srp,
byte* clientPubKey, word32 clientPubKeySz,
byte* serverPubKey, word32 serverPubKeySz);
/*!
\ingroup SRP
\brief 証明を取得します。この関数は、wc_srpcomputekeyの後に呼び出す必要があります。
\return 0 成功
\return BAD_FUNC_ARG SRP、PROV、またはSIZEがNULLの場合に返します。
\return BUFFER_E サイズがSRP-> Typeのハッシュサイズより小さい場合に返します。
\return <0 エラー
\param srp SRP構造
\param proof ピアプルーフ。
_Example_
\code
Srp cli;
byte clientProof[SRP_MAX_DIGEST_SIZE];
word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
// Initialize Srp following steps from previous examples
if (wc_SrpGetProof(&cli, clientProof, &clientProofSz) != 0)
{
// Error getting proof
}
\endcode
\sa wc_SrpComputeKey
*/
int wc_SrpGetProof(Srp* srp, byte* proof, word32* size);
/*!
\ingroup SRP
\brief ピアプルーフを確認します。この関数は、WC_SRPGetSessionKeyの前に呼び出す必要があります。
\return 0 成功
\return <0 エラー
\param srp SRP構造
\param proof ピアプルーフ。
_Example_
\code
Srp cli;
Srp srv;
byte clientProof[SRP_MAX_DIGEST_SIZE];
word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
// Initialize Srp following steps from previous examples
// First get the proof
wc_SrpGetProof(&cli, clientProof, &clientProofSz)
if (wc_SrpVerifyPeersProof(&srv, clientProof, clientProofSz) != 0)
{
// Error verifying proof
}
\endcode
\sa wc_SrpGetSessionKey
\sa wc_SrpGetProof
\sa wc_SrpTerm
*/
int wc_SrpVerifyPeersProof(Srp* srp, byte* proof, word32 size);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
/*!
\ingroup Math
\brief この関数は、整数の最大サイズのランタイムFastMath設定をチェックします。FP_SIZEが正しく機能するために、FP_SIZEが各ライブラリーに一致しなければならないため、ユーザーがWolfCryptライブラリを独立して使用している場合に重要です。このチェックはCheckFastMathSettingsとして定義されています。これは、CheckRuntimeFastMathとFP_SIZEを比較するだけで、ミスマッチがある場合は0を返します。
\return FP_SIZE 数学ライブラリで利用可能な最大サイズに対応するFP_SIZEを返します。
_Example_
\code
if (CheckFastMathSettings() != 1) {
return err_sys("Build vs. runtime fastmath FP_MAX_BITS mismatch\n");
}
// This is converted by the preprocessor to:
// if ( (CheckRunTimeFastMath() == FP_SIZE) != 1) {
// and confirms that the fast math settings match
// the compile time settings
\endcode
\sa CheckRunTimeSettings
*/
word32 CheckRunTimeFastMath(void);

View File

@@ -0,0 +1,81 @@
/*!
\ingroup Memory
\brief これは実際には関数ではなく、むしろプリプロセッサマクロであり、ユーザーは自分のMalloc、Realloc、および標準のCメモリ関数の代わりに自由な関数に置き換えることができます。外部メモリ機能を使用するには、xmalloc_userを定義します。これにより、メモリ機能をフォームの外部関数に置き換えます.extern void * xmallocsize_t n、void * heap、int型; extern void * XrealLocvoid * p、size_t n、void *ヒープ、int型。 extern void xfreevoid * p、void * heap、int型; wolfssl_malloc、wolfssl_realloc、wolfssl_freeの代わりに基本的なCメモリ機能を使用するには、NO_WOLFSSL_MEMORYを定義します。これにより、メモリ関数が次のものに置き換えられます。#define Xmallocs、h、tvoidh、voidt、mallocs#define xfreep、h、t{void * xp =p; ifxpfreexp; #define xreallocp、n、h、tReallocpnこれらのオプションのどれも選択されていない場合、システムはデフォルトで使用されます。 WolfSSLメモリ機能ユーザーはコールバックフックを介してカスタムメモリ機能を設定できますWolfssl_Malloc、WolfSSL_Realloc、wolfssl_freeを参照。このオプションは、メモリ関数を次のものに置き換えます。#define xmallocs、h、tvoidH、VoidT、wolfssl_mallocs#define xfreep、h、t{void * XP =P; ifxpwolfssl_freexp; #define xreallocp、n、h、twolfssl_reallocpn
\return pointer 成功したメモリへのポインタを返します
\return NULL 失敗した
\param s 割り当てるメモリのサイズ
\param h カスタムXMalloc関数で使用されています使用するヒープへのポインタ
_Example_
\code
int* tenInts = XMALLOC(sizeof(int)*10, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (tenInts == NULL) {
// error allocating space
return MEMORY_E;
}
\endcode
\sa wolfSSL_Malloc
\sa wolfSSL_Realloc
\sa wolfSSL_Free
\sa wolfSSL_SetAllocators
*/
void* XMALLOC(size_t n, void* heap, int type);
/*!
\ingroup Memory
\brief これは実際には関数ではなく、むしろプリプロセッサマクロであり、ユーザーは自分のMalloc、Realloc、および標準のCメモリ関数の代わりに自由な関数に置き換えることができます。外部メモリ機能を使用するには、xmalloc_userを定義します。これにより、メモリ機能をフォームの外部関数に置き換えます.extern void * xmallocsize_t n、void * heap、int型; extern void * XrealLocvoid * p、size_t n、void *ヒープ、int型。 extern void xfreevoid * p、void * heap、int型; wolfssl_malloc、wolfssl_realloc、wolfssl_freeの代わりに基本的なCメモリ機能を使用するには、NO_WOLFSSL_MEMORYを定義します。これにより、メモリ関数が次のものに置き換えられます。#define Xmallocs、h、tvoidh、voidt、mallocs#define xfreep、h、t{void * xp =p; ifxpfreexp; #define xreallocp、n、h、tReallocpnこれらのオプションのどれも選択されていない場合、システムはデフォルトで使用されます。 WolfSSLメモリ機能ユーザーはコールバックフックを介してカスタムメモリ機能を設定できますWolfssl_Malloc、WolfSSL_Realloc、wolfssl_freeを参照。このオプションは、メモリ関数を次のものに置き換えます。#define xmallocs、h、tvoidH、VoidT、wolfssl_mallocs#define xfreep、h、t{void * XP =P; ifxpwolfssl_freexp; #define xreallocp、n、h、twolfssl_reallocpn
\return Return 成功したメモリを割り当てるポインタ
\return NULL 失敗した
\param p Reallocateへのアドレスへのポインタ
\param n 割り当てるメモリのサイズ
\param h カスタムXrealloc関数で使用されています使用するヒープへのポインタ
_Example_
\code
int* tenInts = (int*)XMALLOC(sizeof(int)*10, NULL, DYNAMIC_TYPE_TMP_BUFFER);
int* twentyInts = (int*)XREALLOC(tenInts, sizeof(int)*20, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
\endcode
\sa wolfSSL_Malloc
\sa wolfSSL_Realloc
\sa wolfSSL_Free
\sa wolfSSL_SetAllocators
*/
void* XREALLOC(void *p, size_t n, void* heap, int type);
/*!
\ingroup Memory
\brief これは実際には関数ではなく、むしろプリプロセッサマクロであり、ユーザーは自分のMalloc、Realloc、および標準のCメモリ関数の代わりに自由な関数に置き換えることができます。外部メモリ機能を使用するには、xmalloc_userを定義します。これにより、メモリ機能をフォームの外部関数に置き換えます.extern void * xmallocsize_t n、void * heap、int型; extern void * XrealLocvoid * p、size_t n、void *ヒープ、int型。 extern void xfreevoid * p、void * heap、int型; wolfssl_malloc、wolfssl_realloc、wolfssl_freeの代わりに基本的なCメモリ機能を使用するには、NO_WOLFSSL_MEMORYを定義します。これにより、メモリ関数が次のものに置き換えられます。#define Xmallocs、h、tvoidh、voidt、mallocs#define xfreep、h、t{void * xp =p; ifxpfreexp; #define xreallocp、n、h、tReallocpnこれらのオプションのどれも選択されていない場合、システムはデフォルトで使用されます。 WolfSSLメモリ機能ユーザーはコールバックフックを介してカスタムメモリ機能を設定できますWolfssl_Malloc、WolfSSL_Realloc、wolfssl_freeを参照。このオプションは、メモリ関数を次のものに置き換えます。#define xmallocs、h、tvoidH、VoidT、wolfssl_mallocs#define xfreep、h、t{void * XP =P; ifxpwolfssl_freexp; #define xreallocp、n、h、twolfssl_reallocpn
\return none いいえ返します。
\param p 無料のアドレスへのポインタ
\param h 使用するヒープへのカスタムXFree関数で使用されています
_Example_
\code
int* tenInts = XMALLOC(sizeof(int) * 10, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (tenInts == NULL) {
// error allocating space
return MEMORY_E;
}
\endcode
\sa wolfSSL_Malloc
\sa wolfSSL_Realloc
\sa wolfSSL_Free
\sa wolfSSL_SetAllocators
*/
void XFREE(void *p, void* heap, int type);
/*!
\ingroup Math
\brief この関数はコンパイル時クラスの設定をチェックします。設定が正しく機能するためのライブラリ間のライブラリ間で一致する必要があるため、ユーザーがWolfCryptライブラリを独立して使用している場合は重要です。このチェックはCheckCtcSettingsとして定義されています。これは、CheckRuntimeSettingsとCTC_Settingsを比較するだけで、ミスマッチがある場合は0、または1が一致した場合は1を返します。
\return settings 実行時CTC_SETTINGSコンパイル時設定を返します。
_Example_
\code
if (CheckCtcSettings() != 1) {
return err_sys("Build vs. runtime math mismatch\n");
}
// This is converted by the preprocessor to:
// if ( (CheckCtcSettings() == CTC_SETTINGS) != 1) {
// and will compare whether the compile time class settings
// match the current settings
\endcode
\sa CheckRunTimeFastMath
*/
word32 CheckRunTimeSettings(void);

View File

@@ -0,0 +1,150 @@
/*!
\ingroup AES
\brief 入力バッファーから暗号を復号化し、AESでCipher Block Chainingを使用して出力バッファに出力バッファーに入れます。この関数は、AES構造を初期化する必要はありません。代わりに、キーとIV初期化ベクトルを取り、これらを使用してAESオブジェクトを初期化してから暗号テキストを復号化します。
\return 0 メッセージの復号化に成功しました
\return BAD_ALIGN_E ブロック整列エラーに戻りました
\return BAD_FUNC_ARG aesetivの間にキーの長さが無効な場合、またはAESオブジェクトがNULLの場合
\return MEMORY_E wolfssl_small_stackが有効になっていて、xmallocがAESオブジェクトのインスタンス化に失敗した場合に返されます。
\param out 復号化されたメッセージのプレーンテキストを保存する出力バッファへのポインタ
\param in 復号化される暗号テキストを含む入力バッファへのポインタ
\param inSz 入力メッセージのサイズ
\param key 復号化のための16,24、または32バイトの秘密鍵
_Example_
\code
int ret = 0;
byte key[] = { some 16, 24, or 32 byte key };
byte iv[] = { some 16 byte iv };
byte cipher[AES_BLOCK_SIZE * n]; //n being a positive integer making
cipher some multiple of 16 bytes
// fill cipher with cipher text
byte plain [AES_BLOCK_SIZE * n];
if ((ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key,
AES_BLOCK_SIZE, iv)) != 0 ) {
// Decrypt Error
}
\endcode
\sa wc_AesSetKey
\sa wc_AesSetIV
\sa wc_AesCbcEncrypt
\sa wc_AesCbcDecrypt
*/
int wc_AesCbcDecryptWithKey(byte* out, const byte* in, word32 inSz,
const byte* key, word32 keySz,
const byte* iv);
/*!
\ingroup 3DES
\brief この関数は入力暗号文を復号化し、結果の平文を出力バッファーに出力します。暗号ブロックチェーンチェーンCBCモードでDES暗号化を使用します。この関数は、wc_des_cbcdecryptの代わりに、ユーザーがDES構造体を直接インスタンス化せずにメッセージを復号化できるようにします。
\return 0 与えられた暗号文を正常に復号化したときに返されました
\return MEMORY_E DES構造体の割り当てスペースが割り当てられている場合に返された
\param out 復号化された平文を保存するバッファへのポインタ
\param in 暗号化された暗号文を含む入力バッファへのポインタ
\param sz 復号化する暗号文の長さ
\param key 復号化に使用する8バイトのキーを含むバッファへのポインタ
_Example_
\code
int ret;
byte key[] = { // initialize with 8 byte key };
byte iv[] = { // initialize with 8 byte iv };
byte cipher[] = { // initialize with ciphertext };
byte decoded[sizeof(cipher)];
if ( wc_Des_CbcDecryptWithKey(decoded, cipher, sizeof(cipher), key,
iv) != 0) {
// error decrypting message
}
\endcode
\sa wc_Des_CbcDecrypt
*/
int wc_Des_CbcDecryptWithKey(byte* out,
const byte* in, word32 sz,
const byte* key, const byte* iv);
/*!
\ingroup 3DES
\brief この関数は入力平文を暗号化し、結果の暗号文を出力バッファーに出力します。暗号ブロックチェーンチェーンCBCモードでDES暗号化を使用します。この関数は、WC_DES_CBCENCRYPTの代わりになり、ユーザーがDES構造を直接インスタンス化せずにメッセージを暗号化できます。
\return 0 データの暗号化に成功した後に返されます。
\return MEMORY_E DES構造体にメモリを割り当てるエラーがある場合は返されます。
\return <0 暗号化中に任意のエラーに戻ります。
\param out 最終暗号化データ
\param in 暗号化されるデータは、DESブロックサイズに埋められなければなりません。
\param sz 入力バッファのサイズ
\param key 暗号化に使用するキーへのポインタ。
_Example_
\code
byte key[] = { // initialize with 8 byte key };
byte iv[] = { // initialize with 8 byte iv };
byte in[] = { // Initialize with plaintext };
byte out[sizeof(in)];
if ( wc_Des_CbcEncryptWithKey(&out, in, sizeof(in), key, iv) != 0)
{
// error encrypting message
}
\endcode
\sa wc_Des_CbcDecryptWithKey
\sa wc_Des_CbcEncrypt
*/
int wc_Des_CbcEncryptWithKey(byte* out,
const byte* in, word32 sz,
const byte* key, const byte* iv);
/*!
\ingroup 3DES
\brief この関数は入力平文を暗号化し、結果の暗号文を出力バッファーに出力します。暗号ブロックチェーンCBCモードでトリプルDES3DES暗号化を使用します。この関数は、WC_DES3_CBCENCRYPTの代わりになり、ユーザーがDES3構造を直接インスタンス化せずにメッセージを暗号化できます。
\return 0 データの暗号化に成功した後に返されます。
\return MEMORY_E DES構造体にメモリを割り当てるエラーがある場合は返されます。
\return <0 暗号化中に任意のエラーに戻ります。
\param out 最終暗号化データ
\param in 暗号化されるデータは、DESブロックサイズに埋められなければなりません。
\param sz 入力バッファのサイズ
\param key 暗号化に使用するキーへのポインタ。
_Example_
\code
byte key[] = { // initialize with 8 byte key };
byte iv[] = { // initialize with 8 byte iv };
byte in[] = { // Initialize with plaintext };
byte out[sizeof(in)];
if ( wc_Des3_CbcEncryptWithKey(&out, in, sizeof(in), key, iv) != 0)
{
// error encrypting message
}
\endcode
\sa wc_Des3_CbcDecryptWithKey
\sa wc_Des_CbcEncryptWithKey
\sa wc_Des_CbcDecryptWithKey
*/
int wc_Des3_CbcEncryptWithKey(byte* out,
const byte* in, word32 sz,
const byte* key, const byte* iv);
/*!
\ingroup 3DES
\brief この関数は入力暗号文を復号化し、結果の平文を出力バッファーに出力します。暗号ブロックチェーンCBCモードでトリプルDES3DES暗号化を使用します。この関数は、wc_des3_cbcdecryptの代わりに、ユーザーがDES3構造を直接インスタンス化せずにメッセージを復号化できるようにします。
\return 0 与えられた暗号文を正常に復号化したときに返されました
\return MEMORY_E DES構造体の割り当てスペースが割り当てられている場合に返された
\param out 復号化された平文を保存するバッファへのポインタ
\param in 暗号化された暗号文を含む入力バッファへのポインタ
\param sz 復号化する暗号文の長さ
\param key 復号化に使用する24バイトのキーを含むバッファへのポインタ
_Example_
\code
int ret;
byte key[] = { // initialize with 24 byte key };
byte iv[] = { // initialize with 8 byte iv };
byte cipher[] = { // initialize with ciphertext };
byte decoded[sizeof(cipher)];
if ( wc_Des3_CbcDecryptWithKey(decoded, cipher, sizeof(cipher),
key, iv) != 0) {
// error decrypting message
}
\endcode
\sa wc_Des3_CbcDecrypt
*/
int wc_Des3_CbcDecryptWithKey(byte* out,
const byte* in, word32 sz,
const byte* key, const byte* iv);

View File

@@ -0,0 +1,31 @@
/*!
\ingroup wolfCrypt
\brief WolfCryptによって使用されるリソースを初期化するために使用されます。
\return 0 成功すると。
\return <0 initリソースが失敗すると。
_Example_
\code
...
if (wolfCrypt_Init() != 0) {
WOLFSSL_MSG("Error with wolfCrypt_Init call");
}
\endcode
\sa wolfCrypt_Cleanup
*/
int wolfCrypt_Init(void);
/*!
\ingroup wolfCrypt
\brief WolfCryptによって使用されるリソースをクリーンアップするために使用されます。
\return 0 成功すると。
\return <0 リソースのクリーンアップが失敗したとき。
_Example_
\code
...
if (wolfCrypt_Cleanup() != 0) {
WOLFSSL_MSG("Error with wolfCrypt_Cleanup call");
}
\endcode
\sa wolfCrypt_Init
*/
int wolfCrypt_Cleanup(void);

View File

@@ -0,0 +1,398 @@
/*!
\brief
\return Success この関数は、読み取られたバイト数を返します。
\return WOLFSSL_CBIO_ERR_WANT_READ 最後のエラーがsocket_ewouldbolcokまたはsocket_eagainであれば、メッセージを返されます。
\return WOLFSSL_CBIO_ERR_TIMEOUT "Socket Timeout"メッセージを返しました。
\return WOLFSSL_CBIO_ERR_CONN_RST 最後のエラーがsocket_econnresetの場合、 "Connection Reset"メッセージで返されます。
\return WOLFSSL_CBIO_ERR_ISR 最後のエラーがsocket_eintrの場合、 "Socket Interrupted"メッセージが返されます。
\return WOLFSSL_CBIO_ERR_WANT_READ 最後のエラーがsocket_econneRefusedの場合、「接続拒否」メッセージを返しました。
\return WOLFSSL_CBIO_ERR_CONN_CLOSE 最後のエラーがSOCKET_ECONNABORTEDの場合、「接続中止」メッセージで返されます。
\return WOLFSSL_CBIO_ERR_GENERAL 最後のエラーが指定されていない場合は、「一般的なエラー」メッセージで返されます。
\param ssl wolfssl_newを使用して作成されたWolfSSL構造へのポインタ。
\param buf バッファのチャーポインタ表現。
\param sz バッファのサイズ。
_Example_
\code
WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
WOLFSSL* ssl = wolfSSL_new(ctx);
char* buf;
int sz;
void* ctx;
int bytesRead = EmbedReceive(ssl, buf, sz, ctx);
if(bytesRead <= 0){
// There were no bytes read. Failure case.
}
\endcode
\sa EmbedSend
\sa wolfSSL_CTX_SetIORecv
\sa wolfSSL_SSLSetIORecv
*/
int EmbedReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx);
/*!
\brief
\return Success この関数は送信されたバイト数を返します。
\return WOLFSSL_CBIO_ERR_WANT_WRITE 最後のエラーがsocket_ewouldblockまたはsocket_eagainであれば、 "Block"メッセージを返します。
\return WOLFSSL_CBIO_ERR_CONN_RST 最後のエラーがsocket_econnresetの場合、 "Connection Reset"メッセージで返されます。
\return WOLFSSL_CBIO_ERR_ISR 最後のエラーがsocket_eintrの場合、 "Socket Interrupted"メッセージが返されます。
\return WOLFSSL_CBIO_ERR_CONN_CLOSE 最後のエラーがsocket_epipeの場合、 "Socket Epipe"メッセージを返しました。
\return WOLFSSL_CBIO_ERR_GENERAL 最後のエラーが指定されていない場合は、「一般的なエラー」メッセージで返されます。
\param ssl wolfssl_newを使用して作成されたWolfSSL構造へのポインタ。
\param buf バッファを表す文字ポインタ。
\param sz バッファのサイズ。
_Example_
\code
WOLFSSL* ssl = wolfSSL_new(ctx);
char* buf;
int sz;
void* ctx;
int dSent = EmbedSend(ssl, buf, sz, ctx);
if(dSent <= 0){
// No byes sent. Failure case.
}
\endcode
\sa EmbedReceive
\sa wolfSSL_CTX_SetIOSend
\sa wolfSSL_SSLSetIOSend
*/
int EmbedSend(WOLFSSL* ssl, char* buf, int sz, void* ctx);
/*!
\brief
\return Success この関数は、実行が成功した場合に読み込まれたNBバイトを返します。
\return WOLFSSL_CBIO_ERR_WANT_READ 接続が拒否された場合、または「ブロック」エラーが発生した場合は機能にスローされました。
\return WOLFSSL_CBIO_ERR_TIMEOUT ソケットがタイムアウトした場合は返されます。
\return WOLFSSL_CBIO_ERR_CONN_RST 接続がリセットされている場合は返されます。
\return WOLFSSL_CBIO_ERR_ISR ソケットが中断された場合は返されます。
\return WOLFSSL_CBIO_ERR_GENERAL 一般的なエラーがあった場合に返されます。
\param ssl wolfssl_newを使用して作成されたWolfSSL構造へのポインタ。
\param buf バッファへの定数の文字ポインタ。
\param sz バッファのサイズを表すint型。
_Example_
\code
WOLFSSL_CTX* ctx = wolfSSL_CTX_new( protocol method );
WOLFSSL* ssl = WOLFSSL_new(ctx);
char* buf;
int sz = sizeof(buf)/sizeof(char);
(void*)ctx;
int nb = EmbedReceiveFrom(ssl, buf, sz, ctx);
if(nb > 0){
// nb is the number of bytes written and is positive
}
\endcode
\sa EmbedSendTo
\sa wolfSSL_CTX_SetIORecv
\sa wolfSSL_SSLSetIORecv
\sa wolfSSL_dtls_get_current_timeout
*/
int EmbedReceiveFrom(WOLFSSL* ssl, char* buf, int sz, void*);
/*!
\brief
\return Success この関数は送信されたバイト数を返します。
\return WOLFSSL_CBIO_ERR_WANT_WRITE 最後のエラーがsocket_ewouldblockまたはsocket_eagainエラーの場合、 "Block"メッセージを返します。
\return WOLFSSL_CBIO_ERR_CONN_RST 最後のエラーがsocket_econnresetの場合、 "Connection Reset"メッセージで返されます。
\return WOLFSSL_CBIO_ERR_ISR 最後のエラーがsocket_eintrの場合、 "Socket Interrupted"メッセージが返されます。
\return WOLFSSL_CBIO_ERR_CONN_CLOSE 最後のエラーがwolfssl_cbio_err_conn_croseの場合、 "Socket Epipe"メッセージを返しました。
\return WOLFSSL_CBIO_ERR_GENERAL 最後のエラーが指定されていない場合は、「一般的なエラー」メッセージで返されます。
\param ssl wolfssl_newを使用して作成されたWolfSSL構造へのポインタ。
\param buf バッファを表す文字ポインタ。
\param sz バッファのサイズ。
_Example_
\code
WOLFSSL* ssl;
char* buf;
int sz;
void* ctx;
int sEmbed = EmbedSendto(ssl, buf, sz, ctx);
if(sEmbed <= 0){
// No bytes sent. Failure case.
}
\endcode
\sa EmbedReceiveFrom
\sa wolfSSL_CTX_SetIOSend
\sa wolfSSL_SSLSetIOSend
*/
int EmbedSendTo(WOLFSSL* ssl, char* buf, int sz, void* ctx);
/*!
\brief
\return Success この関数は、バッファにコピーされたバイト数を返します。
\return GEN_COOKIE_E getPeernameがEmbedGenerateCookieに失敗した場合に返されます。
\param ssl wolfssl_newを使用して作成されたWolfSSL構造へのポインタ。
\param buf バッファを表すバイトポインタ。xmemcpyからの宛先です。
\param sz バッファのサイズ。
_Example_
\code
WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
WOLFSSL* ssl = wolfSSL_new(ctx);
byte buffer[BUFFER_SIZE];
int sz = sizeof(buffer)/sizeof(byte);
void* ctx;
int ret = EmbedGenerateCookie(ssl, buffer, sz, ctx);
if(ret > 0){
// EmbedGenerateCookie code block for success
}
\endcode
\sa wolfSSL_CTX_SetGenCookie
*/
int EmbedGenerateCookie(WOLFSSL* ssl, unsigned char* buf,
int sz, void*);
/*!
\brief
\return none いいえ返します。
\param ctx ヒープヒントへのvoidポインタ。
_Example_
\code
void* ctx;
byte* resp; // Response buffer.
EmbedOcspRespFree(ctx, resp);
\endcode
\sa wolfSSL_CertManagerSetOCSP_Cb
\sa wolfSSL_CertManagerEnableOCSPStapling
\sa wolfSSL_CertManagerEnableOCSP
*/
void EmbedOcspRespFree(void* ctx, byte* resp);
/*!
\brief データ。デフォルトでは、WolfSSLはシステムのTCP RECV関数を使用するコールバックとしてEmbedReceiveを使用します。ユーザは、メモリ、他のネットワークモジュール、またはどこからでも入力するように機能を登録できます。関数の機能とエラーコードのためのガイドとして、src / io.cの埋め込みReceive関数を参照してください。特に、データが準備ができていないときに、IO_ERR_WANT_READを非ブロック受信用に返す必要があります。
\return none いいえ返します。
\param ctx wolfssl_ctx_newで作成されたSSLコンテキストへのポインタ。
_Example_
\code
WOLFSSL_CTX* ctx = 0;
// Receive callback prototype
int MyEmbedReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx);
// Register the custom receive callback with wolfSSL
wolfSSL_CTX_SetIORecv(ctx, MyEmbedReceive);
int MyEmbedReceive(WOLFSSL* ssl, char* buf, int sz, void* ctx)
{
// custom EmbedReceive function
}
\endcode
\sa wolfSSL_CTX_SetIOSend
\sa wolfSSL_SetIOReadCtx
\sa wolfSSL_SetIOWriteCtx
*/
void wolfSSL_CTX_SetIORecv(WOLFSSL_CTX* ctx, CallbackIORecv CBIORecv);
/*!
\brief コールバック関数デフォルトでは、WolfSSLは、WolfSSLがシステムのTCPライブラリを使用している場合、wolfssl_set_fdに渡されたファイル記述子をコンテキストとして設定します。自分の受信コールバックを登録した場合は、セッションの特定のコンテキストを設定することができます。たとえば、メモリバッファを使用している場合、コンテキストは、メモリバッファーのどこにありかを説明する構造へのポインタであり得る。
\return none いいえ返します。
\param ssl wolfssl_newで作成されたSSLセッションへのポインタ。
_Example_
\code
int sockfd;
WOLFSSL* ssl = 0;
...
// Manually setting the socket fd as the receive CTX, for example
wolfSSL_SetIOReadCtx(ssl, &sockfd);
...
\endcode
\sa wolfSSL_CTX_SetIORecv
\sa wolfSSL_CTX_SetIOSend
\sa wolfSSL_SetIOWriteCtx
*/
void wolfSSL_SetIOReadCtx( WOLFSSL* ssl, void *ctx);
/*!
\brief コールバック関数デフォルトでは、WolfSSLは、WolfSSLがシステムのTCPライブラリを使用している場合、wolfssl_set_fdに渡されたファイル記述子をコンテキストとして設定します。独自の送信コールバックを登録した場合は、セッションの特定のコンテキストを設定することができます。たとえば、メモリバッファを使用している場合、コンテキストは、メモリバッファーのどこにありかを説明する構造へのポインタであり得る。
\return none いいえ返します。
\param ssl wolfssl_newで作成されたSSLセッションへのポインタ。
_Example_
\code
int sockfd;
WOLFSSL* ssl = 0;
...
// Manually setting the socket fd as the send CTX, for example
wolfSSL_SetIOWriteCtx(ssl, &sockfd);
...
\endcode
\sa wolfSSL_CTX_SetIORecv
\sa wolfSSL_CTX_SetIOSend
\sa wolfSSL_SetIOReadCtx
*/
void wolfSSL_SetIOWriteCtx(WOLFSSL* ssl, void *ctx);
/*!
\ingroup IO
\brief この関数は、WolfSSL構造体のIOCB_READCTXメンバーを返します。
\return pointer この関数は、wolfssl構造体のiocb_readctxメンバーへのvoidポインタを返します。
\return NULL wolfssl構造体がNULLの場合に返されます。
_Example_
\code
WOLFSSL* ssl = wolfSSL_new(ctx);
void* ioRead;
...
ioRead = wolfSSL_GetIOReadCtx(ssl);
if(ioRead == NULL){
// Failure case. The ssl object was NULL.
}
\endcode
\sa wolfSSL_GetIOWriteCtx
\sa wolfSSL_SetIOReadFlags
\sa wolfSSL_SetIOWriteCtx
\sa wolfSSL_SetIOReadCtx
\sa wolfSSL_CTX_SetIOSend
*/
void* wolfSSL_GetIOReadCtx( WOLFSSL* ssl);
/*!
\ingroup IO
\brief この関数は、WolfSSL構造のIOCB_WRITECTXメンバーを返します。
\return pointer この関数は、WolfSSL構造のIOCB_WRITECTXメンバーへのvoidポインタを返します。
\return NULL wolfssl構造体がNULLの場合に返されます。
_Example_
\code
WOLFSSL* ssl;
void* ioWrite;
...
ioWrite = wolfSSL_GetIOWriteCtx(ssl);
if(ioWrite == NULL){
// The function returned NULL.
}
\endcode
\sa wolfSSL_GetIOReadCtx
\sa wolfSSL_SetIOWriteCtx
\sa wolfSSL_SetIOReadCtx
\sa wolfSSL_CTX_SetIOSend
*/
void* wolfSSL_GetIOWriteCtx(WOLFSSL* ssl);
/*!
\brief 与えられたSSLセッション受信コールバックは、デフォルトのwolfssl埋め込み受信コールバック、またはユーザによって指定されたカスタムコールバックであり得るwolfssl_ctx_setiorecvを参照。デフォルトのフラグ値は、WolfSSLによってwolfsslによって0の値に設定されます。デフォルトのWolfSSL受信コールバックはRECV関数を使用してソケットからデータを受信します。 「Recv」ページから「Recv関数へのflags引数は、1つ以上の値をOR処理するか、MSG_OOBプロセス帯域外データ、MSG_PEEK PEEK、MSG_PEEK PEEK、MSG_WAITALLがフルを待っています要求またはエラー。 MSG_OOBフラグは、通常のデータストリームで受信されないであろう帯域外データの受信を要求します。一部のプロトコルは通常のデータキューの先頭に迅速なデータを配置し、このフラグをそのようなプロトコルで使用することはできません。 MSG_PEEKフラグは、受信操作によって受信キューの先頭からのデータをキューから削除することなくデータを返します。したがって、以降の受信呼び出しは同じデータを返します。 MSG_WAITALLフラグは、完全な要求が満たされるまで操作ブロックを要求します。ただし、信号がキャッチされている場合は、呼び出し側よりも少ないデータが少なく、エラーまたは切断が発生するか、または受信されるデータが返されるものとは異なるタイプのデータを返します。
\return none いいえ返します。
\param ssl wolfssl_newで作成されたSSLセッションへのポインタ。
_Example_
\code
WOLFSSL* ssl = 0;
...
// Manually setting recv flags to 0
wolfSSL_SetIOReadFlags(ssl, 0);
...
\endcode
\sa wolfSSL_CTX_SetIORecv
\sa wolfSSL_CTX_SetIOSend
\sa wolfSSL_SetIOReadCtx
*/
void wolfSSL_SetIOReadFlags( WOLFSSL* ssl, int flags);
/*!
\brief SSLセッションを考えると送信コールバックは、デフォルトのWolfSSL EmbedEndコールバック、またはユーザーによって指定されたカスタムコールバックのいずれかですWolfSSL_CTX_SetiosEndを参照。デフォルトのフラグ値は、wolfsslによって0の値に設定されます。デフォルトのWolfSSL Send Callbackはsend関数を使用してソケットからデータを送信します。sendmanページから "flagsパラメータには、次のうち1つ以上が含まれていてもよい。フラグMSG_OOBは、この概念例えばSOCK_STREAMをサポートするソケットに「帯域外」データを送信するために使用される。基礎となるプロトコルは、「帯域外」のデータもサポートする必要があります。MSG_DONTROUTEは通常、診断プログラムまたはルーティングプログラムによってのみ使用されます。」
\return none いいえ返します。
\param ssl wolfssl_newで作成されたSSLセッションへのポインタ。
_Example_
\code
WOLFSSL* ssl = 0;
...
// Manually setting send flags to 0
wolfSSL_SetIOWriteFlags(ssl, 0);
...
\endcode
\sa wolfSSL_CTX_SetIORecv
\sa wolfSSL_CTX_SetIOSend
\sa wolfSSL_SetIOReadCtx
*/
void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags);
/*!
\ingroup IO
\brief この関数は、wolfssl構造内のnxctx構造体のNxSocketメンバーとNXWAITメンバーを設定します。
\return none いいえ返します。
\param ssl wolfssl_newを使用して作成されたWolfSSL構造へのポインタ。
\param nxSocket NXCTX構造のNXSOCTOCKメンバーに設定されているNX_TCP_SOCKETを入力するためのポインタ。
_Example_
\code
WOLFSSL* ssl = wolfSSL_new(ctx);
NX_TCP_SOCKET* nxSocket;
ULONG waitOption;
if(ssl != NULL || nxSocket != NULL || waitOption <= 0){
wolfSSL_SetIO_NetX(ssl, nxSocket, waitOption);
} else {
// You need to pass in good parameters.
}
\endcode
\sa set_fd
\sa NetX_Send
\sa NetX_Receive
*/
void wolfSSL_SetIO_NetX(WOLFSSL* ssl, NX_TCP_SOCKET* nxsocket,
ULONG waitoption);
/*!
\brief wolfssl_ctx構造CallBackGencookie Typeは関数ポインタで、署名int* callbackgencookiewolfssl * ssl、unsigned char * buf、int sz、void * ctxを持っています。
\return none いいえ返します。
\param ssl wolfssl_newを使用して作成されたWolfSSL構造へのポインタ。
_Example_
\code
WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
WOLFSSL* ssl = wolfSSL_new(ctx);
int SetGenCookieCB(WOLFSSL* ssl, unsigned char* buf, int sz, void* ctx){
// Callback function body.
}
wolfSSL_CTX_SetGenCookie(ssl->ctx, SetGenCookieCB);
\endcode
\sa CallbackGenCookie
*/
void wolfSSL_CTX_SetGenCookie(WOLFSSL_CTX* ctx, CallbackGenCookie cb);
/*!
\ingroup Setup
\brief この関数は、WolfSSL構造のIOCB_COOKIECTXメンバーを返します。
\return pointer この関数は、iocb_cookiectxに格納されているvoidポインタ値を返します。
\return NULL WolfSSL構造体がNULLの場合
_Example_
\code
WOLFSSL_CTX* ctx = wolfSSL_CTX_new( method );
WOLFSSL* ssl = wolfSSL_new(ctx);
void* cookie;
...
cookie = wolfSSL_GetCookieCtx(ssl);
if(cookie != NULL){
// You have the cookie
}
\endcode
\sa wolfSSL_SetCookieCtx
\sa wolfSSL_CTX_SetGenCookie
*/
void* wolfSSL_GetCookieCtx(WOLFSSL* ssl);
/*!
\ingroup Setup
\brief この関数は、WolfSSLがWolfSSL_ISOTPでコンパイルされている場合に使用する場合は、WolfSSLの場合はISO-TPコンテキストを設定します。
\return 0 成功すると、故障のwolfssl_cbio_err_general
\param ssl wolfsslコンテキスト
\param ctx ユーザーはこの関数が初期化されるISOTPコンテキストを作成しました
\param recv_fn ユーザーはバスを受信できます
\param send_fn ユーザーはバスを送ることができます
\param delay_fn ユーザーマイクロ秒の粒度遅延関数
\param receive_delay 各CANバスパケットを遅らせるためのマイクロ秒のセット数
\param receive_buffer ユーザーがデータを受信するためのバッファーが提供され、ISOTP_DEFAULT_BUFFER_SIZEバイトに割り当てられていることをお勧めします。
\param receive_buffer_size - receive_bufferのサイズ
_Example_
\code
struct can_info can_con_info;
isotp_wolfssl_ctx isotp_ctx;
char *receive_buffer = malloc(ISOTP_DEFAULT_BUFFER_SIZE);
WOLFSSL_CTX* ctx = wolfSSL_CTX_new(method);
WOLFSSL* ssl = wolfSSL_new(ctx);
...
wolfSSL_SetIO_ISOTP(ssl, &isotp_ctx, can_receive, can_send, can_delay, 0,
receive_buffer, ISOTP_DEFAULT_BUFFER_SIZE, &can_con_info);
\endcode
*/
int wolfSSL_SetIO_ISOTP(WOLFSSL *ssl, isotp_wolfssl_ctx *ctx,
can_recv_fn recv_fn, can_send_fn send_fn, can_delay_fn delay_fn,
word32 receive_delay, char *receive_buffer, int receive_buffer_size,
void *arg);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
/*!
\ingroup ARC4
\brief This function encrypts an input message from the buffer in, placing
the ciphertext in the output buffer out, or decrypts a ciphertext from the
buffer in, placing the plaintext in the output buffer out, using ARC4
encryption. This function is used for both encryption and decryption.
Before this method may be called, one must first initialize the ARC4
structure using wc_Arc4SetKey.
\return none
\param arc4 pointer to the ARC4 structure used to process the message
\param out pointer to the output buffer in which to store the
processed message
\param in pointer to the input buffer containing the message to process
\param length length of the message to process
_Example_
\code
Arc4 enc;
byte key[] = { key to use for encryption };
wc_Arc4SetKey(&enc, key, sizeof(key));
byte plain[] = { plain text to encode };
byte cipher[sizeof(plain)];
byte decrypted[sizeof(plain)];
// encrypt the plain into cipher
wc_Arc4Process(&enc, cipher, plain, sizeof(plain));
// decrypt the cipher
wc_Arc4Process(&enc, decrypted, cipher, sizeof(cipher));
\endcode
\sa wc_Arc4SetKey
*/
int wc_Arc4Process(Arc4* arc4, byte* out, const byte* in, word32 length);
/*!
\ingroup ARC4
\brief This function sets the key for a ARC4 object, initializing it for
use as a cipher. It should be called before using it for encryption
with wc_Arc4Process.
\return none
\param arc4 pointer to an arc4 structure to be used for encryption
\param key key with which to initialize the arc4 structure
\param length length of the key used to initialize the arc4 structure
_Example_
\code
Arc4 enc;
byte key[] = { initialize with key to use for encryption };
wc_Arc4SetKey(&enc, key, sizeof(key));
\endcode
\sa wc_Arc4Process
*/
int wc_Arc4SetKey(Arc4* arc4, const byte* key, word32 length);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,95 @@
/*!
\ingroup BLAKE2
\brief This function initializes a Blake2b structure for use with the
Blake2 hash function.
\return 0 Returned upon successfully initializing the Blake2b structure and
setting the digest size.
\param b2b pointer to the Blake2b structure to initialize
\param digestSz length of the blake 2 digest to implement
_Example_
\code
Blake2b b2b;
// initialize Blake2b structure with 64 byte digest
wc_InitBlake2b(&b2b, 64);
\endcode
\sa wc_Blake2bUpdate
*/
int wc_InitBlake2b(Blake2b* b2b, word32 digestSz);
/*!
\ingroup BLAKE2
\brief This function updates the Blake2b hash with the given input data.
This function should be called after wc_InitBlake2b, and repeated until
one is ready for the final hash: wc_Blake2bFinal.
\return 0 Returned upon successfully update the Blake2b structure with
the given data
\return -1 Returned if there is a failure while compressing the input data
\param b2b pointer to the Blake2b structure to update
\param data pointer to a buffer containing the data to append
\param sz length of the input data to append
_Example_
\code
int ret;
Blake2b b2b;
// initialize Blake2b structure with 64 byte digest
wc_InitBlake2b(&b2b, 64);
byte plain[] = { // initialize input };
ret = wc_Blake2bUpdate(&b2b, plain, sizeof(plain));
if( ret != 0) {
// error updating blake2b
}
\endcode
\sa wc_InitBlake2b
\sa wc_Blake2bFinal
*/
int wc_Blake2bUpdate(Blake2b* b2b, const byte* data, word32 sz);
/*!
\ingroup BLAKE2
\brief This function computes the Blake2b hash of the previously supplied
input data. The output hash will be of length requestSz, or, if
requestSz==0, the digestSz of the b2b structure. This function should be
called after wc_InitBlake2b and wc_Blake2bUpdate has been processed for
each piece of input data desired.
\return 0 Returned upon successfully computing the Blake2b hash
\return -1 Returned if there is a failure while parsing the Blake2b hash
\param b2b pointer to the Blake2b structure to update
\param final pointer to a buffer in which to store the blake2b hash.
Should be of length requestSz
\param requestSz length of the digest to compute. When this is zero,
b2b->digestSz will be used instead
_Example_
\code
int ret;
Blake2b b2b;
byte hash[64];
// initialize Blake2b structure with 64 byte digest
wc_InitBlake2b(&b2b, 64);
... // call wc_Blake2bUpdate to add data to hash
ret = wc_Blake2bFinal(&b2b, hash, 64);
if( ret != 0) {
// error generating blake2b hash
}
\endcode
\sa wc_InitBlake2b
\sa wc_Blake2bUpdate
*/
int wc_Blake2bFinal(Blake2b* b2b, byte* final, word32 requestSz);

View File

@@ -0,0 +1,28 @@
/*!
\ingroup openSSL
\brief This function performs the following math “r = (a^p) % m”.
\return SSL_SUCCESS On successfully performing math operation.
\return SSL_FAILURE If an error case was encountered.
\param r structure to hold result.
\param a value to be raised by a power.
\param p power to raise a by.
\param m modulus to use.
\param ctx currently not used with wolfSSL can be NULL.
_Example_
\code
WOLFSSL_BIGNUM r,a,p,m;
int ret;
// set big number values
ret = wolfSSL_BN_mod_exp(r, a, p, m, NULL);
// check ret value
\endcode
\sa wolfSSL_BN_new
\sa wolfSSL_BN_free
*/
int wolfSSL_BN_mod_exp(WOLFSSL_BIGNUM *r, const WOLFSSL_BIGNUM *a,
const WOLFSSL_BIGNUM *p, const WOLFSSL_BIGNUM *m, WOLFSSL_BN_CTX *ctx);

View File

@@ -0,0 +1,184 @@
/*!
\ingroup Camellia
\brief This function sets the key and initialization vector for a
camellia object, initializing it for use as a cipher.
\return 0 Returned upon successfully setting the key and initialization
vector
\return BAD_FUNC_ARG returned if there is an error processing one of
the input arguments
\return MEMORY_E returned if there is an error allocating memory with
XMALLOC
\param cam pointer to the camellia structure on which to set the key and iv
\param key pointer to the buffer containing the 16, 24, or 32 byte key
to use for encryption and decryption
\param len length of the key passed in
\param iv pointer to the buffer containing the 16 byte initialization
vector for use with this camellia structure
_Example_
\code
Camellia cam;
byte key[32];
// initialize key
byte iv[16];
// initialize iv
if( wc_CamelliaSetKey(&cam, key, sizeof(key), iv) != 0) {
// error initializing camellia structure
}
\endcode
\sa wc_CamelliaEncryptDirect
\sa wc_CamelliaDecryptDirect
\sa wc_CamelliaCbcEncrypt
\sa wc_CamelliaCbcDecrypt
*/
int wc_CamelliaSetKey(Camellia* cam,
const byte* key, word32 len, const byte* iv);
/*!
\ingroup Camellia
\brief This function sets the initialization vector for a camellia object.
\return 0 Returned upon successfully setting the key and initialization
vector
\return BAD_FUNC_ARG returned if there is an error processing one of the
input arguments
\param cam pointer to the camellia structure on which to set the iv
\param iv pointer to the buffer containing the 16 byte initialization
vector for use with this camellia structure
_Example_
\code
Camellia cam;
byte iv[16];
// initialize iv
if( wc_CamelliaSetIV(&cam, iv) != 0) {
// error initializing camellia structure
}
\endcode
\sa wc_CamelliaSetKey
*/
int wc_CamelliaSetIV(Camellia* cam, const byte* iv);
/*!
\ingroup Camellia
\brief This function does a one-block encrypt using the provided camellia
object. It parses the first 16 byte block from the buffer in and stores
the encrypted result in the buffer out. Before using this function, one
should initialize the camellia object using wc_CamelliaSetKey.
\return none No returns.
\param cam pointer to the camellia structure to use for encryption
\param out pointer to the buffer in which to store the encrypted block
\param in pointer to the buffer containing the plaintext block to encrypt
_Example_
\code
Camellia cam;
// initialize cam structure with key and iv
byte plain[] = { // initialize with message to encrypt };
byte cipher[16];
wc_CamelliaEncryptDirect(&ca, cipher, plain);
\endcode
\sa wc_CamelliaDecryptDirect
*/
int wc_CamelliaEncryptDirect(Camellia* cam, byte* out,
const byte* in);
/*!
\ingroup Camellia
\brief This function does a one-block decrypt using the provided camellia
object. It parses the first 16 byte block from the buffer in, decrypts it,
and stores the result in the buffer out. Before using this function, one
should initialize the camellia object using wc_CamelliaSetKey.
\return none No returns.
\param cam pointer to the camellia structure to use for encryption
\param out pointer to the buffer in which to store the decrypted
plaintext block
\param in pointer to the buffer containing the ciphertext block to decrypt
_Example_
\code
Camellia cam;
// initialize cam structure with key and iv
byte cipher[] = { // initialize with encrypted message to decrypt };
byte decrypted[16];
wc_CamelliaDecryptDirect(&cam, decrypted, cipher);
\endcode
\sa wc_CamelliaEncryptDirect
*/
int wc_CamelliaDecryptDirect(Camellia* cam, byte* out,
const byte* in);
/*!
\ingroup Camellia
\brief This function encrypts the plaintext from the buffer in and
stores the output in the buffer out. It performs this encryption
using Camellia with Cipher Block Chaining (CBC).
\return none No returns.
\param cam pointer to the camellia structure to use for encryption
\param out pointer to the buffer in which to store the encrypted ciphertext
\param in pointer to the buffer containing the plaintext to encrypt
\param sz the size of the message to encrypt
_Example_
\code
Camellia cam;
// initialize cam structure with key and iv
byte plain[] = { // initialize with encrypted message to decrypt };
byte cipher[sizeof(plain)];
wc_CamelliaCbcEncrypt(&cam, cipher, plain, sizeof(plain));
\endcode
\sa wc_CamelliaCbcDecrypt
*/
int wc_CamelliaCbcEncrypt(Camellia* cam,
byte* out, const byte* in, word32 sz);
/*!
\ingroup Camellia
\brief This function decrypts the ciphertext from the buffer in and
stores the output in the buffer out. It performs this decryption using
Camellia with Cipher Block Chaining (CBC).
\return none No returns.
\param cam pointer to the camellia structure to use for encryption
\param out pointer to the buffer in which to store the decrypted message
\param in pointer to the buffer containing the encrypted ciphertext
\param sz the size of the message to encrypt
_Example_
\code
Camellia cam;
// initialize cam structure with key and iv
byte cipher[] = { // initialize with encrypted message to decrypt };
byte decrypted[sizeof(cipher)];
wc_CamelliaCbcDecrypt(&cam, decrypted, cipher, sizeof(cipher));
\endcode
\sa wc_CamelliaCbcEncrypt
*/
int wc_CamelliaCbcDecrypt(Camellia* cam,
byte* out, const byte* in, word32 sz);

View File

@@ -0,0 +1,99 @@
/*!
\ingroup ChaCha
\brief This function sets the initialization vector (nonce) for a ChaCha
object, initializing it for use as a cipher. It should be called after the
key has been set, using wc_Chacha_SetKey. A difference nonce should be
used for each round of encryption.
\return 0 Returned upon successfully setting the initialization vector
\return BAD_FUNC_ARG returned if there is an error processing the ctx
input argument
\param ctx pointer to the ChaCha structure on which to set the iv
\param inIv pointer to a buffer containing the 12 byte initialization
vector with which to initialize the ChaCha structure
\param counter the value at which the block counter should start--usually
zero.
_Example_
\code
ChaCha enc;
// initialize enc with wc_Chacha_SetKey
byte iv[12];
// initialize iv
if( wc_Chacha_SetIV(&enc, iv, 0) != 0) {
// error initializing ChaCha structure
}
\endcode
\sa wc_Chacha_SetKey
\sa wc_Chacha_Process
*/
int wc_Chacha_SetIV(ChaCha* ctx, const byte* inIv, word32 counter);
/*!
\ingroup ChaCha
\brief This function processes the text from the buffer input, encrypts
or decrypts it, and stores the result in the buffer output.
\return 0 Returned upon successfully encrypting or decrypting the input
\return BAD_FUNC_ARG returned if there is an error processing the ctx
input argument
\param ctx pointer to the ChaCha structure on which to set the iv
\param output pointer to a buffer in which to store the output ciphertext
or decrypted plaintext
\param input pointer to the buffer containing the input plaintext to
encrypt or the input ciphertext to decrypt
\param msglen length of the message to encrypt or the ciphertext to decrypt
_Example_
\code
ChaCha enc;
// initialize enc with wc_Chacha_SetKey and wc_Chacha_SetIV
byte plain[] = { // initialize plaintext };
byte cipher[sizeof(plain)];
if( wc_Chacha_Process(&enc, cipher, plain, sizeof(plain)) != 0) {
// error processing ChaCha cipher
}
\endcode
\sa wc_Chacha_SetKey
\sa wc_Chacha_Process
*/
int wc_Chacha_Process(ChaCha* ctx, byte* cipher, const byte* plain,
word32 msglen);
/*!
\ingroup ChaCha
\brief This function sets the key for a ChaCha object, initializing it for
use as a cipher. It should be called before setting the nonce with
wc_Chacha_SetIV, and before using it for encryption with wc_Chacha_Process.
\return 0 Returned upon successfully setting the key
\return BAD_FUNC_ARG returned if there is an error processing the ctx
input argument or if the key is not 16 or 32 bytes long
\param ctx pointer to the ChaCha structure in which to set the key
\param key pointer to a buffer containing the 16 or 32 byte key with
which to initialize the ChaCha structure
\param keySz the length of the key passed in
_Example_
\code
ChaCha enc;
byte key[] = { // initialize key };
if( wc_Chacha_SetKey(&enc, key, sizeof(key)) != 0) {
// error initializing ChaCha structure
}
\endcode
\sa wc_Chacha_SetIV
\sa wc_Chacha_Process
*/
int wc_Chacha_SetKey(ChaCha* ctx, const byte* key, word32 keySz);

View File

@@ -0,0 +1,120 @@
/*!
\ingroup ChaCha20Poly1305
\brief This function encrypts an input message, inPlaintext, using the
ChaCha20 stream cipher, into the output buffer, outCiphertext. It
also performs Poly-1305 authentication (on the cipher text), and
stores the generated authentication tag in the output buffer, outAuthTag.
\return 0 Returned upon successfully encrypting the message
\return BAD_FUNC_ARG returned if there is an error during the encryption
process
\param inKey pointer to a buffer containing the 32 byte key to use
for encryption
\param inIv pointer to a buffer containing the 12 byte iv to use for
encryption
\param inAAD pointer to the buffer containing arbitrary length additional
authenticated data (AAD)
\param inAADLen length of the input AAD
\param inPlaintext pointer to the buffer containing the plaintext to
encrypt
\param inPlaintextLen the length of the plain text to encrypt
\param outCiphertext pointer to the buffer in which to store the ciphertext
\param outAuthTag pointer to a 16 byte wide buffer in which to store the
authentication tag
_Example_
\code
byte key[] = { // initialize 32 byte key };
byte iv[] = { // initialize 12 byte key };
byte inAAD[] = { // initialize AAD };
byte plain[] = { // initialize message to encrypt };
byte cipher[sizeof(plain)];
byte authTag[16];
int ret = wc_ChaCha20Poly1305_Encrypt(key, iv, inAAD, sizeof(inAAD),
plain, sizeof(plain), cipher, authTag);
if(ret != 0) {
// error running encrypt
}
\endcode
\sa wc_ChaCha20Poly1305_Decrypt
\sa wc_ChaCha_*
\sa wc_Poly1305*
*/
int wc_ChaCha20Poly1305_Encrypt(
const byte inKey[CHACHA20_POLY1305_AEAD_KEYSIZE],
const byte inIV[CHACHA20_POLY1305_AEAD_IV_SIZE],
const byte* inAAD, const word32 inAADLen,
const byte* inPlaintext, const word32 inPlaintextLen,
byte* outCiphertext,
byte outAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE]);
/*!
\ingroup ChaCha20Poly1305
\brief This function decrypts input ciphertext, inCiphertext, using the
ChaCha20 stream cipher, into the output buffer, outPlaintext. It also
performs Poly-1305 authentication, comparing the given inAuthTag to an
authentication generated with the inAAD (arbitrary length additional
authentication data). Note: If the generated authentication tag does
not match the supplied authentication tag, the text is not decrypted.
\return 0 Returned upon successfully decrypting the message
\return BAD_FUNC_ARG Returned if any of the function arguments do not
match what is expected
\return MAC_CMP_FAILED_E Returned if the generated authentication tag
does not match the supplied inAuthTag.
\param inKey pointer to a buffer containing the 32 byte key to use for
decryption
\param inIv pointer to a buffer containing the 12 byte iv to use for
decryption
\param inAAD pointer to the buffer containing arbitrary length additional
authenticated data (AAD)
\param inAADLen length of the input AAD
\param inCiphertext pointer to the buffer containing the ciphertext to
decrypt
\param outCiphertextLen the length of the ciphertext to decrypt
\param inAuthTag pointer to the buffer containing the 16 byte digest
for authentication
\param outPlaintext pointer to the buffer in which to store the plaintext
_Example_
\code
byte key[] = { // initialize 32 byte key };
byte iv[] = { // initialize 12 byte key };
byte inAAD[] = { // initialize AAD };
byte cipher[] = { // initialize with received ciphertext };
byte authTag[16] = { // initialize with received authentication tag };
byte plain[sizeof(cipher)];
int ret = wc_ChaCha20Poly1305_Decrypt(key, iv, inAAD, sizeof(inAAD),
cipher, sizeof(cipher), plain, authTag);
if(ret == MAC_CMP_FAILED_E) {
// error during authentication
} else if( ret != 0) {
// error with function arguments
}
\endcode
\sa wc_ChaCha20Poly1305_Encrypt
\sa wc_ChaCha_*
\sa wc_Poly1305*
*/
int wc_ChaCha20Poly1305_Decrypt(
const byte inKey[CHACHA20_POLY1305_AEAD_KEYSIZE],
const byte inIV[CHACHA20_POLY1305_AEAD_IV_SIZE],
const byte* inAAD, const word32 inAADLen,
const byte* inCiphertext, const word32 inCiphertextLen,
const byte inAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE],
byte* outPlaintext);

View File

@@ -0,0 +1,158 @@
/*!
\ingroup CMAC
\brief Initialize the Cmac structure with defaults
\return 0 on success
\param cmac pointer to the Cmac structure
\param key key pointer
\param keySz size of the key pointer (16, 24 or 32)
\param type Always WC_CMAC_AES = 1
\param unused not used, exists for potential future use around compatiblity
_Example_
\code
Cmac cmac[1];
ret = wc_InitCmac(cmac, key, keySz, WC_CMAC_AES, NULL);
if (ret == 0) {
ret = wc_CmacUpdate(cmac, in, inSz);
}
if (ret == 0) {
ret = wc_CmacFinal(cmac, out, outSz);
}
\endcode
\sa wc_InitCmac_ex
\sa wc_CmacUpdate
\sa wc_CmacFinal
*/
int wc_InitCmac(Cmac* cmac,
const byte* key, word32 keySz,
int type, void* unused);
/*!
\ingroup CMAC
\brief Initialize the Cmac structure with defaults
\return 0 on success
\param cmac pointer to the Cmac structure
\param key key pointer
\param keySz size of the key pointer (16, 24 or 32)
\param type Always WC_CMAC_AES = 1
\param unused not used, exists for potential future use around compatiblity
\param heap pointer to the heap hint used for dynamic allocation. Typically used with our static memory option. Can be NULL.
\param devId ID to use with async hardware. Set to INVALID_DEVID if not using async hardware.
_Example_
\code
Cmac cmac[1];
ret = wc_InitCmac_ex(cmac, key, keySz, WC_CMAC_AES, NULL, NULL, INVALID_DEVID);
if (ret == 0) {
ret = wc_CmacUpdate(cmac, in, inSz);
}
if (ret == 0) {
ret = wc_CmacFinal(cmac, out, &outSz);
}
\endcode
\sa wc_InitCmac_ex
\sa wc_CmacUpdate
\sa wc_CmacFinal
*/
int wc_InitCmac_ex(Cmac* cmac,
const byte* key, word32 keySz,
int type, void* unused, void* heap, int devId);
/*!
\ingroup CMAC
\brief Add Cipher-based Message Authentication Code input data
\return 0 on success
\param cmac pointer to the Cmac structure
\param in input data to process
\param inSz size of input data
_Example_
\code
ret = wc_CmacUpdate(cmac, in, inSz);
\endcode
\sa wc_InitCmac
\sa wc_CmacFinal
*/
int wc_CmacUpdate(Cmac* cmac,
const byte* in, word32 inSz);
/*!
\ingroup CMAC
\brief Generate the final result using Cipher-based Message Authentication Code
\return 0 on success
\param cmac pointer to the Cmac structure
\param out pointer to return the result
\param outSz pointer size of output (in/out)
_Example_
\code
ret = wc_CmacFinal(cmac, out, &outSz);
\endcode
\sa wc_InitCmac
\sa wc_CmacFinal
*/
int wc_CmacFinal(Cmac* cmac,
byte* out, word32* outSz);
/*!
\ingroup CMAC
\brief Single shot fuction for generating a CMAC
\return 0 on success
\param out pointer to return the result
\param outSz pointer size of output (in/out)
\param in input data to process
\param inSz size of input data
\param key key pointer
\param keySz size of the key pointer (16, 24 or 32)
_Example_
\code
ret = wc_AesCmacGenerate(mac, &macSz, msg, msgSz, key, keySz);
\endcode
\sa wc_AesCmacVerify
*/
int wc_AesCmacGenerate(byte* out, word32* outSz,
const byte* in, word32 inSz,
const byte* key, word32 keySz);
/*!
\ingroup CMAC
\brief Single shot fuction for validating a CMAC
\return 0 on success
\param check pointer to return the result
\param checkSz size of checkout buffer
\param in input data to process
\param inSz size of input data
\param key key pointer
\param keySz size of the key pointer (16, 24 or 32)
_Example_
\code
ret = wc_AesCmacVerify(mac, macSz, msg, msgSz, key, keySz);
\endcode
\sa wc_AesCmacGenerate
*/
int wc_AesCmacVerify(const byte* check, word32 checkSz,
const byte* in, word32 inSz,
const byte* key, word32 keySz);
/*!
\ingroup CMAC
\brief Only used with WOLFSSL_HASH_KEEP when hardware requires single-shot and the updates must be cached in memory
\return 0 on success
\param in input data to process
\param inSz size of input data
_Example_
\code
ret = wc_CMAC_Grow(cmac, in, inSz)
\endcode
*/
int wc_CMAC_Grow(Cmac* cmac, const byte* in, int inSz);

View File

@@ -0,0 +1,233 @@
/*!
\ingroup Base_Encoding
\brief This function decodes the given Base64 encoded input, in, and
stores the result in the output buffer out. It also sets the size
written to the output buffer in the variable outLen.
\return 0 Returned upon successfully decoding the Base64 encoded input
\return BAD_FUNC_ARG Returned if the output buffer is too small to
store the decoded input
\return ASN_INPUT_E Returned if a character in the input buffer falls
outside of the Base64 range ([A-Za-z0-9+/=]) or if there is an invalid
line ending in the Base64 encoded input
\param in pointer to the input buffer to decode
\param inLen length of the input buffer to decode
\param out pointer to the output buffer in which to store the decoded
message
\param outLen pointer to the length of the output buffer. Updated with
the bytes written at the end of the function call
_Example_
\code
byte encoded[] = { // initialize text to decode };
byte decoded[sizeof(encoded)];
// requires at least (sizeof(encoded) * 3 + 3) / 4 room
int outLen = sizeof(decoded);
if( Base64_Decode(encoded,sizeof(encoded), decoded, &outLen) != 0 ) {
// error decoding input buffer
}
\endcode
\sa Base64_Encode
\sa Base16_Decode
*/
int Base64_Decode(const byte* in, word32 inLen, byte* out,
word32* outLen);
/*!
\ingroup Base_Encoding
\brief This function encodes the given input, in, and stores the Base64
encoded result in the output buffer out. It writes the data with the
traditional \n line endings, instead of escaped %0A line endings. Upon
successfully completing, this function also sets outLen to the number
of bytes written to the output buffer.
\return 0 Returned upon successfully decoding the Base64 encoded input
\return BAD_FUNC_ARG Returned if the output buffer is too small to
store the encoded input
\return BUFFER_E Returned if the output buffer runs out of room
while encoding
\param in pointer to the input buffer to encode
\param inLen length of the input buffer to encode
\param out pointer to the output buffer in which to store the
encoded message
\param outLen pointer to the length of the output buffer in
which to store the encoded message
_Example_
\code
byte plain[] = { // initialize text to encode };
byte encoded[MAX_BUFFER_SIZE];
int outLen = sizeof(encoded);
if( Base64_Encode(plain, sizeof(plain), encoded, &outLen) != 0 ) {
// error encoding input buffer
}
\endcode
\sa Base64_EncodeEsc
\sa Base64_Decode
*/
int Base64_Encode(const byte* in, word32 inLen, byte* out,
word32* outLen);
/*!
\ingroup Base_Encoding
\brief This function encodes the given input, in, and stores the
Base64 encoded result in the output buffer out. It writes the data
with %0A escaped line endings instead of \n line endings.
Upon successfully completing, this function also sets outLen
to the number of bytes written to the output buffer.
\return 0 Returned upon successfully decoding the Base64 encoded input
\return BAD_FUNC_ARG Returned if the output buffer is too small
to store the encoded input
\return BUFFER_E Returned if the output buffer runs out of
room while encoding
\return ASN_INPUT_E Returned if there is an error processing
the decode on the input message
\param in pointer to the input buffer to encode
\param inLen length of the input buffer to encode
\param out pointer to the output buffer in which to store
the encoded message
\param outLen pointer to the length of the output buffer in
which to store the encoded message
_Example_
\code
byte plain[] = { // initialize text to encode };
byte encoded[MAX_BUFFER_SIZE];
int outLen = sizeof(encoded);
if( Base64_EncodeEsc(plain, sizeof(plain), encoded, &outLen) != 0 ) {
// error encoding input buffer
}
\endcode
\sa Base64_Encode
\sa Base64_Decode
*/
int Base64_EncodeEsc(const byte* in, word32 inLen, byte* out,
word32* outLen);
/*!
\ingroup Base_Encoding
\brief This function encodes the given input, in, and stores the
Base64 encoded result in the output buffer out. It writes the data
with no new lines. Upon successfully completing, this function
also sets outLen to the number of bytes written to the output buffer
\return 0 Returned upon successfully decoding the Base64 encoded input
\return BAD_FUNC_ARG Returned if the output buffer is too small
to store the encoded input
\return BUFFER_E Returned if the output buffer runs out of room
while encoding
\return ASN_INPUT_E Returned if there is an error processing the
decode on the input message
\param in pointer to the input buffer to encode
\param inLen length of the input buffer to encode
\param out pointer to the output buffer in which to store the
encoded message
\param outLen pointer to the length of the output buffer in which to
store the encoded message
_Example_
\code
byte plain[] = { // initialize text to encode };
byte encoded[MAX_BUFFER_SIZE];
int outLen = sizeof(encoded);
if( Base64_Encode_NoNl(plain, sizeof(plain), encoded, &outLen) != 0 ) {
// error encoding input buffer
}
\endcode
\sa Base64_Encode
\sa Base64_Decode
*/
int Base64_Encode_NoNl(const byte* in, word32 inLen, byte* out,
word32* outLen);
/*!
\ingroup Base_Encoding
\brief This function decodes the given Base16 encoded input, in, and
stores the result in the output buffer out. It also sets the size written
to the output buffer in the variable outLen.
\return 0 Returned upon successfully decoding the Base16 encoded input
\return BAD_FUNC_ARG Returned if the output buffer is too small to store
the decoded input or if the input length is not a multiple of two
\return ASN_INPUT_E Returned if a character in the input buffer falls
outside of the Base16 range ([0-9A-F])
\param in pointer to the input buffer to decode
\param inLen length of the input buffer to decode
\param out pointer to the output buffer in which to store the decoded
message
\param outLen pointer to the length of the output buffer. Updated with the
bytes written at the end of the function call
_Example_
\code
byte encoded[] = { // initialize text to decode };
byte decoded[sizeof(encoded)];
int outLen = sizeof(decoded);
if( Base16_Decode(encoded,sizeof(encoded), decoded, &outLen) != 0 ) {
// error decoding input buffer
}
\endcode
\sa Base64_Encode
\sa Base64_Decode
\sa Base16_Encode
*/
int Base16_Decode(const byte* in, word32 inLen, byte* out, word32* outLen);
/*!
\ingroup Base_Encoding
\brief Encode input to base16 output.
\return 0 Success
\return BAD_FUNC_ARG Returns if in, out, or outLen is null or if outLen is
less than 2 times inLen plus 1.
\param in Pointer to input buffer to be encoded.
\param inLen Length of input buffer.
\param out Pointer to output buffer.
\param outLen Length of output buffer. Is set to len of encoded output.
_Example_
\code
byte in[] = { // Contents of something to be encoded };
byte out[NECESSARY_OUTPUT_SIZE];
word32 outSz = sizeof(out);
if(Base16_Encode(in, sizeof(in), out, &outSz) != 0)
{
// Handle encode error
}
\endcode
\sa Base64_Encode
\sa Base64_Decode
\sa Base16_Decode
*/
int Base16_Encode(const byte* in, word32 inLen, byte* out, word32* outLen);

View File

@@ -0,0 +1,72 @@
/*!
\ingroup Compression
\brief This function compresses the given input data using Huffman coding
and stores the output in out. Note that the output buffer should still be
larger than the input buffer because there exists a certain input for
which there will be no compression possible, which will still require a
lookup table. It is recommended that one allocate srcSz + 0.1% + 12 for
the output buffer.
\return On successfully compressing the input data, returns the number
of bytes stored in the output buffer
\return COMPRESS_INIT_E Returned if there is an error initializing the
stream for compression
\return COMPRESS_E Returned if an error occurs during compression
\param out pointer to the output buffer in which to store the compressed
data
\param outSz size available in the output buffer for storage
\param in pointer to the buffer containing the message to compress
\param inSz size of the input message to compress
\param flags flags to control how compression operates. Use 0 for normal
decompression
_Example_
\code
byte message[] = { // initialize text to compress };
byte compressed[(sizeof(message) + sizeof(message) * .001 + 12 )];
// Recommends at least srcSz + .1% + 12
if( wc_Compress(compressed, sizeof(compressed), message, sizeof(message),
0) != 0){
// error compressing data
}
\endcode
\sa wc_DeCompress
*/
int wc_Compress(byte* out, word32 outSz, const byte* in, word32 inSz, word32 flags);
/*!
\ingroup Compression
\brief This function decompresses the given compressed data using Huffman
coding and stores the output in out.
\return Success On successfully decompressing the input data, returns the
number of bytes stored in the output buffer
\return COMPRESS_INIT_E: Returned if there is an error initializing the
stream for compression
\return COMPRESS_E: Returned if an error occurs during compression
\param out pointer to the output buffer in which to store the decompressed
data
\param outSz size available in the output buffer for storage
\param in pointer to the buffer containing the message to decompress
\param inSz size of the input message to decompress
_Example_
\code
byte compressed[] = { // initialize compressed message };
byte decompressed[MAX_MESSAGE_SIZE];
if( wc_DeCompress(decompressed, sizeof(decompressed),
compressed, sizeof(compressed)) != 0 ) {
// error decompressing data
}
\endcode
\sa wc_Compress
*/
int wc_DeCompress(byte* out, word32 outSz, const byte* in, word32 inSz);

View File

@@ -0,0 +1,111 @@
/*!
\ingroup CryptoCb
\brief This function registers a unique device identifier (devID) and
callback function for offloading crypto operations to external
hardware such as Key Store, Secure Element, HSM, PKCS11 or TPM.
For STSAFE with Crypto Callbacks example see
wolfcrypt/src/port/st/stsafe.c and the wolfSSL_STSAFE_CryptoDevCb function.
For TPM based crypto callbacks example see the wolfTPM2_CryptoDevCb
function in wolfTPM src/tpm2_wrap.c
\return CRYPTOCB_UNAVAILABLE to fallback to using software crypto
\return 0 for success
\return negative value for failure
\param devId any unique value, not -2 (INVALID_DEVID)
\param cb a callback function with prototype:
typedef int (*CryptoDevCallbackFunc)(int devId, wc_CryptoInfo* info, void* ctx);
_Example_
\code
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/cryptocb.h>
static int myCryptoCb_Func(int devId, wc_CryptoInfo* info, void* ctx)
{
int ret = CRYPTOCB_UNAVAILABLE;
if (info->algo_type == WC_ALGO_TYPE_PK) {
#ifndef NO_RSA
if (info->pk.type == WC_PK_TYPE_RSA) {
switch (info->pk.rsa.type) {
case RSA_PUBLIC_ENCRYPT:
case RSA_PUBLIC_DECRYPT:
// RSA public op
ret = wc_RsaFunction(
info->pk.rsa.in, info->pk.rsa.inLen,
info->pk.rsa.out, info->pk.rsa.outLen,
info->pk.rsa.type, info->pk.rsa.key,
info->pk.rsa.rng);
break;
case RSA_PRIVATE_ENCRYPT:
case RSA_PRIVATE_DECRYPT:
// RSA private op
ret = wc_RsaFunction(
info->pk.rsa.in, info->pk.rsa.inLen,
info->pk.rsa.out, info->pk.rsa.outLen,
info->pk.rsa.type, info->pk.rsa.key,
info->pk.rsa.rng);
break;
}
}
#endif
#ifdef HAVE_ECC
if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
// ECDSA
ret = wc_ecc_sign_hash(
info->pk.eccsign.in, info->pk.eccsign.inlen,
info->pk.eccsign.out, info->pk.eccsign.outlen,
info->pk.eccsign.rng, info->pk.eccsign.key);
}
#endif
#ifdef HAVE_ED25519
if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
// ED25519 sign
ret = wc_ed25519_sign_msg_ex(
info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
info->pk.ed25519sign.key, info->pk.ed25519sign.type,
info->pk.ed25519sign.context,
info->pk.ed25519sign.contextLen);
}
#endif
}
return ret;
}
int devId = 1;
wc_CryptoCb_RegisterDevice(devId, myCryptoCb_Func, &myCtx);
wolfSSL_CTX_SetDevId(ctx, devId);
\endcode
\sa wc_CryptoCb_UnRegisterDevice
\sa wolfSSL_SetDevId
\sa wolfSSL_CTX_SetDevId
*/
int wc_CryptoCb_RegisterDevice(int devId, CryptoDevCallbackFunc cb, void* ctx);
/*!
\ingroup CryptoCb
\brief This function un-registers a unique device identifier (devID)
callback function.
\return none No returns.
\param devId any unique value, not -2 (INVALID_DEVID)
_Example_
\code
wc_CryptoCb_UnRegisterDevice(devId);
devId = INVALID_DEVID;
wolfSSL_CTX_SetDevId(ctx, devId);
\endcode
\sa wc_CryptoCb_RegisterDevice
\sa wolfSSL_SetDevId
\sa wolfSSL_CTX_SetDevId
*/
void wc_CryptoCb_UnRegisterDevice(int devId);

View File

@@ -0,0 +1,771 @@
/*!
\ingroup Curve25519
\brief This function generates a Curve25519 key using the given random
number generator, rng, of the size given (keysize), and stores it in
the given curve25519_key structure. It should be called after the key
structure has been initialized through wc_curve25519_init().
\return 0 Returned on successfully generating the key and and storing
it in the given curve25519_key structure.
\return ECC_BAD_ARG_E Returned if the input keysize does not correspond to
the keysize for a curve25519 key (32 bytes).
\return RNG_FAILURE_E Returned if the rng internal status is not
DRBG_OK or if there is in generating the next random block with rng.
\return BAD_FUNC_ARG Returned if any of the input parameters passed in
are NULL.
\param [in] rng Pointer to the RNG object used to generate the ecc key.
\param [in] keysize Size of the key to generate. Must be 32 bytes for
curve25519.
\param [in,out] key Pointer to the curve25519_key structure in which to
store the generated key.
_Example_
\code
int ret;
curve25519_key key;
wc_curve25519_init(&key); // initialize key
WC_RNG rng;
wc_InitRng(&rng); // initialize random number generator
ret = wc_curve25519_make_key(&rng, 32, &key);
if (ret != 0) {
// error making Curve25519 key
}
\endcode
\sa wc_curve25519_init
*/
int wc_curve25519_make_key(WC_RNG* rng, int keysize, curve25519_key* key);
/*!
\ingroup Curve25519
\brief This function computes a shared secret key given a secret private
key and a received public key. It stores the generated secret key in the
buffer out and assigns the variable of the secret key to outlen. Only
supports big endian.
\return 0 Returned on successfully computing a shared secret key.
\return BAD_FUNC_ARG Returned if any of the input parameters passed in
are NULL.
\return ECC_BAD_ARG_E Returned if the first bit of the public key is
set, to avoid implementation fingerprinting.
\param [in] private_key Pointer to the curve25519_key structure initialized
with the users private key.
\param [in] public_key Pointer to the curve25519_key structure containing
the received public key.
\param [out] out Pointer to a buffer in which to store the 32 byte computed
secret key.
\param [in,out] outlen Pointer in which to store the length written to the
output buffer.
_Example_
\code
int ret;
byte sharedKey[32];
word32 keySz;
curve25519_key privKey, pubKey;
// initialize both keys
ret = wc_curve25519_shared_secret(&privKey, &pubKey, sharedKey, &keySz);
if (ret != 0) {
// error generating shared key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
\sa wc_curve25519_shared_secret_ex
*/
int wc_curve25519_shared_secret(curve25519_key* private_key,
curve25519_key* public_key,
byte* out, word32* outlen);
/*!
\ingroup Curve25519
\brief This function computes a shared secret key given a secret private
key and a received public key. It stores the generated secret key in the
buffer out and assigns the variable of the secret key to outlen. Supports
both big and little endian.
\return 0 Returned on successfully computing a shared secret key.
\return BAD_FUNC_ARG Returned if any of the input parameters passed in
are NULL.
\return ECC_BAD_ARG_E Returned if the first bit of the public key is set,
to avoid implementation fingerprinting.
\param [in] private_key Pointer to the curve25519_key structure initialized
with the users private key.
\param [in] public_key Pointer to the curve25519_key structure containing
the received public key.
\param [out] out Pointer to a buffer in which to store the 32 byte computed
secret key.
\param pin,out] outlen Pointer in which to store the length written to the
output buffer.
\param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set which
form to use.
_Example_
\code
int ret;
byte sharedKey[32];
word32 keySz;
curve25519_key privKey, pubKey;
// initialize both keys
ret = wc_curve25519_shared_secret_ex(&privKey, &pubKey, sharedKey, &keySz,
EC25519_BIG_ENDIAN);
if (ret != 0) {
// error generating shared key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
\sa wc_curve25519_shared_secret
*/
int wc_curve25519_shared_secret_ex(curve25519_key* private_key,
curve25519_key* public_key,
byte* out, word32* outlen, int endian);
/*!
\ingroup Curve25519
\brief This function initializes a Curve25519 key. It should be called
before generating a key for the structure.
\return 0 Returned on successfully initializing the curve25519_key
structure.
\return BAD_FUNC_ARG Returned when key is NULL.
\param [in,out] key Pointer to the curve25519_key structure to initialize.
_Example_
\code
curve25519_key key;
wc_curve25519_init(&key); // initialize key
// make key and proceed to encryption
\endcode
\sa wc_curve25519_make_key
*/
int wc_curve25519_init(curve25519_key* key);
/*!
\ingroup Curve25519
\brief This function frees a Curve25519 object.
\param [in,out] key Pointer to the key object to free.
_Example_
\code
curve25519_key privKey;
// initialize key, use it to generate shared secret key
wc_curve25519_free(&privKey);
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
*/
void wc_curve25519_free(curve25519_key* key);
/*!
\ingroup Curve25519
\brief This function imports a curve25519 private key only. (Big endian).
\return 0 Returned on successfully importing private key.
\return BAD_FUNC_ARG Returns if key or priv is null.
\return ECC_BAD_ARG_E Returns if privSz is not equal to CURVE25519_KEY_SIZE.
\param [in] priv Pointer to a buffer containing the private key to import.
\param [in] privSz Length of the private key to import.
\param [in,out] key Pointer to the structure in which to store the imported
key.
_Example_
\code
int ret;
byte priv[] = { Contents of private key };
curve25519_key key;
wc_curve25519_init(&key);
ret = wc_curve25519_import_private(priv, sizeof(priv), &key);
if (ret != 0) {
// error importing keys
}
\endcode
\sa wc_curve25519_import_private_ex
\sa wc_curve25519_size
*/
int wc_curve25519_import_private(const byte* priv, word32 privSz,
curve25519_key* key);
/*!
\ingroup Curve25519
\brief curve25519 private key import only. (Big or Little endian).
\return 0 Returned on successfully importing private key.
\return BAD_FUNC_ARG Returns if key or priv is null.
\return ECC_BAD_ARG_E Returns if privSz is not equal to CURVE25519_KEY_SIZE.
\param [in] priv Pointer to a buffer containing the private key to import.
\param [in] privSz Length of the private key to import.
\param [in,out] key Pointer to the structure in which to store the imported
key.
\param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to
set which form to use.
_Example_
\code
int ret;
byte priv[] = { // Contents of private key };
curve25519_key key;
wc_curve25519_init(&key);
ret = wc_curve25519_import_private_ex(priv, sizeof(priv), &key,
EC25519_BIG_ENDIAN);
if (ret != 0) {
// error importing keys
}
\endcode
\sa wc_curve25519_import_private
\sa wc_curve25519_size
*/
int wc_curve25519_import_private_ex(const byte* priv, word32 privSz,
curve25519_key* key, int endian);
/*!
\ingroup Curve25519
\brief This function imports a public-private key pair into a
curve25519_key structure. Big endian only.
\return 0 Returned on importing into the curve25519_key structure
\return BAD_FUNC_ARG Returns if any of the input parameters are null.
\return ECC_BAD_ARG_E Returned if the input keys key size does not match
the public or private key sizes.
\param [in] priv Pointer to a buffer containing the private key to import.
\param [in] privSz Length of the private key to import.
\param [in] pub Pointer to a buffer containing the public key to import.
\param [in] pubSz Length of the public key to import.
\param [in,out] key Pointer to the structure in which to store the imported
keys.
_Example_
\code
int ret;
byte priv[32];
byte pub[32];
// initialize with public and private keys
curve25519_key key;
wc_curve25519_init(&key);
// initialize key
ret = wc_curve25519_import_private_raw(&priv, sizeof(priv), pub,
sizeof(pub), &key);
if (ret != 0) {
// error importing keys
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
\sa wc_curve25519_import_public
\sa wc_curve25519_export_private_raw
*/
int wc_curve25519_import_private_raw(const byte* priv, word32 privSz,
const byte* pub, word32 pubSz, curve25519_key* key);
/*!
\ingroup Curve25519
\brief This function imports a public-private key pair into a curve25519_key structure. Supports both big and little endian.
\return 0 Returned on importing into the curve25519_key structure
\return BAD_FUNC_ARG Returns if any of the input parameters are null.
\return ECC_BAD_ARG_E Returned if or the input keys key size does not match
the public or private key sizes
\param [in] priv Pointer to a buffer containing the private key to import.
\param [in] privSz Length of the private key to import.
\param [in] pub Pointer to a buffer containing the public key to import.
\param [in] pubSz Length of the public key to import.
\param [in,out] key Pointer to the structure in which to store the imported
keys.
\param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set
which form to use.
_Example_
\code
int ret;
byte priv[32];
byte pub[32];
// initialize with public and private keys
curve25519_key key;
wc_curve25519_init(&key);
// initialize key
ret = wc_curve25519_import_private_raw_ex(&priv, sizeof(priv), pub,
sizeof(pub), &key, EC25519_BIG_ENDIAN);
if (ret != 0) {
// error importing keys
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
\sa wc_curve25519_import_public
\sa wc_curve25519_export_private_raw
\sa wc_curve25519_import_private_raw
*/
int wc_curve25519_import_private_raw_ex(const byte* priv, word32 privSz,
const byte* pub, word32 pubSz,
curve25519_key* key, int endian);
/*!
\ingroup Curve25519
\brief This function exports a private key from a curve25519_key structure
and stores it in the given out buffer. It also sets outLen to be the size
of the exported key. Big Endian only.
\return 0 Returned on successfully exporting the private key from the
curve25519_key structure.
\return BAD_FUNC_ARG Returned if any input parameters are NULL.
\return ECC_BAD_ARG_E Returned if wc_curve25519_size() is not equal to key.
\param [in] key Pointer to the structure from which to export the key.
\param [out] out Pointer to the buffer in which to store the exported key.
\param [in,out] outLen On in, is the size of the out in bytes.
On out, will store the bytes written to the output buffer.
_Example_
\code
int ret;
byte priv[32];
int privSz;
curve25519_key key;
// initialize and make key
ret = wc_curve25519_export_private_raw(&key, priv, &privSz);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
\sa wc_curve25519_import_private_raw
\sa wc_curve25519_export_private_raw_ex
*/
int wc_curve25519_export_private_raw(curve25519_key* key, byte* out,
word32* outLen);
/*!
\ingroup Curve25519
\brief This function exports a private key from a curve25519_key structure
and stores it in the given out buffer. It also sets outLen to be the size
of the exported key. Can specify whether it's big or little endian.
\return 0 Returned on successfully exporting the private key from the
curve25519_key structure.
\return BAD_FUNC_ARG Returned if any input parameters are NULL.
\return ECC_BAD_ARG_E Returned if wc_curve25519_size() is not equal to key.
\param [in] key Pointer to the structure from which to export the key.
\param [out] out Pointer to the buffer in which to store the exported key.
\param [in,out] outLen On in, is the size of the out in bytes.
On out, will store the bytes written to the output buffer.
\param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set which
form to use.
_Example_
\code
int ret;
byte priv[32];
int privSz;
curve25519_key key;
// initialize and make key
ret = wc_curve25519_export_private_raw_ex(&key, priv, &privSz,
EC25519_BIG_ENDIAN);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
\sa wc_curve25519_import_private_raw
\sa wc_curve25519_export_private_raw
\sa wc_curve25519_size
*/
int wc_curve25519_export_private_raw_ex(curve25519_key* key, byte* out,
word32* outLen, int endian);
/*!
\ingroup Curve25519
\brief This function imports a public key from the given in buffer and
stores it in the curve25519_key structure.
\return 0 Returned on successfully importing the public key into the
curve25519_key structure.
\return ECC_BAD_ARG_E Returned if the inLen parameter does not match the key
size of the key structure.
\return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
\param [in] in Pointer to the buffer containing the public key to import.
\param [in] inLen Length of the public key to import.
\param [in,out] key Pointer to the curve25519_key structure in which to
store the key.
_Example_
\code
int ret;
byte pub[32];
// initialize pub with public key
curve25519_key key;
// initialize key
ret = wc_curve25519_import_public(pub,sizeof(pub), &key);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_export_public
\sa wc_curve25519_import_private_raw
\sa wc_curve25519_import_public_ex
\sa wc_curve25519_check_public
\sa wc_curve25519_size
*/
int wc_curve25519_import_public(const byte* in, word32 inLen,
curve25519_key* key);
/*!
\ingroup Curve25519
\brief This function imports a public key from the given in buffer and
stores it in the curve25519_key structure.
\return 0 Returned on successfully importing the public key into the
curve25519_key structure.
\return ECC_BAD_ARG_E Returned if the inLen parameter does not match the
key size of the key structure.
\return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
\param [in] in Pointer to the buffer containing the public key to import.
\param [in] inLen Length of the public key to import.
\param [in,out] key Pointer to the curve25519_key structure in which to
store the key.
\param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set which
form to use.
_Example_
\code
int ret;
byte pub[32];
// initialize pub with public key
curve25519_key key;
// initialize key
ret = wc_curve25519_import_public_ex(pub, sizeof(pub), &key,
EC25519_BIG_ENDIAN);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_export_public
\sa wc_curve25519_import_private_raw
\sa wc_curve25519_import_public
\sa wc_curve25519_check_public
\sa wc_curve25519_size
*/
int wc_curve25519_import_public_ex(const byte* in, word32 inLen,
curve25519_key* key, int endian);
/*!
\ingroup Curve25519
\brief This function checks that a public key buffer holds a valid
Curve25519 key value given the endian ordering.
\return 0 Returned when the public key value is valid.
\return ECC_BAD_ARG_E Returned if the public key value is not valid.
\return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
\param [in] pub Pointer to the buffer containing the public key to check.
\param [in] pubLen Length of the public key to check.
\param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set which
form to use.
_Example_
\code
int ret;
byte pub[] = { Contents of public key };
ret = wc_curve25519_check_public_ex(pub, sizeof(pub), EC25519_BIG_ENDIAN);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_import_public
\sa wc_curve25519_import_public_ex
\sa wc_curve25519_size
*/
int wc_curve25519_check_public(const byte* pub, word32 pubSz, int endian);
/*!
\ingroup Curve25519
\brief This function exports a public key from the given key structure and
stores the result in the out buffer. Big endian only.
\return 0 Returned on successfully exporting the public key from the
curve25519_key structure.
\return ECC_BAD_ARG_E Returned if outLen is less than
CURVE25519_PUB_KEY_SIZE.
\return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
\param [in] key Pointer to the curve25519_key structure in from which to
export the key.
\param [out] out Pointer to the buffer in which to store the public key.
\param [in,out] outLen On in, is the size of the out in bytes.
On out, will store the bytes written to the output buffer.
_Example_
\code
int ret;
byte pub[32];
int pubSz;
curve25519_key key;
// initialize and make key
ret = wc_curve25519_export_public(&key, pub, &pubSz);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_export_private_raw
\sa wc_curve25519_import_public
*/
int wc_curve25519_export_public(curve25519_key* key, byte* out, word32* outLen);
/*!
\ingroup Curve25519
\brief This function exports a public key from the given key structure and
stores the result in the out buffer. Supports both big and little endian.
\return 0 Returned on successfully exporting the public key from the
curve25519_key structure.
\return ECC_BAD_ARG_E Returned if outLen is less than
CURVE25519_PUB_KEY_SIZE.
\return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
\param [in] key Pointer to the curve25519_key structure in from which to
export the key.
\param [out] out Pointer to the buffer in which to store the public key.
\param [in,out] outLen On in, is the size of the out in bytes.
On out, will store the bytes written to the output buffer.
\param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set which
form to use.
_Example_
\code
int ret;
byte pub[32];
int pubSz;
curve25519_key key;
// initialize and make key
ret = wc_curve25519_export_public_ex(&key, pub, &pubSz, EC25519_BIG_ENDIAN);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_export_private_raw
\sa wc_curve25519_import_public
*/
int wc_curve25519_export_public_ex(curve25519_key* key, byte* out,
word32* outLen, int endian);
/*!
\ingroup Curve25519
\brief Export Curve25519 key pair. Big endian only.
\return 0 Returned on successfully exporting the key pair from the
curve25519_key structure.
\return BAD_FUNC_ARG Returned if any input parameters are NULL.
\return ECC_BAD_ARG_E Returned if privSz is less than CURVE25519_KEY_SIZE or
pubSz is less than CURVE25519_PUB_KEY_SIZE.
\param [in] key Pointer to the curve448_key structure in from which to
export the key pair.
\param [out] priv Pointer to the buffer in which to store the private key.
\param [in,out] privSz On in, is the size of the priv buffer in bytes.
On out, will store the bytes written to the priv buffer.
\param [out] pub Pointer to the buffer in which to store the public key.
\param [in,out] pubSz On in, is the size of the pub buffer in bytes.
On out, will store the bytes written to the pub buffer.
_Example_
\code
int ret;
byte pub[32];
byte priv[32];
int pubSz;
int privSz;
curve25519_key key;
// initialize and make key
ret = wc_curve25519_export_key_raw(&key, priv, &privSz, pub, &pubSz);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve25519_export_key_raw_ex
\sa wc_curve25519_export_private_raw
*/
int wc_curve25519_export_key_raw(curve25519_key* key,
byte* priv, word32 *privSz,
byte* pub, word32 *pubSz);
/*!
\ingroup Curve25519
\brief Export curve25519 key pair. Big or little endian.
\return 0 Returned on successfully exporting the key pair from the
curve25519_key structure.
\return BAD_FUNC_ARG Returned if any input parameters are NULL.
\return ECC_BAD_ARG_E Returned if privSz is less than CURVE25519_KEY_SIZE or
pubSz is less than CURVE25519_PUB_KEY_SIZE.
\param [in] key Pointer to the curve448_key structure in from which to
export the key pair.
\param [out] priv Pointer to the buffer in which to store the private key.
\param [in,out] privSz On in, is the size of the priv buffer in bytes.
On out, will store the bytes written to the priv buffer.
\param [out] pub Pointer to the buffer in which to store the public key.
\param [in,out] pubSz On in, is the size of the pub buffer in bytes.
On out, will store the bytes written to the pub buffer.
\param [in] endian EC25519_BIG_ENDIAN or EC25519_LITTLE_ENDIAN to set which
form to use.
_Example_
\code
int ret;
byte pub[32];
byte priv[32];
int pubSz;
int privSz;
curve25519_key key;
// initialize and make key
ret = wc_curve25519_export_key_raw_ex(&key,priv, &privSz, pub, &pubSz,
EC25519_BIG_ENDIAN);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve25519_export_key_raw
\sa wc_curve25519_export_private_raw_ex
\sa wc_curve25519_export_public_ex
*/
int wc_curve25519_export_key_raw_ex(curve25519_key* key,
byte* priv, word32 *privSz,
byte* pub, word32 *pubSz,
int endian);
/*!
\ingroup Curve25519
\brief This function returns the key size of the given key structure.
\return Success Given a valid, initialized curve25519_key structure,
returns the size of the key.
\return 0 Returned if key is NULL
\param [in] key Pointer to the curve25519_key structure in for which to
determine the key size.
_Example_
\code
int keySz;
curve25519_key key;
// initialize and make key
keySz = wc_curve25519_size(&key);
\endcode
\sa wc_curve25519_init
\sa wc_curve25519_make_key
*/
int wc_curve25519_size(curve25519_key* key);

View File

@@ -0,0 +1,768 @@
/*!
\ingroup Curve448
\brief This function generates a Curve448 key using the given random
number generator, rng, of the size given (keysize), and stores it in
the given curve448_key structure. It should be called after the key
structure has been initialized through wc_curve448_init().
\return 0 Returned on successfully generating the key and and storing
it in the given curve448_key structure.
\return ECC_BAD_ARG_E Returned if the input keysize does not correspond to
the keysize for a curve448 key (56 bytes).
\return RNG_FAILURE_E Returned if the rng internal status is not
DRBG_OK or if there is in generating the next random block with rng.
\return BAD_FUNC_ARG Returned if any of the input parameters passed in
are NULL.
\param [in] rng Pointer to the RNG object used to generate the ecc key.
\param [in] keysize Size of the key to generate. Must be 56 bytes for
curve448.
\param [in,out] key Pointer to the curve448_key structure in which to
store the generated key.
_Example_
\code
int ret;
curve448_key key;
wc_curve448_init(&key); // initialize key
WC_RNG rng;
wc_InitRng(&rng); // initialize random number generator
ret = wc_curve448_make_key(&rng, 56, &key);
if (ret != 0) {
// error making Curve448 key
}
\endcode
\sa wc_curve448_init
*/
int wc_curve448_make_key(WC_RNG* rng, int keysize, curve448_key* key);
/*!
\ingroup Curve448
\brief This function computes a shared secret key given a secret private
key and a received public key. It stores the generated secret key in the
buffer out and assigns the variable of the secret key to outlen. Only
supports big endian.
\return 0 Returned on successfully computing a shared secret key
\return BAD_FUNC_ARG Returned if any of the input parameters passed in
are NULL
\param [in] private_key Pointer to the curve448_key structure initialized
with the users private key.
\param [in] public_key Pointer to the curve448_key structure containing
the received public key.
\param [out] out Pointer to a buffer in which to store the 56 byte computed
secret key.
\param [in,out] outlen Pointer in which to store the length written to the
output buffer.
_Example_
\code
int ret;
byte sharedKey[56];
word32 keySz;
curve448_key privKey, pubKey;
// initialize both keys
ret = wc_curve448_shared_secret(&privKey, &pubKey, sharedKey, &keySz);
if (ret != 0) {
// error generating shared key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
\sa wc_curve448_shared_secret_ex
*/
int wc_curve448_shared_secret(curve448_key* private_key,
curve448_key* public_key,
byte* out, word32* outlen);
/*!
\ingroup Curve448
\brief This function computes a shared secret key given a secret private
key and a received public key. It stores the generated secret key in the
buffer out and assigns the variable of the secret key to outlen. Supports
both big and little endian.
\return 0 Returned on successfully computing a shared secret key.
\return BAD_FUNC_ARG Returned if any of the input parameters passed in
are NULL.
\param [in] private_key Pointer to the curve448_key structure initialized
with the users private key.
\param [in] public_key Pointer to the curve448_key structure containing
the received public key.
\param [out] out Pointer to a buffer in which to store the 56 byte computed
secret key.
\param [in,out] outlen Pointer in which to store the length written to the
output buffer.
\param [in] endian EC448_BIG_ENDIAN or EC448_LITTLE_ENDIAN to set which
form to use.
_Example_
\code
int ret;
byte sharedKey[56];
word32 keySz;
curve448_key privKey, pubKey;
// initialize both keys
ret = wc_curve448_shared_secret_ex(&privKey, &pubKey, sharedKey, &keySz,
EC448_BIG_ENDIAN);
if (ret != 0) {
// error generating shared key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
\sa wc_curve448_shared_secret
*/
int wc_curve448_shared_secret_ex(curve448_key* private_key,
curve448_key* public_key,
byte* out, word32* outlen, int endian);
/*!
\ingroup Curve448
\brief This function initializes a Curve448 key. It should be called
before generating a key for the structure.
\return 0 Returned on successfully initializing the curve448_key structure.
\return BAD_FUNC_ARG Returned when key is NULL.
\param [in,out] key Pointer to the curve448_key structure to initialize.
_Example_
\code
curve448_key key;
wc_curve448_init(&key); // initialize key
// make key and proceed to encryption
\endcode
\sa wc_curve448_make_key
*/
int wc_curve448_init(curve448_key* key);
/*!
\ingroup Curve448
\brief This function frees a Curve448 object.
\param [in,out] key Pointer to the key object to free.
_Example_
\code
curve448_key privKey;
// initialize key, use it to generate shared secret key
wc_curve448_free(&privKey);
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
*/
void wc_curve448_free(curve448_key* key);
/*!
\ingroup Curve448
\brief This function imports a curve448 private key only. (Big endian).
\return 0 Returned on successfully importing private key.
\return BAD_FUNC_ARG Returns if key or priv is null.
\return ECC_BAD_ARG_E Returns if privSz is not equal to CURVE448_KEY_SIZE.
\param [in] priv Pointer to a buffer containing the private key to import.
\param [in] privSz Length of the private key to import.
\param [in,out] key Pointer to the structure in which to store the imported
key.
_Example_
\code
int ret;
byte priv[] = { Contents of private key };
curve448_key key;
wc_curve448_init(&key);
ret = wc_curve448_import_private(priv, sizeof(priv), &key);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve448_import_private_ex
\sa wc_curve448_size
*/
int wc_curve448_import_private(const byte* priv, word32 privSz,
curve448_key* key);
/*!
\ingroup Curve448
\brief curve448 private key import only. (Big or Little endian).
\return 0 Returned on successfully importing private key.
\return BAD_FUNC_ARG Returns if key or priv is null.
\return ECC_BAD_ARG_E Returns if privSz is not equal to CURVE448_KEY_SIZE.
\param [in] priv Pointer to a buffer containing the private key to import.
\param [in] privSz Length of the private key to import.
\param [in,out] key Pointer to the structure in which to store the imported
key.
\param [in] endian EC448_BIG_ENDIAN or EC448_LITTLE_ENDIAN to
set which form to use.
_Example_
\code
int ret;
byte priv[] = { // Contents of private key };
curve448_key key;
wc_curve448_init(&key);
ret = wc_curve448_import_private_ex(priv, sizeof(priv), &key,
EC448_BIG_ENDIAN);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve448_import_private
\sa wc_curve448_size
*/
int wc_curve448_import_private_ex(const byte* priv, word32 privSz,
curve448_key* key, int endian);
/*!
\ingroup Curve448
\brief This function imports a public-private key pair into a
curve448_key structure. Big endian only.
\return 0 Returned on importing into the curve448_key structure.
\return BAD_FUNC_ARG Returns if any of the input parameters are null.
\return ECC_BAD_ARG_E Returned if the input keys key size does not match
the public or private key sizes.
\param [in] priv Pointer to a buffer containing the private key to import.
\param [in] privSz Length of the private key to import.
\param [in] pub Pointer to a buffer containing the public key to import.
\param [in] pubSz Length of the public key to import.
\param [in,out] key Pointer to the structure in which to store the imported
keys
_Example_
\code
int ret;
byte priv[56];
byte pub[56];
// initialize with public and private keys
curve448_key key;
wc_curve448_init(&key);
// initialize key
ret = wc_curve448_import_private_raw(&priv, sizeof(priv), pub, sizeof(pub),
&key);
if (ret != 0) {
// error importing keys
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
\sa wc_curve448_import_public
\sa wc_curve448_export_private_raw
*/
int wc_curve448_import_private_raw(const byte* priv, word32 privSz,
const byte* pub, word32 pubSz, curve448_key* key);
/*!
\ingroup Curve448
\brief This function imports a public-private key pair into a curve448_key structure. Supports both big and little endian.
\return 0 Returned on importing into the curve448_key structure.
\return BAD_FUNC_ARG Returns if any of the input parameters are null.
\return ECC_BAD_ARG_E Returned if the input keys key size does not match
the public or private key sizes.
\param [in] priv Pointer to a buffer containing the private key to import.
\param [in] privSz Length of the private key to import.
\param [in] pub Pointer to a buffer containing the public key to import.
\param [in] pubSz Length of the public key to import.
\param [in,out] key Pointer to the structure in which to store the imported
keys.
\param [in] endian EC448_BIG_ENDIAN or EC448_LITTLE_ENDIAN to set
which form to use.
_Example_
\code
int ret;
byte priv[56];
byte pub[56];
// initialize with public and private keys
curve448_key key;
wc_curve448_init(&key);
// initialize key
ret = wc_curve448_import_private_raw_ex(&priv, sizeof(priv), pub,
sizeof(pub), &key, EC448_BIG_ENDIAN);
if (ret != 0) {
// error importing keys
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
\sa wc_curve448_import_public
\sa wc_curve448_export_private_raw
\sa wc_curve448_import_private_raw
*/
int wc_curve448_import_private_raw_ex(const byte* priv, word32 privSz,
const byte* pub, word32 pubSz,
curve448_key* key, int endian);
/*!
\ingroup Curve448
\brief This function exports a private key from a curve448_key structure
and stores it in the given out buffer. It also sets outLen to be the size
of the exported key. Big Endian only.
\return 0 Returned on successfully exporting the private key from the
curve448_key structure.
\return BAD_FUNC_ARG Returned if any input parameters are NULL.
\return ECC_BAD_ARG_E Returned if wc_curve448_size() is not equal to key.
\param [in] key Pointer to the structure from which to export the key.
\param [out] out Pointer to the buffer in which to store the exported key.
\param [in,out] outLen On in, is the size of the out in bytes.
On out, will store the bytes written to the output buffer.
_Example_
\code
int ret;
byte priv[56];
int privSz;
curve448_key key;
// initialize and make key
ret = wc_curve448_export_private_raw(&key, priv, &privSz);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
\sa wc_curve448_import_private_raw
\sa wc_curve448_export_private_raw_ex
*/
int wc_curve448_export_private_raw(curve448_key* key, byte* out,
word32* outLen);
/*!
\ingroup Curve448
\brief This function exports a private key from a curve448_key structure
and stores it in the given out buffer. It also sets outLen to be the size
of the exported key. Can specify whether it's big or little endian.
\return 0 Returned on successfully exporting the private key from the
curve448_key structure.
\return BAD_FUNC_ARG Returned if any input parameters are NULL.
\return ECC_BAD_ARG_E Returned if wc_curve448_size() is not equal to key.
\param [in] key Pointer to the structure from which to export the key.
\param [out] out Pointer to the buffer in which to store the exported key.
\param [in,out] outLen On in, is the size of the out in bytes.
On out, will store the bytes written to the output buffer.
\param [in] endian EC448_BIG_ENDIAN or EC448_LITTLE_ENDIAN to set which
form to use.
_Example_
\code
int ret;
byte priv[56];
int privSz;
curve448_key key;
// initialize and make key
ret = wc_curve448_export_private_raw_ex(&key, priv, &privSz,
EC448_BIG_ENDIAN);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
\sa wc_curve448_import_private_raw
\sa wc_curve448_export_private_raw
\sa wc_curve448_size
*/
int wc_curve448_export_private_raw_ex(curve448_key* key, byte* out,
word32* outLen, int endian);
/*!
\ingroup Curve448
\brief This function imports a public key from the given in buffer and
stores it in the curve448_key structure.
\return 0 Returned on successfully importing the public key into the
curve448_key structure.
\return ECC_BAD_ARG_E Returned if the inLen parameter does not match the key
size of the key structure.
\return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
\param [in] in Pointer to the buffer containing the public key to import.
\param [in] inLen Length of the public key to import.
\param [in,out] key Pointer to the curve448_key structure in which to store
the key.
_Example_
\code
int ret;
byte pub[56];
// initialize pub with public key
curve448_key key;
// initialize key
ret = wc_curve448_import_public(pub,sizeof(pub), &key);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_export_public
\sa wc_curve448_import_private_raw
\sa wc_curve448_import_public_ex
\sa wc_curve448_check_public
\sa wc_curve448_size
*/
int wc_curve448_import_public(const byte* in, word32 inLen,
curve448_key* key);
/*!
\ingroup Curve448
\brief This function imports a public key from the given in buffer and
stores it in the curve448_key structure.
\return 0 Returned on successfully importing the public key into the
curve448_key structure.
\return ECC_BAD_ARG_E Returned if the inLen parameter does not match the
key size of the key structure.
\return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
\param [in] in Pointer to the buffer containing the public key to import.
\param [in] inLen Length of the public key to import.
\param [in,out] key Pointer to the curve448_key structure in which to store
the key.
\param [in] endian EC448_BIG_ENDIAN or EC448_LITTLE_ENDIAN to set which
form to use.
_Example_
\code
int ret;
byte pub[56];
// initialize pub with public key
curve448_key key;
// initialize key
ret = wc_curve448_import_public_ex(pub, sizeof(pub), &key,
EC448_BIG_ENDIAN);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_export_public
\sa wc_curve448_import_private_raw
\sa wc_curve448_import_public
\sa wc_curve448_check_public
\sa wc_curve448_size
*/
int wc_curve448_import_public_ex(const byte* in, word32 inLen,
curve448_key* key, int endian);
/*!
\ingroup Curve448
\brief This function checks that a public key buffer holds a valid
Curve448 key value given the endian ordering.
\return 0 Returned when the public key value is valid.
\return ECC_BAD_ARG_E Returned if the public key value is not valid.
\return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
\param [in] pub Pointer to the buffer containing the public key to check.
\param [in] pubLen Length of the public key to check.
\param [in] endian EC448_BIG_ENDIAN or EC448_LITTLE_ENDIAN to set which
form to use.
_Example_
\code
int ret;
byte pub[] = { Contents of public key };
ret = wc_curve448_check_public_ex(pub, sizeof(pub), EC448_BIG_ENDIAN);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_import_public
\sa wc_curve448_import_public_ex
\sa wc_curve448_size
*/
int wc_curve448_check_public(const byte* pub, word32 pubSz, int endian);
/*!
\ingroup Curve448
\brief This function exports a public key from the given key structure and
stores the result in the out buffer. Big endian only.
\return 0 Returned on successfully exporting the public key from the
curve448_key structure.
\return ECC_BAD_ARG_E Returned if outLen is less than CURVE448_PUB_KEY_SIZE.
\return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
\param [in] key Pointer to the curve448_key structure in from which to
export the key.
\param [out] out Pointer to the buffer in which to store the public key.
\param [in,out] outLen On in, is the size of the out in bytes.
On out, will store the bytes written to the output buffer.
_Example_
\code
int ret;
byte pub[56];
int pubSz;
curve448_key key;
// initialize and make key
ret = wc_curve448_export_public(&key, pub, &pubSz);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_export_private_raw
\sa wc_curve448_import_public
*/
int wc_curve448_export_public(curve448_key* key, byte* out, word32* outLen);
/*!
\ingroup Curve448
\brief This function exports a public key from the given key structure and
stores the result in the out buffer. Supports both big and little endian.
\return 0 Returned on successfully exporting the public key from the
curve448_key structure.
\return ECC_BAD_ARG_E Returned if outLen is less than CURVE448_PUB_KEY_SIZE.
\return BAD_FUNC_ARG Returned if any of the input parameters are NULL.
\param [in] key Pointer to the curve448_key structure in from which to
export the key.
\param [out] out Pointer to the buffer in which to store the public key.
\param [in,out] outLen On in, is the size of the out in bytes.
On out, will store the bytes written to the output buffer.
\param [in] endian EC448_BIG_ENDIAN or EC448_LITTLE_ENDIAN to set which
form to use.
_Example_
\code
int ret;
byte pub[56];
int pubSz;
curve448_key key;
// initialize and make key
ret = wc_curve448_export_public_ex(&key, pub, &pubSz, EC448_BIG_ENDIAN);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve448_init
\sa wc_curve448_export_private_raw
\sa wc_curve448_import_public
*/
int wc_curve448_export_public_ex(curve448_key* key, byte* out,
word32* outLen, int endian);
/*!
\ingroup Curve448
\brief This function exports a key pair from the given key structure and
stores the result in the out buffer. Big endian only.
\return 0 Returned on successfully exporting the key pair from the
curve448_key structure.
\return BAD_FUNC_ARG Returned if any input parameters are NULL.
\return ECC_BAD_ARG_E Returned if privSz is less than CURVE448_KEY_SIZE or
pubSz is less than CURVE448_PUB_KEY_SIZE.
\param [in] key Pointer to the curve448_key structure in from which to
export the key pair.
\param [out] priv Pointer to the buffer in which to store the private key.
\param [in,out] privSz On in, is the size of the priv buffer in bytes.
On out, will store the bytes written to the priv buffer.
\param [out] pub Pointer to the buffer in which to store the public key.
\param [in,out] pubSz On in, is the size of the pub buffer in bytes.
On out, will store the bytes written to the pub buffer.
_Example_
\code
int ret;
byte pub[56];
byte priv[56];
int pubSz;
int privSz;
curve448_key key;
// initialize and make key
ret = wc_curve448_export_key_raw(&key, priv, &privSz, pub, &pubSz);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve448_export_key_raw_ex
\sa wc_curve448_export_private_raw
*/
int wc_curve448_export_key_raw(curve448_key* key,
byte* priv, word32 *privSz,
byte* pub, word32 *pubSz);
/*!
\ingroup Curve448
\brief Export curve448 key pair. Big or little endian.
\brief This function exports a key pair from the given key structure and
stores the result in the out buffer. Big or little endian.
\return 0 Success
\return BAD_FUNC_ARG Returned if any input parameters are NULL.
\return ECC_BAD_ARG_E Returned if privSz is less than CURVE448_KEY_SIZE or
pubSz is less than CURVE448_PUB_KEY_SIZE.
\param [in] key Pointer to the curve448_key structure in from which to
export the key pair.
\param [out] priv Pointer to the buffer in which to store the private key.
\param [in,out] privSz On in, is the size of the priv buffer in bytes.
On out, will store the bytes written to the priv buffer.
\param [out] pub Pointer to the buffer in which to store the public key.
\param [in,out] pubSz On in, is the size of the pub buffer in bytes.
On out, will store the bytes written to the pub buffer.
\param [in] endian EC448_BIG_ENDIAN or EC448_LITTLE_ENDIAN to set which
form to use.
_Example_
\code
int ret;
byte pub[56];
byte priv[56];
int pubSz;
int privSz;
curve448_key key;
// initialize and make key
ret = wc_curve448_export_key_raw_ex(&key,priv, &privSz, pub, &pubSz,
EC448_BIG_ENDIAN);
if (ret != 0) {
// error exporting key
}
\endcode
\sa wc_curve448_export_key_raw
\sa wc_curve448_export_private_raw_ex
\sa wc_curve448_export_public_ex
*/
int wc_curve448_export_key_raw_ex(curve448_key* key,
byte* priv, word32 *privSz,
byte* pub, word32 *pubSz,
int endian);
/*!
\ingroup Curve448
\brief This function returns the key size of the given key structure.
\return Success Given a valid, initialized curve448_key structure,
returns the size of the key.
\return 0 Returned if key is NULL.
\param [in] key Pointer to the curve448_key structure in for which to
determine the key size.
_Example_
\code
int keySz;
curve448_key key;
// initialize and make key
keySz = wc_curve448_size(&key);
\endcode
\sa wc_curve448_init
\sa wc_curve448_make_key
*/
int wc_curve448_size(curve448_key* key);

View File

@@ -0,0 +1,332 @@
/*!
\ingroup 3DES
\brief This function sets the key and initialization vector (iv) for the
Des structure given as argument. It also initializes and allocates space
for the buffers needed for encryption and decryption, if these have not
yet been initialized. Note: If no iv is provided (i.e. iv == NULL)
the initialization vector defaults to an iv of 0.
\return 0 On successfully setting the key and initialization vector for
the Des structure
\param des pointer to the Des structure to initialize
\param key pointer to the buffer containing the 8 byte key with which to
initialize the Des structure
\param iv pointer to the buffer containing the 8 byte iv with which to
initialize the Des structure. If this is not provided, the iv defaults to 0
\param dir direction of encryption. Valid options are: DES_ENCRYPTION,
and DES_DECRYPTION
_Example_
\code
Des enc; // Des structure used for encryption
int ret;
byte key[] = { // initialize with 8 byte key };
byte iv[] = { // initialize with 8 byte iv };
ret = wc_Des_SetKey(&des, key, iv, DES_ENCRYPTION);
if (ret != 0) {
// error initializing des structure
}
\endcode
\sa wc_Des_SetIV
\sa wc_Des3_SetKey
*/
int wc_Des_SetKey(Des* des, const byte* key,
const byte* iv, int dir);
/*!
\ingroup 3DES
\brief This function sets the initialization vector (iv) for the Des
structure given as argument. When passed a NULL iv, it sets the
initialization vector to 0.
\return none No returns.
\param des pointer to the Des structure for which to set the iv
\param iv pointer to the buffer containing the 8 byte iv with which to
initialize the Des structure. If this is not provided, the iv defaults to 0
_Example_
\code
Des enc; // Des structure used for encryption
// initialize enc with wc_Des_SetKey
byte iv[] = { // initialize with 8 byte iv };
wc_Des_SetIV(&enc, iv);
}
\endcode
\sa wc_Des_SetKey
*/
void wc_Des_SetIV(Des* des, const byte* iv);
/*!
\ingroup 3DES
\brief This function encrypts the input message, in, and stores the result
in the output buffer, out. It uses DES encryption with cipher block
chaining (CBC) mode.
\return 0 Returned upon successfully encrypting the given input message
\param des pointer to the Des structure to use for encryption
\param out pointer to the buffer in which to store the encrypted ciphertext
\param in pointer to the input buffer containing the message to encrypt
\param sz length of the message to encrypt
_Example_
\code
Des enc; // Des structure used for encryption
// initialize enc with wc_Des_SetKey, use mode DES_ENCRYPTION
byte plain[] = { // initialize with message };
byte cipher[sizeof(plain)];
if ( wc_Des_CbcEncrypt(&enc, cipher, plain, sizeof(plain)) != 0) {
// error encrypting message
}
\endcode
\sa wc_Des_SetKey
\sa wc_Des_CbcDecrypt
*/
int wc_Des_CbcEncrypt(Des* des, byte* out,
const byte* in, word32 sz);
/*!
\ingroup 3DES
\brief This function decrypts the input ciphertext, in, and stores the
resulting plaintext in the output buffer, out. It uses DES encryption
with cipher block chaining (CBC) mode.
\return 0 Returned upon successfully decrypting the given ciphertext
\param des pointer to the Des structure to use for decryption
\param out pointer to the buffer in which to store the decrypted plaintext
\param in pointer to the input buffer containing the encrypted ciphertext
\param sz length of the ciphertext to decrypt
_Example_
\code
Des dec; // Des structure used for decryption
// initialize dec with wc_Des_SetKey, use mode DES_DECRYPTION
byte cipher[] = { // initialize with ciphertext };
byte decoded[sizeof(cipher)];
if ( wc_Des_CbcDecrypt(&dec, decoded, cipher, sizeof(cipher)) != 0) {
// error decrypting message
}
\endcode
\sa wc_Des_SetKey
\sa wc_Des_CbcEncrypt
*/
int wc_Des_CbcDecrypt(Des* des, byte* out,
const byte* in, word32 sz);
/*!
\ingroup 3DES
\brief This function encrypts the input message, in, and stores the result
in the output buffer, out. It uses Des encryption with Electronic
Codebook (ECB) mode.
\return 0: Returned upon successfully encrypting the given plaintext.
\param des pointer to the Des structure to use for encryption
\param out pointer to the buffer in which to store the encrypted message
\param in pointer to the input buffer containing the plaintext to encrypt
\param sz length of the plaintext to encrypt
_Example_
\code
Des enc; // Des structure used for encryption
// initialize enc with wc_Des_SetKey, use mode DES_ENCRYPTION
byte plain[] = { // initialize with message to encrypt };
byte cipher[sizeof(plain)];
if ( wc_Des_EcbEncrypt(&enc,cipher, plain, sizeof(plain)) != 0) {
// error encrypting message
}
\endcode
\sa wc_Des_SetKe
*/
int wc_Des_EcbEncrypt(Des* des, byte* out,
const byte* in, word32 sz);
/*!
\ingroup 3DES
\brief This function encrypts the input message, in, and stores the
result in the output buffer, out. It uses Des3 encryption with
Electronic Codebook (ECB) mode. Warning: In nearly all use cases ECB
mode is considered to be less secure. Please avoid using ECB APIs
directly whenever possible.
\return 0 Returned upon successfully encrypting the given plaintext
\param des3 pointer to the Des3 structure to use for encryption
\param out pointer to the buffer in which to store the encrypted message
\param in pointer to the input buffer containing the plaintext to encrypt
\param sz length of the plaintext to encrypt
_Example_
\code
Des3 enc; // Des3 structure used for encryption
// initialize enc with wc_Des3_SetKey, use mode DES_ENCRYPTION
byte plain[] = { // initialize with message to encrypt };
byte cipher[sizeof(plain)];
if ( wc_Des3_EcbEncrypt(&enc,cipher, plain, sizeof(plain)) != 0) {
// error encrypting message
}
\endcode
\sa wc_Des3_SetKey
*/
int wc_Des3_EcbEncrypt(Des3* des, byte* out,
const byte* in, word32 sz);
/*!
\ingroup 3DES
\brief This function sets the key and initialization vector (iv) for
the Des3 structure given as argument. It also initializes and allocates
space for the buffers needed for encryption and decryption, if these
have not yet been initialized. Note: If no iv is provided (i.e. iv ==
NULL) the initialization vector defaults to an iv of 0.
\return 0 On successfully setting the key and initialization vector
for the Des structure
\param des3 pointer to the Des3 structure to initialize
\param key pointer to the buffer containing the 24 byte key with which
to initialize the Des3 structure
\param iv pointer to the buffer containing the 8 byte iv with which to
initialize the Des3 structure. If this is not provided, the iv defaults
to 0
\param dir direction of encryption. Valid options are: DES_ENCRYPTION,
and DES_DECRYPTION
_Example_
\code
Des3 enc; // Des3 structure used for encryption
int ret;
byte key[] = { // initialize with 24 byte key };
byte iv[] = { // initialize with 8 byte iv };
ret = wc_Des3_SetKey(&des, key, iv, DES_ENCRYPTION);
if (ret != 0) {
// error initializing des structure
}
\endcode
\sa wc_Des3_SetIV
\sa wc_Des3_CbcEncrypt
\sa wc_Des3_CbcDecrypt
*/
int wc_Des3_SetKey(Des3* des, const byte* key,
const byte* iv,int dir);
/*!
\ingroup 3DES
\brief This function sets the initialization vector (iv) for the Des3
structure given as argument. When passed a NULL iv, it sets the
initialization vector to 0.
\return none No returns.
\param des pointer to the Des3 structure for which to set the iv
\param iv pointer to the buffer containing the 8 byte iv with which to
initialize the Des3 structure. If this is not provided, the iv
defaults to 0
_Example_
\code
Des3 enc; // Des3 structure used for encryption
// initialize enc with wc_Des3_SetKey
byte iv[] = { // initialize with 8 byte iv };
wc_Des3_SetIV(&enc, iv);
}
\endcode
\sa wc_Des3_SetKey
*/
int wc_Des3_SetIV(Des3* des, const byte* iv);
/*!
\ingroup 3DES
\brief This function encrypts the input message, in, and stores the
result in the output buffer, out. It uses Triple Des (3DES) encryption
with cipher block chaining (CBC) mode.
\return 0 Returned upon successfully encrypting the given input message
\param des pointer to the Des3 structure to use for encryption
\param out pointer to the buffer in which to store the encrypted ciphertext
\param in pointer to the input buffer containing the message to encrypt
\param sz length of the message to encrypt
_Example_
\code
Des3 enc; // Des3 structure used for encryption
// initialize enc with wc_Des3_SetKey, use mode DES_ENCRYPTION
byte plain[] = { // initialize with message };
byte cipher[sizeof(plain)];
if ( wc_Des3_CbcEncrypt(&enc, cipher, plain, sizeof(plain)) != 0) {
// error encrypting message
}
\endcode
\sa wc_Des3_SetKey
\sa wc_Des3_CbcDecrypt
*/
int wc_Des3_CbcEncrypt(Des3* des, byte* out,
const byte* in,word32 sz);
/*!
\ingroup 3DES
\brief This function decrypts the input ciphertext, in, and stores the
resulting plaintext in the output buffer, out. It uses Triple Des (3DES)
encryption with cipher block chaining (CBC) mode.
\return 0 Returned upon successfully decrypting the given ciphertext
\param des pointer to the Des3 structure to use for decryption
\param out pointer to the buffer in which to store the decrypted plaintext
\param in pointer to the input buffer containing the encrypted ciphertext
\param sz length of the ciphertext to decrypt
_Example_
\code
Des3 dec; // Des structure used for decryption
// initialize dec with wc_Des3_SetKey, use mode DES_DECRYPTION
byte cipher[] = { // initialize with ciphertext };
byte decoded[sizeof(cipher)];
if ( wc_Des3_CbcDecrypt(&dec, decoded, cipher, sizeof(cipher)) != 0) {
// error decrypting message
}
\endcode
\sa wc_Des3_SetKey
\sa wc_Des3_CbcEncrypt
*/
int wc_Des3_CbcDecrypt(Des3* des, byte* out,
const byte* in,word32 sz);

View File

@@ -0,0 +1,400 @@
/*!
\ingroup Diffie-Hellman
\brief This function initializes a Diffie-Hellman key for use in
negotiating a secure secret key with the Diffie-Hellman exchange protocol.
\return none No returns.
\param key pointer to the DhKey structure to initialize for use with
secure key exchanges
_Example_
\code
DhKey key;
wc_InitDhKey(&key); // initialize DH key
\endcode
\sa wc_FreeDhKey
\sa wc_DhGenerateKeyPair
*/
int wc_InitDhKey(DhKey* key);
/*!
\ingroup Diffie-Hellman
\brief This function frees a Diffie-Hellman key after it has been used to
negotiate a secure secret key with the Diffie-Hellman exchange protocol.
\return none No returns.
\param key pointer to the DhKey structure to free
_Example_
\code
DhKey key;
// initialize key, perform key exchange
wc_FreeDhKey(&key); // free DH key to avoid memory leaks
\endcode
\sa wc_InitDhKey
*/
void wc_FreeDhKey(DhKey* key);
/*!
\ingroup Diffie-Hellman
\brief This function generates a public/private key pair based on the
Diffie-Hellman public parameters, storing the private key in priv and the
public key in pub. It takes an initialized Diffie-Hellman key and an
initialized rng structure.
\return BAD_FUNC_ARG Returned if there is an error parsing one of the
inputs to this function
\return RNG_FAILURE_E Returned if there is an error generating a random
number using rng
\return MP_INIT_E May be returned if there is an error in the math library
while generating the public key
\return MP_READ_E May be returned if there is an error in the math library
while generating the public key
\return MP_EXPTMOD_E May be returned if there is an error in the math
library while generating the public key
\return MP_TO_E May be returned if there is an error in the math library
while generating the public key
\param key pointer to the DhKey structure from which to generate
the key pair
\param rng pointer to an initialized random number generator (rng) with
which to generate the keys
\param priv pointer to a buffer in which to store the private key
\param privSz will store the size of the private key written to priv
\param pub pointer to a buffer in which to store the public key
\param pubSz will store the size of the private key written to pub
_Example_
\code
DhKey key;
int ret;
byte priv[256];
byte pub[256];
word32 privSz, pubSz;
wc_InitDhKey(&key); // initialize key
// Set DH parameters using wc_DhSetKey or wc_DhKeyDecode
WC_RNG rng;
wc_InitRng(&rng); // initialize rng
ret = wc_DhGenerateKeyPair(&key, &rng, priv, &privSz, pub, &pubSz);
\endcode
\sa wc_InitDhKey
\sa wc_DhSetKey
\sa wc_DhKeyDecode
*/
int wc_DhGenerateKeyPair(DhKey* key, WC_RNG* rng, byte* priv,
word32* privSz, byte* pub, word32* pubSz);
/*!
\ingroup Diffie-Hellman
\brief This function generates an agreed upon secret key based on a local
private key and a received public key. If completed on both sides of an
exchange, this function generates an agreed upon secret key for symmetric
communication. On successfully generating a shared secret key, the size of
the secret key written will be stored in agreeSz.
\return 0 Returned on successfully generating an agreed upon secret key
\return MP_INIT_E May be returned if there is an error while generating
the shared secret key
\return MP_READ_E May be returned if there is an error while generating
the shared secret key
\return MP_EXPTMOD_E May be returned if there is an error while generating
the shared secret key
\return MP_TO_E May be returned if there is an error while generating the
shared secret key
\param key pointer to the DhKey structure to use to compute the shared key
\param agree pointer to the buffer in which to store the secret key
\param agreeSz will hold the size of the secret key after
successful generation
\param priv pointer to the buffer containing the local secret key
\param privSz size of the local secret key
\param otherPub pointer to a buffer containing the received public key
\param pubSz size of the received public key
_Example_
\code
DhKey key;
int ret;
byte priv[256];
byte agree[256];
word32 agreeSz;
// initialize key, set key prime and base
// wc_DhGenerateKeyPair -- store private key in priv
byte pub[] = { // initialized with the received public key };
ret = wc_DhAgree(&key, agree, &agreeSz, priv, sizeof(priv), pub,
sizeof(pub));
if ( ret != 0 ) {
// error generating shared key
}
\endcode
\sa wc_DhGenerateKeyPair
*/
int wc_DhAgree(DhKey* key, byte* agree, word32* agreeSz,
const byte* priv, word32 privSz, const byte* otherPub,
word32 pubSz);
/*!
\ingroup Diffie-Hellman
\brief This function decodes a Diffie-Hellman key from the given input
buffer containing the key in DER format. It stores the result in the
DhKey structure.
\return 0 Returned on successfully decoding the input key
\return ASN_PARSE_E Returned if there is an error parsing the sequence
of the input
\return ASN_DH_KEY_E Returned if there is an error reading the private
key parameters from the parsed input
\param input pointer to the buffer containing the DER formatted
Diffie-Hellman key
\param inOutIdx pointer to an integer in which to store the index parsed
to while decoding the key
\param key pointer to the DhKey structure to initialize with the input key
\param inSz length of the input buffer. Gives the max length that may
be read
_Example_
\code
DhKey key;
word32 idx = 0;
byte keyBuff[1024];
// initialize with DER formatted key
wc_DhKeyInit(&key);
ret = wc_DhKeyDecode(keyBuff, &idx, &key, sizeof(keyBuff));
if ( ret != 0 ) {
// error decoding key
}
\endcode
\sa wc_DhSetKey
*/
int wc_DhKeyDecode(const byte* input, word32* inOutIdx, DhKey* key,
word32);
/*!
\ingroup Diffie-Hellman
\brief This function sets the key for a DhKey structure using the input
private key parameters. Unlike wc_DhKeyDecode, this function does not
require that the input key be formatted in DER format, and instead simply
accepts the parsed input parameters p (prime) and g (base).
\return 0 Returned on successfully setting the key
\return BAD_FUNC_ARG Returned if any of the input parameters
evaluate to NULL
\return MP_INIT_E Returned if there is an error initializing the key
parameters for storage
\return ASN_DH_KEY_E Returned if there is an error reading in the
DH key parameters p and g
\param key pointer to the DhKey structure on which to set the key
\param p pointer to the buffer containing the prime for use with the key
\param pSz length of the input prime
\param g pointer to the buffer containing the base for use with the key
\param gSz length of the input base
_Example_
\code
DhKey key;
byte p[] = { // initialize with prime };
byte g[] = { // initialize with base };
wc_DhKeyInit(&key);
ret = wc_DhSetKey(key, p, sizeof(p), g, sizeof(g));
if ( ret != 0 ) {
// error setting key
}
\endcode
\sa wc_DhKeyDecode
*/
int wc_DhSetKey(DhKey* key, const byte* p, word32 pSz, const byte* g,
word32 gSz);
/*!
\ingroup Diffie-Hellman
\brief This function loads the Diffie-Hellman parameters, p (prime)
and g (base) out of the given input buffer, DER formatted.
\return 0 Returned on successfully extracting the DH parameters
\return ASN_PARSE_E Returned if an error occurs while parsing the DER
formatted DH certificate
\return BUFFER_E Returned if there is inadequate space in p or g to
store the parsed parameters
\param input pointer to a buffer containing a DER formatted
Diffie-Hellman certificate to parse
\param inSz size of the input buffer
\param p pointer to a buffer in which to store the parsed prime
\param pInOutSz pointer to a word32 object containing the available
size in the p buffer. Will be overwritten with the number of bytes
written to the buffer after completing the function call
\param g pointer to a buffer in which to store the parsed base
\param gInOutSz pointer to a word32 object containing the available size
in the g buffer. Will be overwritten with the number of bytes written to
the buffer after completing the function call
_Example_
\code
byte dhCert[] = { initialize with DER formatted certificate };
byte p[MAX_DH_SIZE];
byte g[MAX_DH_SIZE];
word32 pSz = MAX_DH_SIZE;
word32 gSz = MAX_DH_SIZE;
ret = wc_DhParamsLoad(dhCert, sizeof(dhCert), p, &pSz, g, &gSz);
if ( ret != 0 ) {
// error parsing inputs
}
\endcode
\sa wc_DhSetKey
\sa wc_DhKeyDecode
*/
int wc_DhParamsLoad(const byte* input, word32 inSz, byte* p,
word32* pInOutSz, byte* g, word32* gInOutSz);
/*!
\ingroup Diffie-Hellman
\brief This function returns ... and requires that HAVE_FFDHE_2048 be
defined.
\sa wc_Dh_ffdhe3072_Get
\sa wc_Dh_ffdhe4096_Get
\sa wc_Dh_ffdhe6144_Get
\sa wc_Dh_ffdhe8192_Get
*/
const DhParams* wc_Dh_ffdhe2048_Get(void);
/*!
\ingroup Diffie-Hellman
\brief This function returns ... and requires that HAVE_FFDHE_3072 be
defined.
\sa wc_Dh_ffdhe2048_Get
\sa wc_Dh_ffdhe4096_Get
\sa wc_Dh_ffdhe6144_Get
\sa wc_Dh_ffdhe8192_Get
*/
const DhParams* wc_Dh_ffdhe3072_Get(void);
/*!
\ingroup Diffie-Hellman
\brief This function returns ... and requires that HAVE_FFDHE_4096 be
defined.
\sa wc_Dh_ffdhe2048_Get
\sa wc_Dh_ffdhe3072_Get
\sa wc_Dh_ffdhe6144_Get
\sa wc_Dh_ffdhe8192_Get
*/
const DhParams* wc_Dh_ffdhe4096_Get(void);
/*!
\ingroup Diffie-Hellman
\brief This function returns ... and requires that HAVE_FFDHE_6144 be
defined.
\sa wc_Dh_ffdhe2048_Get
\sa wc_Dh_ffdhe3072_Get
\sa wc_Dh_ffdhe4096_Get
\sa wc_Dh_ffdhe8192_Get
*/
const DhParams* wc_Dh_ffdhe6144_Get(void);
/*!
\ingroup Diffie-Hellman
\brief This function returns ... and requires that HAVE_FFDHE_8192 be
defined.
\sa wc_Dh_ffdhe2048_Get
\sa wc_Dh_ffdhe3072_Get
\sa wc_Dh_ffdhe4096_Get
\sa wc_Dh_ffdhe6144_Get
*/
const DhParams* wc_Dh_ffdhe8192_Get(void);
/*!
\ingroup Diffie-Hellman
\brief Checks DH keys for pair-wise consistency per process in SP 800-56Ar3,
section 5.6.2.1.4, method (b) for FFC.
*/
int wc_DhCheckKeyPair(DhKey* key, const byte* pub, word32 pubSz,
const byte* priv, word32 privSz);
/*!
\ingroup Diffie-Hellman
\brief Check DH private key for invalid numbers
*/
int wc_DhCheckPrivKey(DhKey* key, const byte* priv, word32 pubSz);
/*!
\ingroup Diffie-Hellman
*/
int wc_DhCheckPrivKey_ex(DhKey* key, const byte* priv, word32 pubSz,
const byte* prime, word32 primeSz);
/*!
\ingroup Diffie-Hellman
*/
int wc_DhCheckPubKey(DhKey* key, const byte* pub, word32 pubSz);
/*!
\ingroup Diffie-Hellman
*/
int wc_DhCheckPubKey_ex(DhKey* key, const byte* pub, word32 pubSz,
const byte* prime, word32 primeSz);
/*!
\ingroup Diffie-Hellman
*/
int wc_DhExportParamsRaw(DhKey* dh, byte* p, word32* pSz,
byte* q, word32* qSz, byte* g, word32* gSz);
/*!
\ingroup Diffie-Hellman
*/
int wc_DhGenerateParams(WC_RNG *rng, int modSz, DhKey *dh);
/*!
\ingroup Diffie-Hellman
*/
int wc_DhSetCheckKey(DhKey* key, const byte* p, word32 pSz,
const byte* g, word32 gSz, const byte* q, word32 qSz,
int trusted, WC_RNG* rng);
/*!
\ingroup Diffie-Hellman
*/
int wc_DhSetKey_ex(DhKey* key, const byte* p, word32 pSz,
const byte* g, word32 gSz, const byte* q, word32 qSz);
/*!
\ingroup Diffie-Hellman
*/
int wc_FreeDhKey(DhKey* key);

View File

@@ -0,0 +1,244 @@
/*!
\defgroup 3DES Algorithms - 3DES
\defgroup AES Algorithms - AES
\defgroup ARC4 Algorithms - ARC4
\defgroup BLAKE2 Algorithms - BLAKE2
\defgroup Camellia Algorithms - Camellia
\defgroup ChaCha Algorithms - ChaCha
\defgroup ChaCha20Poly1305 Algorithms - ChaCha20_Poly1305
\defgroup CMAC Algorithm - CMAC
\defgroup Crypto Callbacks - CryptoCb
\defgroup Curve25519 Algorithms - Curve25519
\defgroup Curve448 Algorithms - Curve448
\defgroup DSA Algorithms - DSA
\defgroup Diffie-Hellman Algorithms - Diffie-Hellman
\defgroup ECC Algorithms - ECC
\defgroup ED25519 Algorithms - ED25519
\defgroup ED448 Algorithms - ED448
\defgroup ECCSI_Overview Overview of ECCSI
ECCSI (Elliptic Curve-Based Certificateless Signatures for Identity-Based Encryption) is specified in RFC 6507 (https://tools.ietf.org/html/rfc6507).
In Identity-Based cryptography, there is a Key Management Service that generates keys based on an identity for a client.
The private key (SSK) and public key (PVT) are delivered to the signer and the public key (PVT) only delivered to the verifier on request.\n\n
wolfCrypt offers the ability to:
-# Create KMS keys,
-# Generate signing key pairs,
-# Validate signing key pairs,
-# Sign messages and
-# Verify messages.
KMS:
-# Initialize ECCSI Key: wc_InitEccsiKey()
-# Make and save or load ECCSI Key:
-# wc_MakeEccsiKey(), wc_ExportEccsiKey(), wc_ExportEccsiPublicKey() or
-# wc_ImportEccsiKey()
-# Wait for request:
-# Receive signing ID from client.
-# Generate signing key pair from ID: wc_MakeEccsiPair()
-# Encode result:
-# For signer, signing key pair: wc_EncodeEccsiPair()
-# Send KPAK and result
-# Free ECCSI Key: wc_FreeEccsiKey()
Client, signer:
-# Initialize ECCSI Key: wc_InitEccsiKey()
-# (When signing pair not cached) Request KPAK and signing pair from KMS
-# Send signing ID to KMS.
-# Receive signing key pair from KMS.
-# Load KMS Public Key: wc_ImportEccsiPublicKey()
-# Decode signing key pair: wc_DecodeEccsiPair()
-# Validate the key pair: wc_ValidateEccsiPair()
-# (If not done above) Load KMS Public Key: wc_ImportEccsiPublicKey()
-# (If not cached) Calculate hash of the ID and PVT: wc_HashEccsiId()
-# For each message:
-# Set Hash of Identity: wc_SetEccsiHash()
-# Sign message: wc_SignEccsiHash()
-# Send hash ID, message and signature to peer.
-# Free ECCSI Key: wc_FreeEccsiKey()
Client, verifier:
-# Receive hash ID, message and signature from signer.
-# Request KPAK (if not cached) and PVT (if not cached) for hash ID from KMS.
-# Receive KPAK (if not cached) and PVT (if not cached) for hash ID from KMS.
-# Initialize ECCSI Key: wc_InitEccsiKey()
-# Load KMS Public Key: wc_ImportEccsiPublicKey()
-# Decode PVT: wc_DecodeEccsiPvtFromSig()
-# Calculate hash of the ID and PVT: wc_HashEccsiId()
-# Set ECCSI key pair: wc_SetEccsiPair()
-# Verify signature of message: wc_VerifyEccsiHash()
-# Free ECCSI Key: wc_FreeEccsiKey()
\defgroup ECCSI_Setup Setup ECCSI Key
Operations for establinshing an ECCSI key.
Initialize ECCSI Key before use (wc_InitEccsiKey()).\n
Initialize ECCSI Key before use (wc_InitEccsiKey_ex()) for use with a curve other than P256.\n
Either make a new key (wc_MakeEccsiKey()), import an existing key (wc_ImportEccsiKey()) or import existing private key (wc_ImportEccsiPrivateKey()) and public key (wc_ImportEccsiPublicKey()).\n
Export the key (wc_ExportEccsiKey()) after making a new key for future use.\n
Export the private key (wc_ExportEccsiPrivateKey()) after making a new key for future use.\n
Export the public key (wc_ExportEccsiPublicKey()) from KMS to pass to client.\n
Import the public key (wc_ImportEccsiPublicKey()) into client.\n
Free the ECCSI Key (wc_FreeEccsiKey()) when finished.
\defgroup ECCSI_Operations Operations for Signing and Verifying with ECCSI Key
These operations are for signing and verifying with ECCSI keys.
Make an ECCSI key pair (wc_MakeEccsiPair()) with the signer's ID for use when signing.\n
Validate the ECCSI key pair (wc_ValidateEccsiPair()) with the signer's ID.\n
Validate the ECCSI Public Validation Token (PVT) (wc_ValidateEccsiPvt()).\n
Encode the ECCSI key pair (wc_EncodeEccsiPair()) for transfer to client.\n
Encode the ECCSI SSK (wc_EncodeEccsiSsk()) for transfer to client.\n
Encode the ECCSI PVT (wc_EncodeEccsiPvt()) for transfer to verifier.\n
Decode the ECCSI key pair (wc_DecodeEccsiPair()) on client for signing.\n
Decode the ECCSI SSK (wc_DecodeEccsiSsk()) on client for signing.\n
Decode the ECCSI PVT (wc_DecodeEccsiPvt()) on client for signing.\n
Decode the ECCSI PVT from the signature (wc_DecodeEccsiPvtFromSig()) on client for verifying.\n
Calculate hash of the ID (wc_HashEccsiId()) for signing/verifying using ID and Public Validation Token (PVT).\n
Sign (wc_SignEccsiHash()) a message with the hash of the ID and the Secret Signing Key (SSK) and Public Validation Token (PVT).\n
Verify (wc_VerifyEccsiHash()) a message with the hash of the signer's ID.
\defgroup SAKKE_Overview Overview of SAKKE Key
SAKKE (Sakai-Kasahara Key Encryption) is specified in RFC 6508 (https://tools.ietf.org/html/rfc6508).
SAKKE is used to transfer a secret to a peer using Identity Based cryptography.\n
The Key Management Service (KMS) is responsible for issuing Receiver Secret %Keys (RSKs).
Data up to (2^hashlen)^hashlen bytes of data can be transferred.\n
The sender must know the identity of the receiver and the KMS Public Key.\n
The receiver must have obtained a Receiver Secret Key (RSK) for the identity from a KMS in order to derive the secret.
KMS:
-# Initialize SAKKE Key: wc_InitSakkeKey()
-# Make and save or load SAKKE Key:
-# wc_MakeSakkeKey(), wc_ExportSakkeKey(), wc_ExportSakkePublicKey() or
-# wc_ImportSakkeKey()
-# Wait for request:
-# Make an RSK base on ID for the client: wc_MakeSakkeRsk()
-# Encode RSK for transfer to client: wc_EncodeSakkeRsk()
-# Free SAKKE Key: wc_FreeSakkeKey()
Key Exchange, Peer A:
-# Initialize SAKKE Key: wc_InitSakkeKey()
-# Load KMS Public Key: wc_ImportSakkePublicKey()
-# Generate a random SSV: wc_GenerateSakkeSSV()
-# Set the identity of Peer B: wc_SetSakkeIdentity()
-# Make an encapsulated SSV and auth data: wc_MakeSakkeEncapsulatedSSV()
-# Send encapsulated data to Peer B
-# Free SAKKE Key: wc_FreeSakkeKey()
Key Exchange, Peer B:
-# Receive encapsulated data.
-# Initialize SAKKE Key: wc_InitSakkeKey()
-# Load KMS Public Key: wc_ImportSakkePublicKey()
-# Decode RSK transferred from KMS or stored locally: wc_DecodeSakkeRsk()
-# [Optional] Validate RSK before first use: wc_ValidateSakkeRsk()
-# Set the identity: wc_SetSakkeIdentity()
-# Set the RSK and, optionally precomputation table: wc_SetSakkeRsk()
-# Derive SSV with auth data: wc_DeriveSakkeSSV()
-# Free SAKKE Key: wc_FreeSakkeKey()
Transfer secret, Peer A:
-# Initialize SAKKE Key: wc_InitSakkeKey()
-# Load KMS Public Key: wc_ImportSakkePublicKey()
-# Set the identity of Peer B: wc_SetSakkeIdentity()
-# Make an encapsulation of the SSV and auth data: wc_MakeSakkeEncapsulatedSSV()
-# Send encapsulated data to Peer B
-# Free SAKKE Key: wc_FreeSakkeKey()
Transfer secret, Peer B:
-# Initialize SAKKE Key: wc_InitSakkeKey()
-# Load KMS Public Key: wc_ImportSakkePublicKey()
-# Decode RSK transferred from KMS or stored locally: wc_DecodeSakkeRsk()
-# [Optional] Validate RSK before first use: wc_ValidateSakkeRsk()
-# Receive encapsulated data.
-# Set the identity: wc_SetSakkeIdentity()
-# Set the RSK and, optionally precomputation table: wc_SetSakkeRsk()
-# Derive SSV and auth data: wc_DeriveSakkeSSV()
-# Free SAKKE Key: wc_FreeSakkeKey()
\defgroup SAKKE_Setup Setup SAKKE Key
Operations for establishing a SAKKE key.
Initialization SAKKE Key before use (wc_InitSakkeKey() or wc_InitSakkeKey_ex()).\n
Either make a new key (wc_MakeSakkeKey()) or import an existing key (wc_ImportSakkeKey()).\n
Export the key (wc_ExportSakkeKey()) after making a new key for future use.\n
If only the private part of the KMS SAKKE Key is available, make the public key (wc_MakeSakkePublicKey()).\n
Export the private key (wc_ExportSakkePrivateKey()) from KMS from storage.\n
Import the private key (wc_ImportSakkePrivateKey()) into KMS from storage.\n
Export the public key (wc_ExportSakkePublicKey()) from KMS to pass to client.\n
Import the public key (wc_ImportSakkePublicKey()) into client.\n
Set the identity to use (wc_SetSakkeIdentity()) into client.\n
Free the SAKKE Key (wc_FreeSakkeKey()) when finished.
\defgroup SAKKE_RSK Operations on/with SAKKE RSK
These operations make, validate, encode and decode a Receiver Secret Key (RSK).
An RSK is required to derive an SSV (see wc_DeriveSakkeSSV()).\n
On the KMS, make an RSK (wc_MakeSakkeRsk()) from the client's ID.\n
On the client, validate the RSK (wc_ValidateSakkeRsk()) with the ID.\n
Encode the RSK (wc_EncodeSakkeRsk()) to pass to client or for storage.\n
Decode the RSK (wc_DecodeSakkeRsk()) on the client when needed.\n
Import the RSK (wc_ImportSakkeRsk()) on the client when needed.\n
Set the RSK and, optionally, a pre-computation table (wc_SetSakkeRsk()) on the client when needed.
\defgroup SAKKE_Operations Operations using SAKKE Key
These operations transfer a Shared Secret Value (SSV) from one client to another. The SSV may be randomly generated.
Calculate the size of the authentication data (wc_GetSakkeAuthSize()) to determine where the SSV starts in a buffer.\n
Make the intermediate point I (wc_MakeSakkePointI()) to speed making an encapsulated and deriving SSV.\n
Get intermediate point I (wc_GetSakkePointI()) for storage.\n
Set intermediate point I (wc_SetSakkePointI()) from storage.\n
Generate a pre-computation table for intermediate point I (wc_GenerateSakkePointITable()) to further enhance performance. Store as necessary.\n
Set the pre-computation table for intermediate point I (wc_SetSakkePointITable()) to further enhance performance.\n
Clear the pre-computation table for intermediate point I (wc_ClearSakkePointITable()) to remove reference to external table pointer.\n
Make an encapsulated SSV (wc_MakeSakkeEncapsulatedSSV()) to share with another client. Data in SSV is modified.\n
Generate a random SSV (wc_GenerateSakkeSSV()) for key exchange.\n
Derive the SSV, (wc_DeriveSakkeSSV()) on the recipient from the encapsulated SSV.
\defgroup HMAC Algorithms - HMAC
\defgroup MD2 Algorithms - MD2
\defgroup MD4 Algorithms - MD4
\defgroup MD5 Algorithms - MD5
\defgroup PKCS7 Algorithms - PKCS7
\defgroup PKCS11 Algorithms - PKCS11
\defgroup Password Algorithms - Password Based
\defgroup Poly1305 Algorithms - Poly1305
\defgroup RIPEMD Algorithms - RIPEMD
\defgroup RSA Algorithms - RSA
\defgroup SHA Algorithms - SHA 128/224/256/384/512
\defgroup SipHash Algorithm - SipHash
\defgroup SRP Algorithms - SRP
\defgroup ASN ASN.1
\defgroup Base_Encoding Base Encoding
\defgroup CertManager CertManager API
\defgroup Compression Compression
\defgroup Error Error Reporting
\defgroup IoTSafe IoT-Safe Module
IoT-Safe (IoT-SIM Applet For Secure End-2-End Communication) is a technology that leverage the SIM as robust,
scalable and standardized hardware Root of Trust to protect data communication.
IoT-Safe SSL sessions use the SIM as Hardware Security Module, offloading all the crypto public
key operations and reducing the attack surface by restricting access to certificate and keys
to the SIM.
IoT-Safe support can be enabled on an existing WOLFSSL_CTX contex, using wolfSSL_CTX_iotsafe_enable().\n
Session created within the context can set the parameters for IoT-Safe key and files usage, and enable
the public keys callback, with wolfSSL_iotsafe_on().
If compiled in, the module supports IoT-Safe random number generator as source of entropy for wolfCrypt.
\defgroup PSA Platform Security Architecture (PSA) API
\defgroup Keys Key and Cert Conversion
\defgroup Logging Logging
\defgroup Math Math API
\defgroup Memory Memory Handling
\defgroup Random Random Number Generation
\defgroup Signature Signature API
\defgroup openSSL OpenSSL API
\defgroup wolfCrypt wolfCrypt Init and Cleanup
\defgroup TLS wolfSSL Initialization/Shutdown
\defgroup CertsKeys wolfSSL Certificates and Keys
\defgroup Setup wolfSSL Context and Session Set Up
\defgroup IO wolfSSL Connection, Session, and I/O
\defgroup Debug wolfSSL Error Handling and Reporting
*/

View File

@@ -0,0 +1,76 @@
/*!
\page wolfssl_API wolfSSL API Reference
- \ref CertManager
- \ref Memory
- \ref openSSL
- \ref CertsKeys
- \ref IO
- \ref Setup
- \ref Debug
- \ref TLS
*/
/*!
\page wolfcrypt_API wolfCrypt API Reference
<ul>
<li>\ref ASN</li>
<li>\ref Base_Encoding</li>
<li>\ref Compression</li>
<li>\ref Error</li>
<li>\ref IoTSafe</li>
<li>\ref PSA</li>
<li>\ref Keys</li>
<li>\ref Logging</li>
<li>\ref Math</li>
<li>\ref Random</li>
<li>\ref Signature</li>
<li>\ref wolfCrypt</li>
</ul>
<ul>
<li>\ref DES</li>
<li>\ref AES</li>
<li>\ref ARC4</li>
<li>\ref BLAKE2</li>
<li>\ref Camellia</li>
<li>\ref ChaCha</li>
<li>\ref ChaCha20Poly1305</li>
<li>\ref CMAC</li>
<li>\ref Crypto Callbacks</li>
<li>\ref Curve25519</li>
<li>\ref Curve448</li>
<li>\ref DSA</li>
<li>\ref Diffie-Hellman</li>
<li>\ref ECC</li>
<li>\ref ED25519</li>
<li>\ref ED448</li>
<li>\ref ECCSI</li>
<li>\ref SAKKE</li>
<li>\ref HMAC</li>
<li>\ref MD2</li>
<li>\ref MD4</li>
<li>\ref MD5</li>
<li>\ref Password</li>
<li>\ref PKCS7</li>
<li>\ref PKCS11</li>
<li>\ref Poly1305</li>
<li>\ref RIPEMD</li>
<li>\ref RSA</li>
<li>\ref SHA</li>
<li>\ref SipHash</li>
<li>\ref SRP</li>
</ul>
*/
/*!
\page ECCSI ECCSI API Reference
- \ref ECCSI_Overview
- \ref ECCSI_Setup
- \ref ECCSI_Operations
*/
/*!
\page SAKKE SAKKE API Reference
- \ref SAKKE_Overview
- \ref SAKKE_Setup
- \ref SAKKE_RSK
- \ref SAKKE_Operations
*/

View File

@@ -0,0 +1,342 @@
/*!
\ingroup DSA
\brief This function initializes a DsaKey object in order to use it for
authentication via the Digital Signature Algorithm (DSA).
\return 0 Returned on success.
\return BAD_FUNC_ARG Returned if a NULL key is passed in.
\param key pointer to the DsaKey structure to initialize
_Example_
\code
DsaKey key;
int ret;
ret = wc_InitDsaKey(&key); // initialize DSA key
\endcode
\sa wc_FreeDsaKey
*/
int wc_InitDsaKey(DsaKey* key);
/*!
\ingroup DSA
\brief This function frees a DsaKey object after it has been used.
\return none No returns.
\param key pointer to the DsaKey structure to free
_Example_
\code
DsaKey key;
// initialize key, use for authentication
...
wc_FreeDsaKey(&key); // free DSA key
\endcode
\sa wc_FreeDsaKey
*/
void wc_FreeDsaKey(DsaKey* key);
/*!
\ingroup DSA
\brief This function signs the input digest and stores the result in the
output buffer, out.
\return 0 Returned on successfully signing the input digest
\return MP_INIT_E may be returned if there is an error in processing the
DSA signature.
\return MP_READ_E may be returned if there is an error in processing the
DSA signature.
\return MP_CMP_E may be returned if there is an error in processing the
DSA signature.
\return MP_INVMOD_E may be returned if there is an error in processing the
DSA signature.
\return MP_EXPTMOD_E may be returned if there is an error in processing
the DSA signature.
\return MP_MOD_E may be returned if there is an error in processing the
DSA signature.
\return MP_MUL_E may be returned if there is an error in processing the
DSA signature.
\return MP_ADD_E may be returned if there is an error in processing the
DSA signature.
\return MP_MULMOD_E may be returned if there is an error in processing
the DSA signature.
\return MP_TO_E may be returned if there is an error in processing the
DSA signature.
\return MP_MEM may be returned if there is an error in processing the
DSA signature.
\param digest pointer to the hash to sign
\param out pointer to the buffer in which to store the signature
\param key pointer to the initialized DsaKey structure with which to
generate the signature
\param rng pointer to an initialized RNG to use with the signature
generation
_Example_
\code
DsaKey key;
// initialize DSA key, load private Key
int ret;
WC_RNG rng;
wc_InitRng(&rng);
byte hash[] = { // initialize with hash digest };
byte signature[40]; // signature will be 40 bytes (320 bits)
ret = wc_DsaSign(hash, signature, &key, &rng);
if (ret != 0) {
// error generating DSA signature
}
\endcode
\sa wc_DsaVerify
*/
int wc_DsaSign(const byte* digest, byte* out,
DsaKey* key, WC_RNG* rng);
/*!
\ingroup DSA
\brief This function verifies the signature of a digest, given a private
key. It stores whether the key properly verifies in the answer parameter,
with 1 corresponding to a successful verification, and 0 corresponding to
failed verification.
\return 0 Returned on successfully processing the verify request. Note:
this does not mean that the signature is verified, only that the function
succeeded
\return MP_INIT_E may be returned if there is an error in processing the
DSA signature.
\return MP_READ_E may be returned if there is an error in processing the
DSA signature.
\return MP_CMP_E may be returned if there is an error in processing the
DSA signature.
\return MP_INVMOD_E may be returned if there is an error in processing
the DSA signature.
\return MP_EXPTMOD_E may be returned if there is an error in processing
the DSA signature.
\return MP_MOD_E may be returned if there is an error in processing the
DSA signature.
\return MP_MUL_E may be returned if there is an error in processing the
DSA signature.
\return MP_ADD_E may be returned if there is an error in processing the
DSA signature.
\return MP_MULMOD_E may be returned if there is an error in processing
the DSA signature.
\return MP_TO_E may be returned if there is an error in processing the
DSA signature.
\return MP_MEM may be returned if there is an error in processing the
DSA signature.
\param digest pointer to the digest containing the subject of the signature
\param sig pointer to the buffer containing the signature to verify
\param key pointer to the initialized DsaKey structure with which to
verify the signature
\param answer pointer to an integer which will store whether the
verification was successful
_Example_
\code
DsaKey key;
// initialize DSA key, load public Key
int ret;
int verified;
byte hash[] = { // initialize with hash digest };
byte signature[] = { // initialize with signature to verify };
ret = wc_DsaVerify(hash, signature, &key, &verified);
if (ret != 0) {
// error processing verify request
} else if (answer == 0) {
// invalid signature
}
\endcode
\sa wc_DsaSign
*/
int wc_DsaVerify(const byte* digest, const byte* sig,
DsaKey* key, int* answer);
/*!
\ingroup DSA
\brief This function decodes a DER formatted certificate buffer containing
a DSA public key, and stores the key in the given DsaKey structure. It
also sets the inOutIdx parameter according to the length of the input read.
\return 0 Returned on successfully setting the public key for the DsaKey
object
\return ASN_PARSE_E Returned if there is an error in the encoding while
reading the certificate buffer
\return ASN_DH_KEY_E Returned if one of the DSA parameters is incorrectly
formatted
\param input pointer to the buffer containing the DER formatted DSA
public key
\param inOutIdx pointer to an integer in which to store the final index
of the certificate read
\param key pointer to the DsaKey structure in which to store the public key
\param inSz size of the input buffer
_Example_
\code
int ret, idx=0;
DsaKey key;
wc_InitDsaKey(&key);
byte derBuff[] = { // DSA public key};
ret = wc_DsaPublicKeyDecode(derBuff, &idx, &key, inSz);
if (ret != 0) {
// error reading public key
}
\endcode
\sa wc_InitDsaKey
\sa wc_DsaPrivateKeyDecode
*/
int wc_DsaPublicKeyDecode(const byte* input, word32* inOutIdx,
DsaKey* key, word32 inSz);
/*!
\ingroup DSA
\brief This function decodes a DER formatted certificate buffer containing
a DSA private key, and stores the key in the given DsaKey structure. It
also sets the inOutIdx parameter according to the length of the input read.
\return 0 Returned on successfully setting the private key for the DsaKey
object
\return ASN_PARSE_E Returned if there is an error in the encoding while
reading the certificate buffer
\return ASN_DH_KEY_E Returned if one of the DSA parameters is incorrectly
formatted
\param input pointer to the buffer containing the DER formatted DSA
private key
\param inOutIdx pointer to an integer in which to store the final index
of the certificate read
\param key pointer to the DsaKey structure in which to store the private
key
\param inSz size of the input buffer
_Example_
\code
int ret, idx=0;
DsaKey key;
wc_InitDsaKey(&key);
byte derBuff[] = { // DSA private key };
ret = wc_DsaPrivateKeyDecode(derBuff, &idx, &key, inSz);
if (ret != 0) {
// error reading private key
}
\endcode
\sa wc_InitDsaKey
\sa wc_DsaPublicKeyDecode
*/
int wc_DsaPrivateKeyDecode(const byte* input, word32* inOutIdx,
DsaKey* key, word32 inSz);
/*!
\ingroup DSA
\brief Convert DsaKey key to DER format, write to output (inLen),
return bytes written.
\return outLen Success, number of bytes written
\return BAD_FUNC_ARG key or output are null or key->type is not
DSA_PRIVATE.
\return MEMORY_E Error allocating memory.
\param key Pointer to DsaKey structure to convert.
\param output Pointer to output buffer for converted key.
\param inLen Length of key input.
_Example_
\code
DsaKey key;
WC_RNG rng;
int derSz;
int bufferSize = // Sufficient buffer size;
byte der[bufferSize];
wc_InitDsaKey(&key);
wc_InitRng(&rng);
wc_MakeDsaKey(&rng, &key);
derSz = wc_DsaKeyToDer(&key, der, bufferSize);
\endcode
\sa wc_InitDsaKey
\sa wc_FreeDsaKey
\sa wc_MakeDsaKey
*/
int wc_DsaKeyToDer(DsaKey* key, byte* output, word32 inLen);
/*!
\ingroup DSA
\brief Create a DSA key.
\return MP_OKAY Success
\return BAD_FUNC_ARG Either rng or dsa is null.
\return MEMORY_E Couldn't allocate memory for buffer.
\return MP_INIT_E Error initializing mp_int
\param rng Pointer to WC_RNG structure.
\param dsa Pointer to DsaKey structure.
_Example_
\code
WC_RNG rng;
DsaKey dsa;
wc_InitRng(&rng);
wc_InitDsa(&dsa);
if(wc_MakeDsaKey(&rng, &dsa) != 0)
{
// Error creating key
}
\endcode
\sa wc_InitDsaKey
\sa wc_FreeDsaKey
\sa wc_DsaSign
*/
int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa);
/*!
\ingroup DSA
\brief FIPS 186-4 defines valid for modulus_size values as
(1024, 160) (2048, 256) (3072, 256)
\return 0 Success
\return BAD_FUNC_ARG rng or dsa is null or modulus_size is invalid.
\return MEMORY_E Error attempting to allocate memory.
\param rng pointer to wolfCrypt rng.
\param modulus_size 1024, 2048, or 3072 are valid values.
\param dsa Pointer to a DsaKey structure.
_Example_
\code
DsaKey key;
WC_RNG rng;
wc_InitDsaKey(&key);
wc_InitRng(&rng);
if(wc_MakeDsaParameters(&rng, 1024, &genKey) != 0)
{
// Handle error
}
\endcode
\sa wc_MakeDsaKey
\sa wc_DsaKeyToDer
\sa wc_InitDsaKey
*/
int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,131 @@
/*!
\ingroup ECCSI_Setup
*/
int wc_InitEccsiKey(EccsiKey* key, void* heap, int devId);
/*!
\ingroup ECCSI_Setup
*/
int wc_InitEccsiKey_ex(EccsiKey* key, int keySz, int curveId,
void* heap, int devId);
/*!
\ingroup ECCSI_Setup
*/
void wc_FreeEccsiKey(EccsiKey* key);
/*!
\ingroup ECCSI_Setup
*/
int wc_MakeEccsiKey(EccsiKey* key, WC_RNG* rng);
/*!
\ingroup ECCSI_Operations
*/
int wc_MakeEccsiPair(EccsiKey* key, WC_RNG* rng,
enum wc_HashType hashType, const byte* id, word32 idSz, mp_int* ssk,
ecc_point* pvt);
/*!
\ingroup ECCSI_Operations
*/
int wc_ValidateEccsiPair(EccsiKey* key, enum wc_HashType hashType,
const byte* id, word32 idSz, const mp_int* ssk, ecc_point* pvt,
int* valid);
/*!
\ingroup ECCSI_Operations
*/
int wc_ValidateEccsiPvt(EccsiKey* key, const ecc_point* pvt,
int* valid);
/*!
\ingroup ECCSI_Operations
*/
int wc_EncodeEccsiPair(const EccsiKey* key, mp_int* ssk,
ecc_point* pvt, byte* data, word32* sz);
/*!
\ingroup ECCSI_Operations
*/
int wc_EncodeEccsiSsk(const EccsiKey* key, mp_int* ssk, byte* data,
word32* sz);
/*!
\ingroup ECCSI_Operations
*/
int wc_EncodeEccsiPvt(const EccsiKey* key, ecc_point* pvt,
byte* data, word32* sz, int raw);
/*!
\ingroup ECCSI_Operations
*/
int wc_DecodeEccsiPair(const EccsiKey* key, const byte* data,
word32 sz, mp_int* ssk, ecc_point* pvt);
/*!
\ingroup ECCSI_Operations
*/
int wc_DecodeEccsiSsk(const EccsiKey* key, const byte* data,
word32 sz, mp_int* ssk);
/*!
\ingroup ECCSI_Operations
*/
int wc_DecodeEccsiPvt(const EccsiKey* key, const byte* data,
word32 sz, ecc_point* pvt);
/*!
\ingroup ECCSI_Operations
*/
int wc_DecodeEccsiPvtFromSig(const EccsiKey* key, const byte* sig,
word32 sz, ecc_point* pvt);
/*!
\ingroup ECCSI_Setup
*/
int wc_ExportEccsiKey(EccsiKey* key, byte* data, word32* sz);
/*!
\ingroup ECCSI_Setup
*/
int wc_ImportEccsiKey(EccsiKey* key, const byte* data, word32 sz);
/*!
\ingroup ECCSI_Setup
*/
int wc_ExportEccsiPrivateKey(EccsiKey* key, byte* data, word32* sz);
/*!
\ingroup ECCSI_Setup
*/
int wc_ImportEccsiPrivateKey(EccsiKey* key, const byte* data,
word32 sz);
/*!
\ingroup ECCSI_Setup
*/
int wc_ExportEccsiPublicKey(EccsiKey* key, byte* data, word32* sz,
int raw);
/*!
\ingroup ECCSI_Setup
*/
int wc_ImportEccsiPublicKey(EccsiKey* key, const byte* data,
word32 sz, int trusted);
/*!
\ingroup ECCSI_Operations
*/
int wc_HashEccsiId(EccsiKey* key, enum wc_HashType hashType,
const byte* id, word32 idSz, ecc_point* pvt, byte* hash, byte* hashSz);
/*!
\ingroup ECCSI_Setup
*/
int wc_SetEccsiHash(EccsiKey* key, const byte* hash, byte hashSz);
/*!
\ingroup ECCSI_Setup
*/
int wc_SetEccsiPair(EccsiKey* key, const mp_int* ssk,
const ecc_point* pvt);
/*!
\ingroup ECCSI_Operations
*/
int wc_SignEccsiHash(EccsiKey* key, WC_RNG* rng,
enum wc_HashType hashType, const byte* msg, word32 msgSz, byte* sig,
word32* sigSz);
/*!
\ingroup ECCSI_Operations
*/
int wc_VerifyEccsiHash(EccsiKey* key, enum wc_HashType hashType,
const byte* msg, word32 msgSz, const byte* sig, word32 sigSz,
int* verified);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,968 @@
/*!
\ingroup ED448
\brief This function generates the Ed448 public key from the private key.
It stores the public key in the buffer pubKey, and sets the bytes
written to this buffer in pubKeySz.
\return 0 Returned upon successfully making the public key.
\return BAD_FUNC_ARG Returned ifi key or pubKey evaluate to NULL, or if the
specified key size is not 57 bytes (Ed448 has 57 byte keys).
\return MEMORY_E Returned if there is an error allocating memory
during function execution.
\param [in] key Pointer to the ed448_key for which to generate a key.
\param [out] out Pointer to the buffer in which to store the public key.
\param [in,out] outLen Pointer to a word32 object with the size available
in out. Set with the number of bytes written to out after successfully
exporting the public key.
_Example_
\code
int ret;
ed448_key key;
byte priv[] = { initialize with 57 byte private key };
byte pub[57];
word32 pubSz = sizeof(pub);
wc_ed448_init(&key);
wc_ed448_import_private_only(priv, sizeof(priv), &key);
ret = wc_ed448_make_public(&key, pub, &pubSz);
if (ret != 0) {
// error making public key
}
\endcode
\sa wc_ed448_init
\sa wc_ed448_import_private_only
\sa wc_ed448_make_key
*/
int wc_ed448_make_public(ed448_key* key, unsigned char* pubKey,
word32 pubKeySz);
/*!
\ingroup ED448
\brief This function generates a new Ed448 key and stores it in key.
\return 0 Returned upon successfully making an ed448_key.
\return BAD_FUNC_ARG Returned if rng or key evaluate to NULL, or if the
specified key size is not 57 bytes (Ed448 has 57 byte keys).
\return MEMORY_E Returned if there is an error allocating memory
during function execution.
\param [in] rng Pointer to an initialized RNG object with which to
generate the key.
\param [in] keysize Length of key to generate. Should always be 57 for
Ed448.
\param [in,out] key Pointer to the ed448_key for which to generate a key.
_Example_
\code
int ret;
WC_RNG rng;
ed448_key key;
wc_InitRng(&rng);
wc_ed448_init(&key);
ret = wc_ed448_make_key(&rng, 57, &key);
if (ret != 0) {
// error making key
}
\endcode
\sa wc_ed448_init
*/
int wc_ed448_make_key(WC_RNG* rng, int keysize, ed448_key* key);
/*!
\ingroup ED448
\brief This function signs a message using an ed448_key object
to guarantee authenticity.
\return 0 Returned upon successfully generating a signature for the
message.
\return BAD_FUNC_ARG Returned if any of the input parameters evaluate to
NULL, or if the output buffer is too small to store the generated signature.
\return MEMORY_E Returned if there is an error allocating memory during
function execution.
\param [in] in Pointer to the buffer containing the message to sign.
\param [in] inlen Length of the message to sign.
\param [out] out Buffer in which to store the generated signature.
\param [in,out] outlen Maximum length of the output buffer. Will store the
bytes written to out upon successfully generating a message signature.
\param [in] key Pointer to a private ed448_key with which to generate the
signature.
_Example_
\code
ed448_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[114]; // will hold generated signature
sigSz = sizeof(sig);
byte message[] = { initialize with message };
wc_InitRng(&rng); // initialize rng
wc_ed448_init(&key); // initialize key
wc_ed448_make_key(&rng, 57, &key); // make public/private key pair
ret = wc_ed448_sign_msg(message, sizeof(message), sig, &sigSz, &key);
if (ret != 0 ) {
// error generating message signature
}
\endcode
\sa wc_ed448ph_sign_hash
\sa wc_ed448ph_sign_msg
\sa wc_ed448_verify_msg
*/
int wc_ed448_sign_msg(const byte* in, word32 inlen, byte* out,
word32 *outlen, ed448_key* key);
/*!
\ingroup ED448
\brief This function signs a message digest using an ed448_key object
to guarantee authenticity. The context is included as part of the data
signed. The hash is the pre-hashed message before signature calculation.
The hash algorithm used to create message digest must be SHAKE-256.
\return 0 Returned upon successfully generating a signature for the
message digest.
\return BAD_FUNC_ARG Returned any of the input parameters evaluate to
NULL, or if the output buffer is too small to store the generated signature.
\return MEMORY_E Returned if there is an error allocating memory during
function execution.
\param [in] hash Pointer to the buffer containing the hash of the message
to sign.
\param [in] hashLen Length of the hash of the message to sign.
\param [out] out Buffer in which to store the generated signature.
\param [in,out] outlen Maximum length of the output buffer. Will store the
bytes written to out upon successfully generating a message signature.
\param [in] key Pointer to a private ed448_key with which to generate the
signature.
\param [in] context Pointer to the buffer containing the context for which
message is being signed.
\param [in] contextLen Length of the context buffer.
_Example_
\code
ed448_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[114]; // will hold generated signature
sigSz = sizeof(sig);
byte hash[] = { initialize with SHAKE-256 hash of message };
byte context[] = { initialize with context of signing };
wc_InitRng(&rng); // initialize rng
wc_ed448_init(&key); // initialize key
wc_ed448_make_key(&rng, 57, &key); // make public/private key pair
ret = wc_ed448ph_sign_hash(hash, sizeof(hash), sig, &sigSz, &key,
context, sizeof(context));
if (ret != 0) {
// error generating message signature
}
\endcode
\sa wc_ed448_sign_msg
\sa wc_ed448ph_sign_msg
\sa wc_ed448ph_verify_hash
*/
int wc_ed448ph_sign_hash(const byte* hash, word32 hashLen, byte* out,
word32 *outLen, ed448_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED448
\brief This function signs a message using an ed448_key object
to guarantee authenticity. The context is included as part of the data
signed. The message is pre-hashed before signature calculation.
\return 0 Returned upon successfully generating a signature for the
message.
\return BAD_FUNC_ARG Returned any of the input parameters evaluate to
NULL, or if the output buffer is too small to store the generated signature.
\return MEMORY_E Returned if there is an error allocating memory during
function execution.
\param [in] in Pointer to the buffer containing the message to sign.
\param [in] inlen Length of the message to sign.
\param [out] out Buffer in which to store the generated signature.
\param [in,out] outlen Maximum length of the output buffer. Will store the
bytes written to out upon successfully generating a message signature.
\param [in] key Pointer to a private ed448_key with which to generate the
signature.
\param [in] context Pointer to the buffer containing the context for which
message is being signed.
\param [in] contextLen Length of the context buffer.
_Example_
\code
ed448_key key;
WC_RNG rng;
int ret, sigSz;
byte sig[114]; // will hold generated signature
sigSz = sizeof(sig);
byte message[] = { initialize with message };
byte context[] = { initialize with context of signing };
wc_InitRng(&rng); // initialize rng
wc_ed448_init(&key); // initialize key
wc_ed448_make_key(&rng, 57, &key); // make public/private key pair
ret = wc_ed448ph_sign_msg(message, sizeof(message), sig, &sigSz, &key,
context, sizeof(context));
if (ret != 0) {
// error generating message signature
}
\endcode
\sa wc_ed448_sign_msg
\sa wc_ed448ph_sign_hash
\sa wc_ed448ph_verify_msg
*/
int wc_ed448ph_sign_msg(const byte* in, word32 inLen, byte* out,
word32 *outLen, ed448_key* key, const byte* context,
byte contextLen);
/*!
\ingroup ED448
\brief This function verifies the Ed448 signature of a message to ensure
authenticity. The context is included as part of the data
verified. The answer is returned through res, with 1 corresponding to
a valid signature, and 0 corresponding to an invalid signature.
\return 0 Returned upon successfully performing the signature
verification and authentication.
\return BAD_FUNC_ARG Returned if any of the input parameters evaluate to
NULL, or if the siglen does not match the actual length of a signature.
\return SIG_VERIFY_E Returned if verification completes, but the signature
generated does not match the signature provided.
\param [in] sig Pointer to the buffer containing the signature to verify.
\param [in] siglen Length of the signature to verify.
\param [in] msg Pointer to the buffer containing the message to verify.
\param [in] msgLen Length of the message to verify.
\param [in] key Pointer to a public Ed448 key with which to verify the
signature.
\param [in] context Pointer to the buffer containing the context for which
the message was signed.
\param [in] contextLen Length of the context buffer.
_Example_
\code
ed448_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte msg[] = { initialize with message };
byte context[] = { initialize with context of signature };
// initialize key with received public key
ret = wc_ed448_verify_msg(sig, sizeof(sig), msg, sizeof(msg), &verified,
&key, context, sizeof(context));
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
\endcode
\sa wc_ed448ph_verify_hash
\sa wc_ed448ph_verify_msg
\sa wc_ed448_sign_msg
*/
int wc_ed448_verify_msg(const byte* sig, word32 siglen, const byte* msg,
word32 msgLen, int* res, ed448_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED448
\brief This function verifies the Ed448 signature of the digest of a message
to ensure authenticity. The context is included as part of the data
verified. The hash is the pre-hashed message before signature calculation.
The hash algorithm used to create message digest must be SHAKE-256.
The answer is returned through res, with 1 corresponding to a valid
signature, and 0 corresponding to an invalid signature.
\return 0 Returned upon successfully performing the signature
verification and authentication.
\return BAD_FUNC_ARG Returned if any of the input parameters evaluate to
NULL, or if the siglen does not match the actual length of a signature.
\return SIG_VERIFY_E Returned if verification completes, but the signature
generated does not match the signature provided.
\param [in] sig Pointer to the buffer containing the signature to verify.
\param [in] siglen Length of the signature to verify.
\param [in] hash Pointer to the buffer containing the hash of the message
to verify.
\param [in] hashLen Length of the hash to verify.
\param [in] key Pointer to a public Ed448 key with which to verify the
signature.
\param [in] context Pointer to the buffer containing the context for which
the message was signed.
\param [in] contextLen Length of the context buffer.
_Example_
\code
ed448_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte hash[] = { initialize with SHAKE-256 hash of message };
byte context[] = { initialize with context of signature };
// initialize key with received public key
ret = wc_ed448ph_verify_hash(sig, sizeof(sig), hash, sizeof(hash),
&verified, &key, context, sizeof(context));
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
\endcode
\sa wc_ed448_verify_msg
\sa wc_ed448ph_verify_msg
\sa wc_ed448ph_sign_hash
*/
int wc_ed448ph_verify_hash(const byte* sig, word32 siglen, const byte* hash,
word32 hashlen, int* res, ed448_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED448
\brief This function verifies the Ed448 signature of a message to ensure
authenticity. The context is included as part of the data
verified. The message is pre-hashed before verification. The answer is
returned through res, with 1 corresponding to a valid signature, and 0
corresponding to an invalid signature.
\return 0 Returned upon successfully performing the signature
verification and authentication.
\return BAD_FUNC_ARG Returned if any of the input parameters evaluate to
NULL, or if the siglen does not match the actual length of a signature.
\return SIG_VERIFY_E Returned if verification completes, but the signature
generated does not match the signature provided.
\param [in] sig Pointer to the buffer containing the signature to verify.
\param [in] siglen Length of the signature to verify.
\param [in] msg Pointer to the buffer containing the message to verify.
\param [in] msgLen Length of the message to verify.
\param [in] key Pointer to a public Ed448 key with which to verify the
signature.
\param [in] context Pointer to the buffer containing the context for which
the message was signed.
\param [in] contextLen Length of the context buffer.
_Example_
\code
ed448_key key;
int ret, verified = 0;
byte sig[] { initialize with received signature };
byte msg[] = { initialize with message };
byte context[] = { initialize with context of signature };
// initialize key with received public key
ret = wc_ed448ph_verify_msg(sig, sizeof(sig), msg, sizeof(msg), &verified,
&key, context, sizeof(context));
if (ret < 0) {
// error performing verification
} else if (verified == 0)
// the signature is invalid
}
\endcode
\sa wc_ed448_verify_msg
\sa wc_ed448ph_verify_hash
\sa wc_ed448ph_sign_msg
*/
int wc_ed448ph_verify_msg(const byte* sig, word32 siglen, const byte* msg,
word32 msgLen, int* res, ed448_key* key,
const byte* context, byte contextLen);
/*!
\ingroup ED448
\brief This function initializes an ed448_key object for future use
with message verification.
\return 0 Returned upon successfully initializing the ed448_key object.
\return BAD_FUNC_ARG Returned if key is NULL.
\param [in,out] key Pointer to the ed448_key object to initialize.
_Example_
\code
ed448_key key;
wc_ed448_init(&key);
\endcode
\sa wc_ed448_make_key
\sa wc_ed448_free
*/
int wc_ed448_init(ed448_key* key);
/*!
\ingroup ED448
\brief This function frees an Ed448 object after it has been used.
\param [in,out] key Pointer to the ed448_key object to free
_Example_
\code
ed448_key key;
// initialize key and perform secure exchanges
...
wc_ed448_free(&key);
\endcode
\sa wc_ed448_init
*/
void wc_ed448_free(ed448_key* key);
/*!
\ingroup ED448
\brief This function imports a public ed448_key pair from a buffer
containing the public key. This function will handle both compressed and
uncompressed keys. The public key is checked that it matches the private
key when one is present.
\return 0 Returned on successfully importing the ed448_key.
\return BAD_FUNC_ARG Returned if in or key evaluate to NULL, or inLen is
less than the size of an Ed448 key.
\param [in] in Pointer to the buffer containing the public key.
\param [in] inLen Length of the buffer containing the public key.
\param [in,out] key Pointer to the ed448_key object in which to store the
public key.
_Example_
\code
int ret;
byte pub[] = { initialize Ed448 public key };
ed_448 key;
wc_ed448_init_key(&key);
ret = wc_ed448_import_public(pub, sizeof(pub), &key);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_ed448_import_public_ex
\sa wc_ed448_import_private_key
\sa wc_ed448_import_private_key_ex
\sa wc_ed448_export_public
*/
int wc_ed448_import_public(const byte* in, word32 inLen, ed448_key* key);
/*!
\ingroup ED448
\brief This function imports a public ed448_key pair from a buffer
containing the public key. This function will handle both compressed and
uncompressed keys. Check public key matches private key, when present,
when not trusted.
\return 0 Returned on successfully importing the ed448_key.
\return BAD_FUNC_ARG Returned if in or key evaluate to NULL, or inLen is
less than the size of an Ed448 key.
\param [in] in Pointer to the buffer containing the public key.
\param [in] inLen Length of the buffer containing the public key.
\param [in,out] key Pointer to the ed448_key object in which to store the
public key.
\param [in] trusted Public key data is trusted or not.
_Example_
\code
int ret;
byte pub[] = { initialize Ed448 public key };
ed_448 key;
wc_ed448_init_key(&key);
ret = wc_ed448_import_public_ex(pub, sizeof(pub), &key, 1);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_ed448_import_public
\sa wc_ed448_import_private_key
\sa wc_ed448_import_private_key_ex
\sa wc_ed448_export_public
*/
int wc_ed448_import_public_ex(const byte* in, word32 inLen, ed448_key* key,
int trusted);
/*!
\ingroup ED448
\brief This function imports an Ed448 private key only from a
buffer.
\return 0 Returned on successfully importing the Ed448 private key.
\return BAD_FUNC_ARG Returned if in or key evaluate to NULL, or if
privSz is less than ED448_KEY_SIZE.
\param [in] priv Pointer to the buffer containing the private key.
\param [in] privSz Length of the private key.
\param [in,out] key Pointer to the ed448_key object in which to store the
imported private key.
_Example_
\code
int ret;
byte priv[] = { initialize with 57 byte private key };
ed448_key key;
wc_ed448_init_key(&key);
ret = wc_ed448_import_private_only(priv, sizeof(priv), &key);
if (ret != 0) {
// error importing private key
}
\endcode
\sa wc_ed448_import_public
\sa wc_ed448_import_public_ex
\sa wc_ed448_import_private_key
\sa wc_ed448_import_private_key_ex
\sa wc_ed448_export_private_only
*/
int wc_ed448_import_private_only(const byte* priv, word32 privSz,
ed448_key* key);
/*!
\ingroup ED448
\brief This function imports a public/private Ed448 key pair from a
pair of buffers. This function will handle both compressed and
uncompressed keys.
\return 0 Returned on successfully importing the Ed448 key.
\return BAD_FUNC_ARG Returned if in or key evaluate to NULL, or if
either privSz is less than ED448_KEY_SIZE or pubSz is less than
ED448_PUB_KEY_SIZE.
\param [in] priv Pointer to the buffer containing the private key.
\param [in] privSz Length of the private key.
\param [in] pub Pointer to the buffer containing the public key.
\param [in] pubSz Length of the public key.
\param [in,out] key Pointer to the ed448_key object in which to store the
imported private/public key pair.
_Example_
\code
int ret;
byte priv[] = { initialize with 57 byte private key };
byte pub[] = { initialize with the corresponding public key };
ed448_key key;
wc_ed448_init_key(&key);
ret = wc_ed448_import_private_key(priv, sizeof(priv), pub, sizeof(pub),
&key);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_ed448_import_public
\sa wc_ed448_import_public_ex
\sa wc_ed448_import_private_only
\sa wc_ed448_import_private_key_ex
\sa wc_ed448_export_private
*/
int wc_ed448_import_private_key(const byte* priv, word32 privSz,
const byte* pub, word32 pubSz, ed448_key* key);
/*!
\ingroup ED448
\brief This function imports a public/private Ed448 key pair from a
pair of buffers. This function will handle both compressed and
uncompressed keys. The public is checked against private key if not trusted.
\return 0 Returned on successfully importing the Ed448 key.
\return BAD_FUNC_ARG Returned if in or key evaluate to NULL, or if
either privSz is less than ED448_KEY_SIZE or pubSz is less than
ED448_PUB_KEY_SIZE.
\param [in] priv Pointer to the buffer containing the private key.
\param [in] privSz Length of the private key.
\param [in] pub Pointer to the buffer containing the public key.
\param [in] pubSz Length of the public key.
\param [in,out] key Pointer to the ed448_key object in which to store the
imported private/public key pair.
\param [in] trusted Public key data is trusted or not.
_Example_
\code
int ret;
byte priv[] = { initialize with 57 byte private key };
byte pub[] = { initialize with the corresponding public key };
ed448_key key;
wc_ed448_init_key(&key);
ret = wc_ed448_import_private_key_ex(priv, sizeof(priv), pub, sizeof(pub),
&key, 1);
if (ret != 0) {
// error importing key
}
\endcode
\sa wc_ed448_import_public
\sa wc_ed448_import_public_ex
\sa wc_ed448_import_private_only
\sa wc_ed448_import_private_key
\sa wc_ed448_export_private
*/
int wc_ed448_import_private_key_ex(const byte* priv, word32 privSz,
const byte* pub, word32 pubSz, ed448_key* key, int trusted);
/*!
\ingroup ED448
\brief This function exports the private key from an ed448_key
structure. It stores the public key in the buffer out, and sets the bytes
written to this buffer in outLen.
\return 0 Returned upon successfully exporting the public key.
\return BAD_FUNC_ARG Returned if any of the input values evaluate to NULL.
\return BUFFER_E Returned if the buffer provided is not large enough to
store the private key. Upon returning this error, the function sets the
size required in outLen.
\param [in] key Pointer to an ed448_key structure from which to export the
public key.
\param [out] out Pointer to the buffer in which to store the public key.
\param [in,out] outLen Pointer to a word32 object with the size available
in out. Set with the number of bytes written to out after successfully
exporting the public key.
_Example_
\code
int ret;
ed448_key key;
// initialize key, make key
char pub[57];
word32 pubSz = sizeof(pub);
ret = wc_ed448_export_public(&key, pub, &pubSz);
if (ret != 0) {
// error exporting public key
}
\endcode
\sa wc_ed448_import_public
\sa wc_ed448_import_public_ex
\sa wc_ed448_export_private_only
*/
int wc_ed448_export_public(ed448_key* key, byte* out, word32* outLen);
/*!
\ingroup ED448
\brief This function exports only the private key from an ed448_key
structure. It stores the private key in the buffer out, and sets
the bytes written to this buffer in outLen.
\return 0 Returned upon successfully exporting the private key.
\return ECC_BAD_ARG_E Returned if any of the input values evaluate to NULL.
\return BUFFER_E Returned if the buffer provided is not large enough
to store the private key.
\param [in] key Pointer to an ed448_key structure from which to export
the private key.
\param [out] out Pointer to the buffer in which to store the private key.
\param [in,out] outLen Pointer to a word32 object with the size available in
out. Set with the number of bytes written to out after successfully
exporting the private key.
_Example_
\code
int ret;
ed448_key key;
// initialize key, make key
char priv[57]; // 57 bytes because only private key
word32 privSz = sizeof(priv);
ret = wc_ed448_export_private_only(&key, priv, &privSz);
if (ret != 0) {
// error exporting private key
}
\endcode
\sa wc_ed448_export_public
\sa wc_ed448_import_private_key
\sa wc_ed448_import_private_key_ex
*/
int wc_ed448_export_private_only(ed448_key* key, byte* out, word32* outLen);
/*!
\ingroup ED448
\brief This function exports the key pair from an ed448_key
structure. It stores the key pair in the buffer out, and sets
the bytes written to this buffer in outLen.
\return 0 Returned upon successfully exporting the key pair.
\return ECC_BAD_ARG_E Returned if any of the input values evaluate to NULL.
\return BUFFER_E Returned if the buffer provided is not large enough
to store the key pair.
\param [in] key Pointer to an ed448_key structure from which to export
the key pair.
\param [out] out Pointer to the buffer in which to store the key pair.
\param [in,out] outLen Pointer to a word32 object with the size available in
out. Set with the number of bytes written to out after successfully
exporting the key pair.
_Example_
\code
ed448_key key;
wc_ed448_init(&key);
WC_RNG rng;
wc_InitRng(&rng);
wc_ed448_make_key(&rng, 57, &key); // initialize 57 byte Ed448 key
byte out[114]; // out needs to be a sufficient buffer size
word32 outLen = sizeof(out);
int key_size = wc_ed448_export_private(&key, out, &outLen);
if (key_size == BUFFER_E) {
// Check size of out compared to outLen to see if function reset outLen
}
\endcode
\sa wc_ed448_import_private
\sa wc_ed448_export_private_only
*/
int wc_ed448_export_private(ed448_key* key, byte* out, word32* outLen);
/*!
\ingroup ED448
\brief This function exports the private and public key separately from an
ed448_key structure. It stores the private key in the buffer priv, and sets
the bytes written to this buffer in privSz. It stores the public key in the
buffer pub, and sets the bytes written to this buffer in pubSz.
\return 0 Returned upon successfully exporting the key pair.
\return ECC_BAD_ARG_E Returned if any of the input values evaluate to NULL.
\return BUFFER_E Returned if the buffer provided is not large enough
to store the key pair.
\param [in] key Pointer to an ed448_key structure from which to export
the key pair.
\param [out] priv Pointer to the buffer in which to store the private key.
\param [in,out] privSz Pointer to a word32 object with the size available in
out. Set with the number of bytes written to out after successfully
exporting the private key.
\param [out] pub Pointer to the buffer in which to store the public key.
\param [in,out] pubSz Pointer to a word32 object with the size available in
out. Set with the number of bytes written to out after successfully
exporting the public key.
_Example_
\code
int ret;
ed448_key key;
// initialize key, make key
char pub[57];
word32 pubSz = sizeof(pub);
char priv[57];
word32 privSz = sizeof(priv);
ret = wc_ed448_export_key(&key, priv, &pubSz, pub, &pubSz);
if (ret != 0) {
// error exporting private and public key
}
\endcode
\sa wc_ed448_export_private
\sa wc_ed448_export_public
*/
int wc_ed448_export_key(ed448_key* key,
byte* priv, word32 *privSz,
byte* pub, word32 *pubSz);
/*!
\ingroup ED448
\brief This function checks the public key in ed448_key structure matches
the private key.
\return 0 Returned if the private and public key matched.
\return BAD_FUNC_ARGS Returned if the given key is NULL.
\param [in] key Pointer to an ed448_key structure holding a private and
public key.
_Example_
\code
int ret;
byte priv[] = { initialize with 57 byte private key };
byte pub[] = { initialize with the corresponding public key };
ed448_key key;
wc_ed448_init_key(&key);
wc_ed448_import_private_key_ex(priv, sizeof(priv), pub, sizeof(pub), &key,
1);
ret = wc_ed448_check_key(&key);
if (ret != 0) {
// error checking key
}
\endcode
\sa wc_ed448_import_private_key
\sa wc_ed448_import_private_key_ex
*/
int wc_ed448_check_key(ed448_key* key);
/*!
\ingroup ED448
\brief This function returns the size of an Ed448 private key - 57 bytes.
\return ED448_KEY_SIZE The size of a valid private key (57 bytes).
\return BAD_FUNC_ARGS Returned if the given key is NULL.
\param [in] key Pointer to an ed448_key structure for which to get the
key size.
_Example_
\code
int keySz;
ed448_key key;
// initialize key, make key
keySz = wc_ed448_size(&key);
if (keySz == 0) {
// error determining key size
}
\endcode
\sa wc_ed448_make_key
*/
int wc_ed448_size(ed448_key* key);
/*!
\ingroup ED448
\brief This function returns the private key size (secret + public) in
bytes.
\return ED448_PRV_KEY_SIZE The size of the private key (114 bytes).
\return BAD_FUNC_ARG Returns if key argument is NULL.
\param [in] key Pointer to an ed448_key structure for which to get the
key size.
_Example_
\code
ed448_key key;
wc_ed448_init(&key);
WC_RNG rng;
wc_InitRng(&rng);
wc_ed448_make_key(&rng, 57, &key); // initialize 57 byte Ed448 key
int key_size = wc_ed448_priv_size(&key);
\endcode
\sa wc_ed448_pub_size
*/
int wc_ed448_priv_size(ed448_key* key);
/*!
\ingroup ED448
\brief This function returns the compressed key size in bytes (public key).
\return ED448_PUB_KEY_SIZE The size of the compressed public key (57 bytes).
\return BAD_FUNC_ARG Returns if key argument is NULL.
\param [in] key Pointer to an ed448_key structure for which to get the
key size.
_Example_
\code
ed448_key key;
wc_ed448_init(&key);
WC_RNG rng;
wc_InitRng(&rng);
wc_ed448_make_key(&rng, 57, &key); // initialize 57 byte Ed448 key
int key_size = wc_ed448_pub_size(&key);
\endcode
\sa wc_ed448_priv_size
*/
int wc_ed448_pub_size(ed448_key* key);
/*!
\ingroup ED448
\brief This function returns the size of an Ed448 signature (114 in bytes).
\return ED448_SIG_SIZE The size of an Ed448 signature (114 bytes).
\return BAD_FUNC_ARG Returns if key argument is NULL.
\param [in] key Pointer to an ed448_key structure for which to get the
signature size.
_Example_
\code
int sigSz;
ed448_key key;
// initialize key, make key
sigSz = wc_ed448_sig_size(&key);
if (sigSz == 0) {
// error determining sig size
}
\endcode
\sa wc_ed448_sign_msg
*/
int wc_ed448_sig_size(ed448_key* key);

View File

@@ -0,0 +1,49 @@
/*!
\ingroup Error
\brief This function stores the error string for a particular error code
in the given buffer.
\return none No returns.
\param error error code for which to get the string
\param buffer buffer in which to store the error string. Buffer should be
at least WOLFSSL_MAX_ERROR_SZ (80 bytes) long
_Example_
\code
char errorMsg[WOLFSSL_MAX_ERROR_SZ];
int err = wc_some_function();
if( err != 0) { // error occurred
wc_ErrorString(err, errorMsg);
}
\endcode
\sa wc_GetErrorString
*/
void wc_ErrorString(int err, char* buff);
/*!
\ingroup Error
\brief This function returns the error string for a particular error code.
\return string Returns the error string for an error code as a
string literal.
\param error error code for which to get the string
_Example_
\code
char * errorMsg;
int err = wc_some_function();
if( err != 0) { // error occurred
errorMsg = wc_GetErrorString(err);
}
\endcode
\sa wc_ErrorString
*/
const char* wc_GetErrorString(int error);

View File

@@ -0,0 +1,444 @@
/*!
\ingroup openSSL
\brief Getter functions for the respective WOLFSSL_EVP_CIPHER pointers.
wolfSSL_EVP_init() must be called once in the program first to populate
these cipher strings. WOLFSSL_DES_ECB macro must be defined for
wolfSSL_EVP_des_ede3_ecb().
\return pointer Returns a WOLFSSL_EVP_CIPHER pointer for DES EDE3 operations.
\param none No parameters.
_Example_
\code
printf("block size des ede3 cbc = %d\n",
wolfSSL_EVP_CIPHER_block_size(wolfSSL_EVP_des_ede3_cbc()));
printf("block size des ede3 ecb = %d\n",
wolfSSL_EVP_CIPHER_block_size(wolfSSL_EVP_des_ede3_ecb()));
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_init
*/
const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_des_ede3_ecb(void);
/*!
\ingroup openSSL
\brief Getter functions for the respective WOLFSSL_EVP_CIPHER pointers.
wolfSSL_EVP_init() must be called once in the program first to populate
these cipher strings. WOLFSSL_DES_ECB macro must be defined for
wolfSSL_EVP_des_ecb().
\return pointer Returns a WOLFSSL_EVP_CIPHER pointer for DES operations.
\param none No parameters.
_Example_
\code
WOLFSSL_EVP_CIPHER* cipher;
cipher = wolfSSL_EVP_des_cbc();
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_init
*/
const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_des_cbc(void);
/*!
\ingroup openSSL
\brief Function for initializing WOLFSSL_EVP_MD_CTX. This function is a
wrapper for wolfSSL_EVP_DigestInit() because wolfSSL does not
use WOLFSSL_ENGINE.
\return SSL_SUCCESS If successfully set.
\return SSL_FAILURE If not successful.
\param ctx structure to initialize.
\param type type of hash to do, for example SHA.
\param impl engine to use. N/A for wolfSSL, can be NULL.
_Example_
\code
WOLFSSL_EVP_MD_CTX* md = NULL;
wolfCrypt_Init();
md = wolfSSL_EVP_MD_CTX_new();
if (md == NULL) {
printf("error setting md\n");
return -1;
}
printf("cipher md init ret = %d\n", wolfSSL_EVP_DigestInit_ex(md,
wolfSSL_EVP_sha1(), e));
//free resources
\endcode
\sa wolfSSL_EVP_MD_CTX_new
\sa wolfCrypt_Init
\sa wolfSSL_EVP_MD_CTX_free
*/
int wolfSSL_EVP_DigestInit_ex(WOLFSSL_EVP_MD_CTX* ctx,
const WOLFSSL_EVP_MD* type,
WOLFSSL_ENGINE *impl);
/*!
\ingroup openSSL
\brief Function for initializing WOLFSSL_EVP_CIPHER_CTX. This function is a
wrapper for wolfSSL_CipherInit() because wolfSSL does not
use WOLFSSL_ENGINE.
\return SSL_SUCCESS If successfully set.
\return SSL_FAILURE If not successful.
\param ctx structure to initialize.
\param type type of encryption/decryption to do, for example AES.
\param impl engine to use. N/A for wolfSSL, can be NULL.
\param key key to set .
\param iv iv if needed by algorithm.
\param enc encryption (1) or decryption (0) flag.
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx = NULL;
WOLFSSL_ENGINE* e = NULL;
unsigned char key[16];
unsigned char iv[12];
wolfCrypt_Init();
ctx = wolfSSL_EVP_CIPHER_CTX_new();
if (ctx == NULL) {
printf("issue creating ctx\n");
return -1;
}
printf("cipher init ex error ret = %d\n", wolfSSL_EVP_CipherInit_ex(NULL,
EVP_aes_128_ cbc(), e, key, iv, 1));
printf("cipher init ex success ret = %d\n", wolfSSL_EVP_CipherInit_ex(ctx,
EVP_aes_128_c bc(), e, key, iv, 1));
// free resources
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
\sa wolfCrypt_Init
\sa wolfSSL_EVP_CIPHER_CTX_free
*/
int wolfSSL_EVP_CipherInit_ex(WOLFSSL_EVP_CIPHER_CTX* ctx,
const WOLFSSL_EVP_CIPHER* type,
WOLFSSL_ENGINE *impl,
const unsigned char* key,
const unsigned char* iv,
int enc);
/*!
\ingroup openSSL
\brief Function for initializing WOLFSSL_EVP_CIPHER_CTX. This function is a
wrapper for wolfSSL_EVP_CipherInit() because wolfSSL does not use
WOLFSSL_ENGINE. Sets encrypt flag to be encrypt.
\return SSL_SUCCESS If successfully set.
\return SSL_FAILURE If not successful.
\param ctx structure to initialize.
\param type type of encryption to do, for example AES.
\param impl engine to use. N/A for wolfSSL, can be NULL.
\param key key to use.
\param iv iv to use.
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx = NULL;
wolfCrypt_Init();
ctx = wolfSSL_EVP_CIPHER_CTX_new();
if (ctx == NULL) {
printf("error setting ctx\n");
return -1;
}
printf("cipher ctx init ret = %d\n", wolfSSL_EVP_EncryptInit_ex(ctx,
wolfSSL_EVP_aes_128_cbc(), e, key, iv));
//free resources
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
\sa wolfCrypt_Init
\sa wolfSSL_EVP_CIPHER_CTX_free
*/
int wolfSSL_EVP_EncryptInit_ex(WOLFSSL_EVP_CIPHER_CTX* ctx,
const WOLFSSL_EVP_CIPHER* type,
WOLFSSL_ENGINE *impl,
const unsigned char* key,
const unsigned char* iv);
/*!
\ingroup openSSL
\brief Function for initializing WOLFSSL_EVP_CIPHER_CTX. This function is a
wrapper for wolfSSL_EVP_CipherInit() because wolfSSL does not use
WOLFSSL_ENGINE. Sets encrypt flag to be decrypt.
\return SSL_SUCCESS If successfully set.
\return SSL_FAILURE If not successful.
\param ctx structure to initialize.
\param type type of encryption/decryption to do, for example AES.
\param impl engine to use. N/A for wolfSSL, can be NULL.
\param key key to set .
\param iv iv if needed by algorithm.
\param enc encryption (1) or decryption (0) flag.
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx = NULL;
WOLFSSL_ENGINE* e = NULL;
unsigned char key[16];
unsigned char iv[12];
wolfCrypt_Init();
ctx = wolfSSL_EVP_CIPHER_CTX_new();
if (ctx == NULL) {
printf("issue creating ctx\n");
return -1;
}
printf("cipher init ex error ret = %d\n", wolfSSL_EVP_DecryptInit_ex(NULL,
EVP_aes_128_ cbc(), e, key, iv, 1));
printf("cipher init ex success ret = %d\n", wolfSSL_EVP_DecryptInit_ex(ctx,
EVP_aes_128_c bc(), e, key, iv, 1));
// free resources
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
\sa wolfCrypt_Init
\sa wolfSSL_EVP_CIPHER_CTX_free
*/
int wolfSSL_EVP_DecryptInit_ex(WOLFSSL_EVP_CIPHER_CTX* ctx,
const WOLFSSL_EVP_CIPHER* type,
WOLFSSL_ENGINE *impl,
const unsigned char* key,
const unsigned char* iv);
/*!
\ingroup openSSL
\brief Function for encrypting/decrypting data. In buffer is added to be
encrypted or decrypted and out buffer holds the results. outl will be the
length of encrypted/decrypted information.
\return SSL_SUCCESS If successful.
\return SSL_FAILURE If not successful.
\param ctx structure to get cipher type from.
\param out buffer to hold output.
\param outl adjusted to be size of output.
\param in buffer to perform operation on.
\param inl length of input buffer.
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx = NULL;
unsigned char out[100];
int outl;
unsigned char in[100];
int inl = 100;
ctx = wolfSSL_EVP_CIPHER_CTX_new();
// set up ctx
ret = wolfSSL_EVP_CipherUpdate(ctx, out, outl, in, inl);
// check ret value
// buffer out holds outl bytes of data
// free resources
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
\sa wolfCrypt_Init
\sa wolfSSL_EVP_CIPHER_CTX_free
*/
int wolfSSL_EVP_CipherUpdate(WOLFSSL_EVP_CIPHER_CTX *ctx,
unsigned char *out, int *outl,
const unsigned char *in, int inl);
/*!
\ingroup openSSL
\brief This function performs the final cipher operations adding in
padding. If WOLFSSL_EVP_CIPH_NO_PADDING flag is set in
WOLFSSL_EVP_CIPHER_CTX structure then 1 is returned and no
encryption/decryption is done. If padding flag is seti padding is added and
encrypted when ctx is set to encrypt, padding values are checked when set
to decrypt.
\return 1 Returned on success.
\return 0 If encountering a failure.
\param ctx structure to decrypt/encrypt with.
\param out buffer for final decrypt/encrypt.
\param out1 size of out buffer when data has been added by function.
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx;
int out1;
unsigned char out[64];
// create ctx
wolfSSL_EVP_CipherFinal(ctx, out, &out1);
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
*/
int wolfSSL_EVP_CipherFinal(WOLFSSL_EVP_CIPHER_CTX *ctx,
unsigned char *out, int *outl);
/*!
\ingroup openSSL
\brief Setter function for WOLFSSL_EVP_CIPHER_CTX structure key length.
\return SSL_SUCCESS If successfully set.
\return SSL_FAILURE If failed to set key length.
\param ctx structure to set key length.
\param keylen key length.
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx;
int keylen;
// create ctx
wolfSSL_EVP_CIPHER_CTX_set_key_length(ctx, keylen);
\endcode
\sa wolfSSL_EVP_CIPHER_flags
*/
int wolfSSL_EVP_CIPHER_CTX_set_key_length(WOLFSSL_EVP_CIPHER_CTX* ctx,
int keylen);
/*!
\ingroup openSSL
\brief This is a getter function for the ctx block size.
\return size Returns ctx->block_size.
\param ctx the cipher ctx to get block size of.
_Example_
\code
const WOLFSSL_CVP_CIPHER_CTX* ctx;
//set up ctx
printf(“block size = %d\n”, wolfSSL_EVP_CIPHER_CTX_block_size(ctx));
\endcode
\sa wolfSSL_EVP_CIPHER_block_size
*/
int wolfSSL_EVP_CIPHER_CTX_block_size(const WOLFSSL_EVP_CIPHER_CTX *ctx);
/*!
\ingroup openSSL
\brief This is a getter function for the block size of cipher.
\return size returns the block size.
\param cipher cipher to get block size of.
_Example_
\code
printf(“block size = %d\n”,
wolfSSL_EVP_CIPHER_block_size(wolfSSL_EVP_aes_256_ecb()));
\endcode
\sa wolfSSL_EVP_aes_256_ctr
*/
int wolfSSL_EVP_CIPHER_block_size(const WOLFSSL_EVP_CIPHER *cipher);
/*!
\ingroup openSSL
\brief Setter function for WOLFSSL_EVP_CIPHER_CTX structure.
\return none No returns.
\param ctx structure to set flag.
\param flag flag to set in structure.
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx;
int flag;
// create ctx
wolfSSL_EVP_CIPHER_CTX_set_flags(ctx, flag);
\endcode
\sa wolfSSL_EVP_CIPHER_flags
\sa wolfSSL_EVP_CIPHER_CTX_flags
*/
void wolfSSL_EVP_CIPHER_CTX_set_flags(WOLFSSL_EVP_CIPHER_CTX *ctx, int flags);
/*!
\ingroup openSSL
\brief Clearing function for WOLFSSL_EVP_CIPHER_CTX structure.
\return none No returns.
\param ctx structure to clear flag.
\param flag flag value to clear in structure.
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx;
int flag;
// create ctx
wolfSSL_EVP_CIPHER_CTX_clear_flags(ctx, flag);
\endcode
\sa wolfSSL_EVP_CIPHER_flags
\sa wolfSSL_EVP_CIPHER_CTX_flags
*/
void wolfSSL_EVP_CIPHER_CTX_clear_flags(WOLFSSL_EVP_CIPHER_CTX *ctx, int flags);
/*!
\ingroup openSSL
\brief Setter function for WOLFSSL_EVP_CIPHER_CTX structure to use padding.
\return SSL_SUCCESS If successfully set.
\return BAD_FUNC_ARG If null argument passed in.
\param ctx structure to set padding flag.
\param padding 0 for not setting padding, 1 for setting padding.
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx;
// create ctx
wolfSSL_EVP_CIPHER_CTX_set_padding(ctx, 1);
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
*/
int wolfSSL_EVP_CIPHER_CTX_set_padding(WOLFSSL_EVP_CIPHER_CTX *c, int pad);
/*!
\ingroup openSSL
\brief Getter function for WOLFSSL_EVP_CIPHER_CTX structure. Deprecated v1.1.0
\return unsigned long of flags/mode.
\param ctx structure to get flag.
_Example_
\code
WOLFSSL_EVP_CIPHER_CTX* ctx;
unsigned long flags;
ctx = wolfSSL_EVP_CIPHER_CTX_new()
flags = wolfSSL_EVP_CIPHER_CTX_flags(ctx);
\endcode
\sa wolfSSL_EVP_CIPHER_CTX_new
\sa wolfSSL_EVP_CIPHER_flags
*/
unsigned long wolfSSL_EVP_CIPHER_CTX_flags(const WOLFSSL_EVP_CIPHER_CTX *ctx);

View File

@@ -0,0 +1,396 @@
/*!
\ingroup wolfCrypt
\brief This function will return the OID for the wc_HashType provided.
\return OID returns value greater than 0
\return HASH_TYPE_E hash type not supported.
\return BAD_FUNC_ARG one of the provided arguments is incorrect.
\param hash_type A hash type from the “enum wc_HashType” such
as “WC_HASH_TYPE_SHA256”.
_Example_
\code
enum wc_HashType hash_type = WC_HASH_TYPE_SHA256;
int oid = wc_HashGetOID(hash_type);
if (oid > 0) {
// Success
}
\endcode
\sa wc_HashGetDigestSize
\sa wc_Hash
*/
int wc_HashGetOID(enum wc_HashType hash_type);
/*!
\ingroup wolfCrypt
\brief This function returns the size of the digest (output) for a
hash_type. The returns size is used to make sure the output buffer
provided to wc_Hash is large enough.
\return Success A positive return value indicates the digest size
for the hash.
\return Error Returns HASH_TYPE_E if hash_type is not supported.
\return Failure Returns BAD_FUNC_ARG if an invalid hash_type was used.
\param hash_type A hash type from the “enum wc_HashType” such as
“WC_HASH_TYPE_SHA256”.
_Example_
\code
int hash_len = wc_HashGetDigestSize(hash_type);
if (hash_len <= 0) {
WOLFSSL_MSG("Invalid hash type/len");
return BAD_FUNC_ARG;
}
\endcode
\sa wc_Hash
*/
int wc_HashGetDigestSize(enum wc_HashType hash_type);
/*!
\ingroup wolfCrypt
\brief This function performs a hash on the provided data buffer
and returns it in the hash buffer provided.
\return 0 Success, else error (such as BAD_FUNC_ARG or BUFFER_E).
\param hash_type A hash type from the “enum wc_HashType”
such as “WC_HASH_TYPE_SHA256”.
\param data Pointer to buffer containing the data to hash.
\param data_len Length of the data buffer.
\param hash Pointer to buffer used to output the final hash to.
\param hash_len Length of the hash buffer.
_Example_
\code
enum wc_HashType hash_type = WC_HASH_TYPE_SHA256;
int hash_len = wc_HashGetDigestSize(hash_type);
if (hash_len > 0) {
int ret = wc_Hash(hash_type, data, data_len, hash_data, hash_len);
if(ret == 0) {
// Success
}
}
\endcode
\sa wc_HashGetDigestSize
*/
int wc_Hash(enum wc_HashType hash_type,
const byte* data, word32 data_len,
byte* hash, word32 hash_len);
/*!
\ingroup MD5
\brief Convenience function, handles all the hashing and places the
result into hash.
\return 0 Returned upon successfully hashing the data.
\return Memory_E memory error, unable to allocate memory. This is only
possible with the small stack option enabled.
\param data the data to hash
\param len the length of data
\param hash Byte array to hold hash value.
_Example_
\code
const byte* data;
word32 data_len;
byte* hash;
int ret;
...
ret = wc_Md5Hash(data, data_len, hash);
if (ret != 0) {
// Md5 Hash Failure Case.
}
\endcode
\sa wc_Md5Hash
\sa wc_Md5Final
\sa wc_InitMd5
*/
int wc_Md5Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief Convenience function, handles all the hashing and places the
result into hash.
\return 0 Returned upon successfully ….
\return Memory_E memory error, unable to allocate memory. This is only
possible with the small stack option enabled.
\param data the data to hash
\param len the length of data
\param hash Byte array to hold hash value.
_Example_
\code
none
\endcode
\sa wc_ShaHash
\sa wc_ShaFinal
\sa wc_InitSha
*/
int wc_ShaHash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief Convenience function, handles all the hashing and places the
result into hash.
\return 0 Success
\return <0 Error
\param data the data to hash
\param len the length of data
\param hash Byte array to hold hash value.
_Example_
\code
none
\endcode
\sa wc_InitSha224
\sa wc_Sha224Update
\sa wc_Sha224Final
*/
int wc_Sha224Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief Convenience function, handles all the hashing and places the
result into hash.
\return 0 Returned upon successfully …
\return Memory_E memory error, unable to allocate memory. This is only
possible with the small stack option enabled.
\param data the data to hash
\param len the length of data
\param hash Byte array to hold hash value.
_Example_
\code
none
\endcode
\sa wc_Sha256Hash
\sa wc_Sha256Final
\sa wc_InitSha256
*/
int wc_Sha256Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief Convenience function, handles all the hashing and places the
result into hash.
\return 0 Returned upon successfully hashing the data
\return Memory_E memory error, unable to allocate memory. This is only
possible with the small stack option enabled.
\param data the data to hash
\param len the length of data
\param hash Byte array to hold hash value.
_Example_
\code
none
\endcode
\sa wc_Sha384Hash
\sa wc_Sha384Final
\sa wc_InitSha384
*/
int wc_Sha384Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief Convenience function, handles all the hashing and places the
result into hash.
\return 0 Returned upon successfully hashing the inputted data
\return Memory_E memory error, unable to allocate memory. This is only
possible with the small stack option enabled.
\param data the data to hash
\param len the length of data
\param hash Byte array to hold hash value.
_Example_
\code
none
\endcode
\sa wc_Sha512Hash
\sa wc_Sha512Final
\sa wc_InitSha512
*/
int wc_Sha512Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief Convenience function, handles all the hashing and places the
result into hash.
\return 0 Returned upon successfully hashing the data
\return Memory_E memory error, unable to allocate memory. This is only
possible with the small stack option enabled.
\param data the data to hash
\param len the length of data
\param hash Byte array to hold hash value.
_Example_
\code
none
\endcode
\sa wc_InitSha3_224
\sa wc_Sha3_224_Update
\sa wc_Sha3_224_Final
*/
int wc_Sha3_224Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief Convenience function, handles all the hashing and places the
result into hash.
\return 0 Returned upon successfully hashing the data
\return Memory_E memory error, unable to allocate memory. This is only
possible with the small stack option enabled.
\param data the data to hash
\param len the length of data
\param hash Byte array to hold hash value.
_Example_
\code
none
\endcode
\sa wc_InitSha3_256
\sa wc_Sha3_256_Update
\sa wc_Sha3_256_Final
*/
int wc_Sha3_256Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief Convenience function, handles all the hashing and places the
result into hash.
\return 0 Returned upon successfully hashing the data
\return Memory_E memory error, unable to allocate memory. This is only
possible with the small stack option enabled.
\param data the data to hash
\param len the length of data
\param hash Byte array to hold hash value.
_Example_
\code
none
\endcode
\sa wc_InitSha3_384
\sa wc_Sha3_384_Update
\sa wc_Sha3_384_Final
*/
int wc_Sha3_384Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief Convenience function, handles all the hashing and places the
result into hash.
\return 0 Returned upon successfully hashing the inputted data
\return Memory_E memory error, unable to allocate memory. This is only
possible with the small stack option enabled.
\param data the data to hash
\param len the length of data
\param hash Byte array to hold hash value.
_Example_
\code
none
\endcode
\sa wc_InitSha3_512
\sa wc_Sha3_512_Update
\sa wc_Sha3_512_Final
*/
int wc_Sha3_512Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief Convenience function, handles all the hashing and places the
result into hash.
\return 0 Returned upon successfully hashing the inputted data
\return Memory_E memory error, unable to allocate memory. This is only
possible with the small stack option enabled.
\param data the data to hash
\param len the length of data
\param hash Byte array to hold hash value.
_Example_
\code
none
\endcode
\sa wc_InitShake128
\sa wc_Shake128_Update
\sa wc_Shake128_Final
*/
int wc_Shake128Hash(const byte* data, word32 len, byte* hash);
/*!
\ingroup SHA
\brief Convenience function, handles all the hashing and places the
result into hash.
\return 0 Returned upon successfully hashing the inputted data
\return Memory_E memory error, unable to allocate memory. This is only
possible with the small stack option enabled.
\param data the data to hash
\param len the length of data
\param hash Byte array to hold hash value.
_Example_
\code
none
\endcode
\sa wc_InitShake256
\sa wc_Shake256_Update
\sa wc_Shake256_Final
*/
int wc_Shake256Hash(const byte* data, word32 len, byte* hash);

View File

@@ -0,0 +1,172 @@
/*!
\ingroup HMAC
\brief This function initializes an Hmac object, setting its
encryption type, key and HMAC length.
\return 0 Returned on successfully initializing the Hmac object
\return BAD_FUNC_ARG Returned if the input type is invalid (see type param)
\return MEMORY_E Returned if there is an error allocating memory for the
structure to use for hashing
\return HMAC_MIN_KEYLEN_E May be returned when using a FIPS implementation
and the key length specified is shorter than the minimum acceptable
FIPS standard
\param hmac pointer to the Hmac object to initialize
\param type type specifying which encryption method the Hmac object
should use. Valid options are: WC_MD5, WC_SHA, WC_SHA256, WC_SHA384,
WC_SHA512, WC_SHA3_224, WC_SHA3_256, WC_SHA3_384 or WC_SHA3_512
\param key pointer to a buffer containing the key with which to
initialize the Hmac object
\param length length of the key
_Example_
\code
Hmac hmac;
byte key[] = { // initialize with key to use for encryption };
if (wc_HmacSetKey(&hmac, WC_MD5, key, sizeof(key)) != 0) {
// error initializing Hmac object
}
\endcode
\sa wc_HmacUpdate
\sa wc_HmacFinal
*/
int wc_HmacSetKey(Hmac* hmac, int type, const byte* key, word32 keySz);
/*!
\ingroup HMAC
\brief This function updates the message to authenticate using HMAC.
It should be called after the Hmac object has been initialized with
wc_HmacSetKey. This function may be called multiple times to update
the message to hash. After calling wc_HmacUpdate as desired, one should
call wc_HmacFinal to obtain the final authenticated message tag.
\return 0 Returned on successfully updating the message to authenticate
\return MEMORY_E Returned if there is an error allocating memory for
use with a hashing algorithm
\param hmac pointer to the Hmac object for which to update the message
\param msg pointer to the buffer containing the message to append
\param length length of the message to append
_Example_
\code
Hmac hmac;
byte msg[] = { // initialize with message to authenticate };
byte msg2[] = { // initialize with second half of message };
// initialize hmac
if( wc_HmacUpdate(&hmac, msg, sizeof(msg)) != 0) {
// error updating message
}
if( wc_HmacUpdate(&hmac, msg2, sizeof(msg)) != 0) {
// error updating with second message
}
\endcode
\sa wc_HmacSetKey
\sa wc_HmacFinal
*/
int wc_HmacUpdate(Hmac* hmac, const byte* in, word32 sz);
/*!
\ingroup HMAC
\brief This function computes the final hash of an Hmac object's message.
\return 0 Returned on successfully computing the final hash
\return MEMORY_E Returned if there is an error allocating memory for
use with a hashing algorithm
\param hmac pointer to the Hmac object for which to calculate the
final hash
\param hash pointer to the buffer in which to store the final hash.
Should have room available as required by the hashing algorithm chosen
_Example_
\code
Hmac hmac;
byte hash[MD5_DIGEST_SIZE];
// initialize hmac with MD5 as type
// wc_HmacUpdate() with messages
if (wc_HmacFinal(&hmac, hash) != 0) {
// error computing hash
}
\endcode
\sa wc_HmacSetKey
\sa wc_HmacUpdate
*/
int wc_HmacFinal(Hmac* hmac, byte* out);
/*!
\ingroup HMAC
\brief This function returns the largest HMAC digest size available
based on the configured cipher suites.
\return Success Returns the largest HMAC digest size available based
on the configured cipher suites
\param none No parameters.
_Example_
\code
int maxDigestSz = wolfSSL_GetHmacMaxSize();
\endcode
\sa none
*/
int wolfSSL_GetHmacMaxSize(void);
/*!
\ingroup HMAC
\brief This function provides access to a HMAC Key Derivation Function
(HKDF). It utilizes HMAC to convert inKey, with an optional salt and
optional info into a derived key, which it stores in out. The hash type
defaults to MD5 if 0 or NULL is given.
\return 0 Returned upon successfully generating a key with the given inputs
\return BAD_FUNC_ARG Returned if an invalid hash type is given (see type param)
\return MEMORY_E Returned if there is an error allocating memory
\return HMAC_MIN_KEYLEN_E May be returned when using a FIPS implementation
and the key length specified is shorter than the minimum acceptable FIPS
standard
\param type hash type to use for the HKDF. Valid types are: WC_MD5, WC_SHA,
WC_SHA256, WC_SHA384, WC_SHA512, WC_SHA3_224, WC_SHA3_256, WC_SHA3_384 or
WC_SHA3_512
\param inKey pointer to the buffer containing the key to use for KDF
\param inKeySz length of the input key
\param salt pointer to a buffer containing an optional salt. Use NULL
instead if not using a salt
\param saltSz length of the salt. Use 0 if not using a salt
\param info pointer to a buffer containing optional additional info.
Use NULL if not appending extra info
\param infoSz length of additional info. Use 0 if not using additional info
\param out pointer to the buffer in which to store the derived key
\param outSz space available in the output buffer to store the
generated key
_Example_
\code
byte key[] = { // initialize with key };
byte salt[] = { // initialize with salt };
byte derivedKey[MAX_DIGEST_SIZE];
int ret = wc_HKDF(WC_SHA512, key, sizeof(key), salt, sizeof(salt),
NULL, 0, derivedKey, sizeof(derivedKey));
if ( ret != 0 ) {
// error generating derived key
}
\endcode
\sa wc_HmacSetKey
*/
int wc_HKDF(int type, const byte* inKey, word32 inKeySz,
const byte* salt, word32 saltSz,
const byte* info, word32 infoSz,
byte* out, word32 outSz);

View File

@@ -0,0 +1,465 @@
/*!
\ingroup IoTSafe
\brief This function enables the IoT-Safe support on the given context.
\param ctx pointer to the WOLFSSL_CTX object on which the IoT-safe support must be enabled
\return 0 on success
\return WC_HW_E on hardware error
_Example_
\code
WOLFSSL_CTX *ctx;
ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
if (!ctx)
return NULL;
wolfSSL_CTX_iotsafe_enable(ctx);
\endcode
\sa wolfSSL_iotsafe_on
\sa wolfIoTSafe_SetCSIM_read_cb
\sa wolfIoTSafe_SetCSIM_write_cb
*/
int wolfSSL_CTX_iotsafe_enable(WOLFSSL_CTX *ctx);
/*!
\ingroup IoTSafe
\brief This function connects the IoT-Safe TLS callbacks to the given SSL session.
\brief This should be called to connect a SSL session to IoT-Safe applet when the
ID of the slots are one-byte long.
If IoT-SAFE slots have an ID of two or more bytes, \ref wolfSSL_iotsafe_on_ex "wolfSSL_iotsafe_on_ex()"
should be used instead.
\param ssl pointer to the WOLFSSL object where the callbacks will be enabled
\param privkey_id id of the iot-safe applet slot containing the private key for the host
\param ecdh_keypair_slot id of the iot-safe applet slot to store the ECDH keypair
\param peer_pubkey_slot id of the iot-safe applet slot to store the other endpoint's public key for ECDH
\param peer_cert_slot id of the iot-safe applet slot to store the other endpoint's public key for verification
\return 0 upon success
\return NOT_COMPILED_IN if HAVE_PK_CALLBACKS is disabled
\return BAD_FUNC_ARG if the ssl pointer is invalid
_Example_
\code
// Define key ids for IoT-Safe
#define PRIVKEY_ID 0x02
#define ECDH_KEYPAIR_ID 0x03
#define PEER_PUBKEY_ID 0x04
#define PEER_CERT_ID 0x05
// Create new ssl session
WOLFSSL *ssl;
ssl = wolfSSL_new(ctx);
if (!ssl)
return NULL;
// Enable IoT-Safe and associate key slots
ret = wolfSSL_CTX_iotsafe_enable(ctx);
if (ret == 0) {
ret = wolfSSL_iotsafe_on(ssl, PRIVKEY_ID, ECDH_KEYPAIR_ID, PEER_PUBKEY_ID, PEER_CERT_ID);
}
\endcode
\sa wolfSSL_iotsafe_on_ex
\sa wolfSSL_CTX_iotsafe_enable
*/
int wolfSSL_iotsafe_on(WOLFSSL *ssl, byte privkey_id,
byte ecdh_keypair_slot, byte peer_pubkey_slot, byte peer_cert_slot);
/*!
\ingroup IoTSafe
\brief This function connects the IoT-Safe TLS callbacks to the given SSL session.
This is equivalent to \ref wolfSSL_iotsafe_on "wolfSSL_iotsafe_on" except that the IDs for the IoT-SAFE
slots can be passed by reference, and the length of the ID fields can be specified via
the parameter "id_size".
\param ssl pointer to the WOLFSSL object where the callbacks will be enabled
\param privkey_id pointer to the id of the iot-safe applet slot containing the private key for the host
\param ecdh_keypair_slot pointer to the id of the iot-safe applet slot to store the ECDH keypair
\param peer_pubkey_slot pointer to the of id the iot-safe applet slot to store the other endpoint's public key for ECDH
\param peer_cert_slot pointer to the id of the iot-safe applet slot to store the other endpoint's public key for verification
\param id_size size of each slot ID
\return 0 upon success
\return NOT_COMPILED_IN if HAVE_PK_CALLBACKS is disabled
\return BAD_FUNC_ARG if the ssl pointer is invalid
_Example_
\code
// Define key ids for IoT-Safe (16 bit, little endian)
#define PRIVKEY_ID 0x0201
#define ECDH_KEYPAIR_ID 0x0301
#define PEER_PUBKEY_ID 0x0401
#define PEER_CERT_ID 0x0501
#define ID_SIZE (sizeof(word16))
word16 privkey = PRIVKEY_ID,
ecdh_keypair = ECDH_KEYPAIR_ID,
peer_pubkey = PEER_PUBKEY_ID,
peer_cert = PEER_CERT_ID;
// Create new ssl session
WOLFSSL *ssl;
ssl = wolfSSL_new(ctx);
if (!ssl)
return NULL;
// Enable IoT-Safe and associate key slots
ret = wolfSSL_CTX_iotsafe_enable(ctx);
if (ret == 0) {
ret = wolfSSL_CTX_iotsafe_on_ex(ssl, &privkey, &ecdh_keypair, &peer_pubkey, &peer_cert, ID_SIZE);
}
\endcode
\sa wolfSSL_iotsafe_on
\sa wolfSSL_CTX_iotsafe_enable
*/
int wolfSSL_iotsafe_on_ex(WOLFSSL *ssl, byte *privkey_id,
byte *ecdh_keypair_slot, byte *peer_pubkey_slot, byte *peer_cert_slot, word16 id_size);
/*!
\ingroup IoTSafe
\brief Associates a read callback for the AT+CSIM commands. This input function is
usually associated to a read event of a UART channel communicating with the modem.
The read callback associated is global and changes for all the contexts that use
IoT-safe support at the same time.
\param rf Read callback associated to a UART read event. The callback function takes
two arguments (buf, len) and return the number of characters read, up to len. When a
newline is encountered, the callback should return the number of characters received
so far, including the newline character.
_Example_
\code
// USART read function, defined elsewhere
int usart_read(char *buf, int len);
wolfIoTSafe_SetCSIM_read_cb(usart_read);
\endcode
\sa wolfIoTSafe_SetCSIM_write_cb
*/
void wolfIoTSafe_SetCSIM_read_cb(wolfSSL_IOTSafe_CSIM_read_cb rf);
/*!
\ingroup IoTSafe
\brief Associates a write callback for the AT+CSIM commands. This output function is
usually associated to a write event on a UART channel communicating with the modem.
The write callback associated is global and changes for all the contexts that use
IoT-safe support at the same time.
\param rf Write callback associated to a UART write event. The callback function takes
two arguments (buf, len) and return the number of characters written, up to len.
_Example_
\code
// USART write function, defined elsewhere
int usart_write(const char *buf, int len);
wolfIoTSafe_SetCSIM_write_cb(usart_write);
\endcode
\sa wolfIoTSafe_SetCSIM_read_cb
*/
void wolfIoTSafe_SetCSIM_write_cb(wolfSSL_IOTSafe_CSIM_write_cb wf);
/*!
\ingroup IoTSafe
\brief Generate a random buffer of given size, using the IoT-Safe function
GetRandom. This function is automatically used by the wolfCrypt RNG object.
\param out the buffer where the random sequence of bytes is stored.
\param sz the size of the random sequence to generate, in bytes
\return 0 upon success
*/
int wolfIoTSafe_GetRandom(unsigned char* out, word32 sz);
/*!
\ingroup IoTSafe
\brief Import a certificate stored in a file on IoT-Safe applet, and
store it locally in memory. Works with one-byte file ID field.
\param id The file id in the IoT-Safe applet where the certificate is stored
\param output the buffer where the certificate will be imported
\param sz the maximum size available in the buffer output
\return the length of the certificate imported
\return < 0 in case of failure
_Example_
\code
#define CRT_CLIENT_FILE_ID 0x03
unsigned char cert_buffer[2048];
// Get the certificate into the buffer
cert_buffer_size = wolfIoTSafe_GetCert(CRT_CLIENT_FILE_ID, cert_buffer, 2048);
if (cert_buffer_size < 1) {
printf("Bad cli cert\n");
return -1;
}
printf("Loaded Client certificate from IoT-Safe, size = %lu\n", cert_buffer_size);
// Use the certificate buffer as identity for the TLS client context
if (wolfSSL_CTX_use_certificate_buffer(cli_ctx, cert_buffer,
cert_buffer_size, SSL_FILETYPE_ASN1) != SSL_SUCCESS) {
printf("Cannot load client cert\n");
return -1;
}
printf("Client certificate successfully imported.\n");
\endcode
*/
int wolfIoTSafe_GetCert(uint8_t id, unsigned char *output, unsigned long sz);
/*!
\ingroup IoTSafe
\brief Import a certificate stored in a file on IoT-Safe applet, and
store it locally in memory. Equivalent to \ref wolfIoTSafe_GetCert "wolfIoTSafe_GetCert",
except that it can be invoked with a file ID of two or more bytes.
\param id Pointer to the file id in the IoT-Safe applet where the certificate is stored
\param id_sz Size of the file id in bytes
\param output the buffer where the certificate will be imported
\param sz the maximum size available in the buffer output
\return the length of the certificate imported
\return < 0 in case of failure
_Example_
\code
#define CRT_CLIENT_FILE_ID 0x0302
#define ID_SIZE (sizeof(word16))
unsigned char cert_buffer[2048];
word16 client_file_id = CRT_CLIENT_FILE_ID;
// Get the certificate into the buffer
cert_buffer_size = wolfIoTSafe_GetCert_ex(&client_file_id, ID_SIZE, cert_buffer, 2048);
if (cert_buffer_size < 1) {
printf("Bad cli cert\n");
return -1;
}
printf("Loaded Client certificate from IoT-Safe, size = %lu\n", cert_buffer_size);
// Use the certificate buffer as identity for the TLS client context
if (wolfSSL_CTX_use_certificate_buffer(cli_ctx, cert_buffer,
cert_buffer_size, SSL_FILETYPE_ASN1) != SSL_SUCCESS) {
printf("Cannot load client cert\n");
return -1;
}
printf("Client certificate successfully imported.\n");
\endcode
*/
int wolfIoTSafe_GetCert_ex(uint8_t *id, uint16_t id_sz, unsigned char *output, unsigned long sz);
/*!
\ingroup IoTSafe
\brief Import an ECC 256-bit public key, stored in the IoT-Safe applet, into an ecc_key
object.
\param key the ecc_key object that will contain the key imported from the IoT-Safe applet
\param id The key id in the IoT-Safe applet where the public key is stored
\return 0 upon success
\return < 0 in case of failure
\sa wc_iotsafe_ecc_export_public
\sa wc_iotsafe_ecc_export_private
*/
int wc_iotsafe_ecc_import_public(ecc_key *key, byte key_id);
/*!
\ingroup IoTSafe
\brief Export an ECC 256-bit public key, from ecc_key object to a writable public-key slot into the IoT-Safe applet.
\param key the ecc_key object containing the key to be exported
\param id The key id in the IoT-Safe applet where the public key will be stored
\return 0 upon success
\return < 0 in case of failure
\sa wc_iotsafe_ecc_import_public_ex
\sa wc_iotsafe_ecc_export_private
*/
int wc_iotsafe_ecc_export_public(ecc_key *key, byte key_id);
/*!
\ingroup IoTSafe
\brief Export an ECC 256-bit public key, from ecc_key object to a writable public-key slot into the IoT-Safe applet.
Equivalent to \ref wc_iotsafe_ecc_import_public "wc_iotsafe_ecc_import_public",
except that it can be invoked with a key ID of two or more bytes.
\param key the ecc_key object containing the key to be exported
\param id The pointer to the key id in the IoT-Safe applet where the public key will be stored
\param id_size The key id size
\return 0 upon success
\return < 0 in case of failure
\sa wc_iotsafe_ecc_import_public
\sa wc_iotsafe_ecc_export_private
*/
int wc_iotsafe_ecc_import_public_ex(ecc_key *key, byte *key_id, word16 id_size);
/*!
\ingroup IoTSafe
\brief Export an ECC 256-bit key, from ecc_key object to a writable private-key slot into the IoT-Safe applet.
\param key the ecc_key object containing the key to be exported
\param id The key id in the IoT-Safe applet where the private key will be stored
\return 0 upon success
\return < 0 in case of failure
\sa wc_iotsafe_ecc_export_private_ex
\sa wc_iotsafe_ecc_import_public
\sa wc_iotsafe_ecc_export_public
*/
int wc_iotsafe_ecc_export_private(ecc_key *key, byte key_id);
/*!
\ingroup IoTSafe
\brief Export an ECC 256-bit key, from ecc_key object to a writable private-key slot into the IoT-Safe applet.
Equivalent to \ref wc_iotsafe_ecc_export_private "wc_iotsafe_ecc_export_private",
except that it can be invoked with a key ID of two or more bytes.
\param key the ecc_key object containing the key to be exported
\param id The pointer to the key id in the IoT-Safe applet where the private key will be stored
\param id_size The key id size
\return 0 upon success
\return < 0 in case of failure
\sa wc_iotsafe_ecc_export_private
\sa wc_iotsafe_ecc_import_public
\sa wc_iotsafe_ecc_export_public
*/
int wc_iotsafe_ecc_export_private_ex(ecc_key *key, byte *key_id, word16 id_size);
/*!
\ingroup IoTSafe
\brief Sign a pre-computed 256-bit HASH, using a private key previously stored, or pre-provisioned,
in the IoT-Safe applet.
\param in pointer to the buffer containing the message hash to sign
\param inlen length of the message hash to sign
\param out buffer in which to store the generated signature
\param outlen max length of the output buffer. Will store the bytes
\param id key id in the IoT-Safe applet for the slot containing the private key to sign the payload
written to out upon successfully generating a message signature
\return 0 upon success
\return < 0 in case of failure
\sa wc_iotsafe_ecc_sign_hash_ex
\sa wc_iotsafe_ecc_verify_hash
\sa wc_iotsafe_ecc_gen_k
*/
int wc_iotsafe_ecc_sign_hash(byte *in, word32 inlen, byte *out, word32 *outlen, byte key_id);
/*!
\ingroup IoTSafe
\brief Sign a pre-computed 256-bit HASH, using a private key previously stored, or pre-provisioned,
in the IoT-Safe applet. Equivalent to \ref wc_iotsafe_ecc_sign_hash "wc_iotsafe_ecc_sign_hash",
except that it can be invoked with a key ID of two or more bytes.
\param in pointer to the buffer containing the message hash to sign
\param inlen length of the message hash to sign
\param out buffer in which to store the generated signature
\param outlen max length of the output buffer. Will store the bytes
\param id pointer to a key id in the IoT-Safe applet for the slot containing the private key to sign the payload
written to out upon successfully generating a message signature
\param id_size The key id size
\return 0 upon success
\return < 0 in case of failure
\sa wc_iotsafe_ecc_sign_hash
\sa wc_iotsafe_ecc_verify_hash
\sa wc_iotsafe_ecc_gen_k
*/
int wc_iotsafe_ecc_sign_hash_ex(byte *in, word32 inlen, byte *out, word32 *outlen, byte *key_id, word16 id_size);
/*!
\ingroup IoTSafe
\brief Verify an ECC signature against a pre-computed 256-bit HASH, using a public key previously stored, or pre-provisioned,
in the IoT-Safe applet. Result is written to res. 1 is valid, 0 is invalid.
Note: Do not use the return value to test for valid. Only use res.
\return 0 upon success (even if the signature is not valid)
\return < 0 in case of failure.
\param sig buffer containing the signature to verify
\param hash The hash (message digest) that was signed
\param hashlen The length of the hash (octets)
\param res Result of signature, 1==valid, 0==invalid
\param key_id The id of the slot where the public ECC key is stored in the IoT-Safe applet
\sa wc_iotsafe_ecc_verify_hash_ex
\sa wc_iotsafe_ecc_sign_hash
\sa wc_iotsafe_ecc_gen_k
*/
int wc_iotsafe_ecc_verify_hash(byte *sig, word32 siglen, byte *hash, word32 hashlen, int *res, byte key_id);
/*!
\ingroup IoTSafe
\brief Verify an ECC signature against a pre-computed 256-bit HASH, using a public key previously stored, or pre-provisioned,
in the IoT-Safe applet. Result is written to res. 1 is valid, 0 is invalid.
Note: Do not use the return value to test for valid. Only use res.
Equivalent to \ref wc_iotsafe_ecc_verify_hash "wc_iotsafe_ecc_verify_hash",
except that it can be invoked with a key ID of two or more bytes.
\return 0 upon success (even if the signature is not valid)
\return < 0 in case of failure.
\param sig buffer containing the signature to verify
\param hash The hash (message digest) that was signed
\param hashlen The length of the hash (octets)
\param res Result of signature, 1==valid, 0==invalid
\param key_id The id of the slot where the public ECC key is stored in the IoT-Safe applet
\param id_size The key id size
\sa wc_iotsafe_ecc_verify_hash
\sa wc_iotsafe_ecc_sign_hash
\sa wc_iotsafe_ecc_gen_k
*/
int wc_iotsafe_ecc_verify_hash_ex(byte *sig, word32 siglen, byte *hash, word32 hashlen, int *res, byte *key_id, word16 id_size);
/*!
\ingroup IoTSafe
\brief Generate an ECC 256-bit keypair and store it in a (writable) slot into the IoT-Safe applet.
\param key_id The id of the slot where the ECC key pair is stored in the IoT-Safe applet.
\return 0 upon success
\return < 0 in case of failure.
\sa wc_iotsafe_ecc_gen_k_ex
\sa wc_iotsafe_ecc_sign_hash
\sa wc_iotsafe_ecc_verify_hash
*/
int wc_iotsafe_ecc_gen_k(byte key_id);
/*!
\ingroup IoTSafe
\brief Generate an ECC 256-bit keypair and store it in a (writable) slot into the IoT-Safe applet.
Equivalent to \ref wc_iotsafe_ecc_gen_k "wc_iotsafe_ecc_gen_k",
except that it can be invoked with a key ID of two or more bytes.
\param key_id The id of the slot where the ECC key pair is stored in the IoT-Safe applet.
\param id_size The key id size
\return 0 upon success
\return < 0 in case of failure.
\sa wc_iotsafe_ecc_gen_k
\sa wc_iotsafe_ecc_sign_hash_ex
\sa wc_iotsafe_ecc_verify_hash_ex
*/
int wc_iotsafe_ecc_gen_k(byte key_id);

View File

@@ -0,0 +1,78 @@
/*!
\ingroup Logging
\brief This function registers a logging callback that will be used to
handle the wolfSSL log message. By default, if the system supports it
fprintf() to stderr is used but by using this function anything
can be done by the user.
\return Success If successful this function will return 0.
\return BAD_FUNC_ARG is the error that will be returned if a function
pointer is not provided.
\param log_function function to register as a logging callback.
Function signature must follow the above prototype.
_Example_
\code
int ret = 0;
// Logging callback prototype
void MyLoggingCallback(const int logLevel, const char* const logMessage);
// Register the custom logging callback with wolfSSL
ret = wolfSSL_SetLoggingCb(MyLoggingCallback);
if (ret != 0) {
// failed to set logging callback
}
void MyLoggingCallback(const int logLevel, const char* const logMessage)
{
// custom logging function
}
\endcode
\sa wolfSSL_Debugging_ON
\sa wolfSSL_Debugging_OFF
*/
int wolfSSL_SetLoggingCb(wolfSSL_Logging_cb log_function);
/*!
\ingroup Debug
\brief If logging has been enabled at build time this function turns on
logging at runtime. To enable logging at build time use --enable-debug
or define DEBUG_WOLFSSL.
\return 0 upon success.
\return NOT_COMPILED_IN is the error that will be returned if logging
isnt enabled for this build.
\param none No parameters.
_Example_
\code
wolfSSL_Debugging_ON();
\endcode
\sa wolfSSL_Debugging_OFF
\sa wolfSSL_SetLoggingCb
*/
int wolfSSL_Debugging_ON(void);
/*!
\ingroup Debug
\brief This function turns off runtime logging messages. If theyre
already off, no action is taken.
\return none No returns.
\param none No parameters.
_Example_
\code
wolfSSL_Debugging_OFF();
\endcode
\sa wolfSSL_Debugging_ON
\sa wolfSSL_SetLoggingCb
*/
void wolfSSL_Debugging_OFF(void);

View File

@@ -0,0 +1,116 @@
/*!
\ingroup MD2
\brief This function initializes md2. This is automatically
called by wc_Md2Hash.
\return 0 Returned upon successfully initializing
\param md2 pointer to the md2 structure to use for encryption
_Example_
\code
md2 md2[1];
if ((ret = wc_InitMd2(md2)) != 0) {
WOLFSSL_MSG("wc_Initmd2 failed");
}
else {
wc_Md2Update(md2, data, len);
wc_Md2Final(md2, hash);
}
\endcode
\sa wc_Md2Hash
\sa wc_Md2Update
\sa wc_Md2Final
*/
void wc_InitMd2(Md2*);
/*!
\ingroup MD2
\brief Can be called to continually hash the provided byte
array of length len.
\return 0 Returned upon successfully adding the data to the digest.
\param md2 pointer to the md2 structure to use for encryption
\param data the data to be hashed
\param len length of data to be hashed
_Example_
\code
md2 md2[1];
byte data[] = { }; // Data to be hashed
word32 len = sizeof(data);
if ((ret = wc_InitMd2(md2)) != 0) {
WOLFSSL_MSG("wc_Initmd2 failed");
}
else {
wc_Md2Update(md2, data, len);
wc_Md2Final(md2, hash);
}
\endcode
\sa wc_Md2Hash
\sa wc_Md2Final
\sa wc_InitMd2
*/
void wc_Md2Update(Md2* md2, const byte* data, word32 len);
/*!
\ingroup MD2
\brief Finalizes hashing of data. Result is placed into hash.
\return 0 Returned upon successfully finalizing.
\param md2 pointer to the md2 structure to use for encryption
\param hash Byte array to hold hash value.
_Example_
\code
md2 md2[1];
byte data[] = { }; // Data to be hashed
word32 len = sizeof(data);
if ((ret = wc_InitMd2(md2)) != 0) {
WOLFSSL_MSG("wc_Initmd2 failed");
}
else {
wc_Md2Update(md2, data, len);
wc_Md2Final(md2, hash);
}
\endcode
\sa wc_Md2Hash
\sa wc_Md2Final
\sa wc_InitMd2
*/
void wc_Md2Final(Md2* md2, byte* hash);
/*!
\ingroup MD2
\brief Convenience function, handles all the hashing and places
the result into hash.
\return 0 Returned upon successfully hashing the data.
\return Memory_E memory error, unable to allocate memory. This is only
possible with the small stack option enabled.
\param data the data to hash
\param len the length of data
\param hash Byte array to hold hash value.
_Example_
\code
none
\endcode
\sa wc_Md2Hash
\sa wc_Md2Final
\sa wc_InitMd2
*/
int wc_Md2Hash(const byte* data, word32 len, byte* hash);

View File

@@ -0,0 +1,88 @@
/*!
\ingroup MD4
\brief This function initializes md4. This is automatically
called by wc_Md4Hash.
\return 0 Returned upon successfully initializing
\param md4 pointer to the md4 structure to use for encryption
_Example_
\code
md4 md4[1];
if ((ret = wc_InitMd4(md4)) != 0) {
WOLFSSL_MSG("wc_Initmd4 failed");
}
else {
wc_Md4Update(md4, data, len);
wc_Md4Final(md4, hash);
}
\endcode
\sa wc_Md4Hash
\sa wc_Md4Update
\sa wc_Md4Final
*/
void wc_InitMd4(Md4*);
/*!
\ingroup MD4
\brief Can be called to continually hash the provided byte array
of length len.
\return 0 Returned upon successfully adding the data to the digest.
\param md4 pointer to the md4 structure to use for encryption
\param data the data to be hashed
\param len length of data to be hashed
_Example_
\code
md4 md4[1];
byte data[] = { }; // Data to be hashed
word32 len = sizeof(data);
if ((ret = wc_InitMd4(md4)) != 0) {
WOLFSSL_MSG("wc_Initmd4 failed");
}
else {
wc_Md4Update(md4, data, len);
wc_Md4Final(md4, hash);
}
\endcode
\sa wc_Md4Hash
\sa wc_Md4Final
\sa wc_InitMd4
*/
void wc_Md4Update(Md4* md4, const byte* data, word32 len);
/*!
\ingroup MD4
\brief Finalizes hashing of data. Result is placed into hash.
\return 0 Returned upon successfully finalizing.
\param md4 pointer to the md4 structure to use for encryption
\param hash Byte array to hold hash value.
_Example_
\code
md4 md4[1];
if ((ret = wc_InitMd4(md4)) != 0) {
WOLFSSL_MSG("wc_Initmd4 failed");
}
else {
wc_Md4Update(md4, data, len);
wc_Md4Final(md4, hash);
}
\endcode
\sa wc_Md4Hash
\sa wc_Md4Final
\sa wc_InitMd4
*/
void wc_Md4Final(Md4* md4, byte* hash);

View File

@@ -0,0 +1,180 @@
/*!
\ingroup MD5
\brief This function initializes md5. This is automatically
called by wc_Md5Hash.
\return 0 Returned upon successfully initializing.
\return BAD_FUNC_ARG Returned if the Md5 structure is passed
as a NULL value.
\param md5 pointer to the md5 structure to use for encryption
_Example_
\code
Md5 md5;
byte* hash;
if ((ret = wc_InitMd5(&md5)) != 0) {
WOLFSSL_MSG("wc_Initmd5 failed");
}
else {
ret = wc_Md5Update(&md5, data, len);
if (ret != 0) {
// Md5 Update Failure Case.
}
ret = wc_Md5Final(&md5, hash);
if (ret != 0) {
// Md5 Final Failure Case.
}
}
\endcode
\sa wc_Md5Hash
\sa wc_Md5Update
\sa wc_Md5Final
*/
int wc_InitMd5(wc_Md5*);
/*!
\ingroup MD5
\brief Can be called to continually hash the provided byte array of
length len.
\return 0 Returned upon successfully adding the data to the digest.
\return BAD_FUNC_ARG Returned if the Md5 structure is NULL or if
data is NULL and len is greater than zero. The function should
not return an error if the data parameter is NULL and len is zero.
\param md5 pointer to the md5 structure to use for encryption
\param data the data to be hashed
\param len length of data to be hashed
_Example_
\code
Md5 md5;
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitMd5(&md5)) != 0) {
WOLFSSL_MSG("wc_Initmd5 failed");
}
else {
ret = wc_Md5Update(&md5, data, len);
if (ret != 0) {
// Md5 Update Error Case.
}
ret = wc_Md5Final(&md5, hash);
if (ret != 0) {
// Md5 Final Error Case.
}
}
\endcode
\sa wc_Md5Hash
\sa wc_Md5Final
\sa wc_InitMd5
*/
int wc_Md5Update(wc_Md5* md5, const byte* data, word32 len);
/*!
\ingroup MD5
\brief Finalizes hashing of data. Result is placed into hash. Md5
Struct is reset. Note: This function will also return the result
of calling IntelQaSymMd5() in the case that HAVE_INTEL_QA is defined.
\return 0 Returned upon successfully finalizing.
\return BAD_FUNC_ARG Returned if the Md5 structure or hash pointer
is passed in NULL.
\param md5 pointer to the md5 structure to use for encryption
\param hash Byte array to hold hash value.
_Example_
\code
md5 md5[1];
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitMd5(md5)) != 0) {
WOLFSSL_MSG("wc_Initmd5 failed");
}
else {
ret = wc_Md5Update(md5, data, len);
if (ret != 0) {
// Md5 Update Failure Case.
}
ret = wc_Md5Final(md5, hash);
if (ret != 0) {
// Md5 Final Failure Case.
}
}
\endcode
\sa wc_Md5Hash
\sa wc_InitMd5
\sa wc_Md5GetHash
*/
int wc_Md5Final(wc_Md5* md5, byte* hash);
/*!
\ingroup MD5
\brief Resets the Md5 structure. Note: this is only supported if
you have WOLFSSL_TI_HASH defined.
\return none No returns.
\param md5 Pointer to the Md5 structure to be reset.
_Example_
\code
Md5 md5;
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitMd5(&md5)) != 0) {
WOLFSSL_MSG("wc_InitMd5 failed");
}
else {
wc_Md5Update(&md5, data, len);
wc_Md5Final(&md5, hash);
wc_Md5Free(&md5);
}
\endcode
\sa wc_InitMd5
\sa wc_Md5Update
\sa wc_Md5Final
*/
void wc_Md5Free(wc_Md5*);
/*!
\ingroup MD5
\brief Gets hash data. Result is placed into hash. Md5 struct
is not reset.
\return none No returns
\param md5 pointer to the md5 structure to use for encryption.
\param hash Byte array to hold hash value.
_Example_
\code
md5 md5[1];
if ((ret = wc_InitMd5(md5)) != 0) {
WOLFSSL_MSG("wc_Initmd5 failed");
}
else {
wc_Md5Update(md5, data, len);
wc_Md5GetHash(md5, hash);
}
\endcode
\sa wc_Md5Hash
\sa wc_Md5Final
\sa wc_InitMd5
*/
int wc_Md5GetHash(wc_Md5* md5, byte* hash);

View File

@@ -0,0 +1,219 @@
/*!
\ingroup Memory
\brief This function is similar to malloc(), but calls the memory
allocation function which wolfSSL has been configured to use. By default,
wolfSSL uses malloc(). This can be changed using the wolfSSL memory
abstraction layer - see wolfSSL_SetAllocators(). Note wolfSSL_Malloc is not
called directly by wolfSSL, but instead called by macro XMALLOC.
For the default build only the size argument exists. If using
WOLFSSL_STATIC_MEMORY build then heap and type arguments are included.
\return pointer If successful, this function returns a pointer to
allocated memory.
\return error If there is an error, NULL will be returned.
\param size size, in bytes, of the memory to allocate
\param heap heap hint to use for memory. Can be NULL
\param type dynamic type (see DYNAMIC_TYPE_ list in types.h)
_Example_
\code
int* tenInts = (int*)wolfSSL_Malloc(sizeof(int)*10);
\endcode
\sa wolfSSL_Free
\sa wolfSSL_Realloc
\sa wolfSSL_SetAllocators
\sa XMALLOC
\sa XFREE
\sa XREALLOC
*/
void* wolfSSL_Malloc(size_t size, void* heap, int type);
/*!
\ingroup Memory
\brief This function is similar to free(), but calls the memory free
function which wolfSSL has been configured to use. By default, wolfSSL
uses free(). This can be changed using the wolfSSL memory abstraction
layer - see wolfSSL_SetAllocators(). Note wolfSSL_Free is not
called directly by wolfSSL, but instead called by macro XFREE.
For the default build only the ptr argument exists. If using
WOLFSSL_STATIC_MEMORY build then heap and type arguments are included.
\return none No returns.
\param ptr pointer to the memory to be freed.
\param heap heap hint to use for memory. Can be NULL
\param type dynamic type (see DYNAMIC_TYPE_ list in types.h)
_Example_
\code
int* tenInts = (int*)wolfSSL_Malloc(sizeof(int)*10);
// process data as desired
...
if(tenInts) {
wolfSSL_Free(tenInts);
}
\endcode
\sa wolfSSL_Alloc
\sa wolfSSL_Realloc
\sa wolfSSL_SetAllocators
\sa XMALLOC
\sa XFREE
\sa XREALLOC
*/
void wolfSSL_Free(void *ptr, void* heap, int type);
/*!
\ingroup Memory
\brief This function is similar to realloc(), but calls the memory
re-allocation function which wolfSSL has been configured to use.
By default, wolfSSL uses realloc(). This can be changed using the
wolfSSL memory abstraction layer - see wolfSSL_SetAllocators().
Note wolfSSL_Realloc is not called directly by wolfSSL, but instead called
by macro XREALLOC. For the default build only the size argument exists.
If using WOLFSSL_STATIC_MEMORY build then heap and type arguments are included.
\return pointer If successful, this function returns a pointer to
re-allocated memory. This may be the same pointer as ptr, or a
new pointer location.
\return Null If there is an error, NULL will be returned.
\param ptr pointer to the previously-allocated memory, to be reallocated.
\param size number of bytes to allocate.
\param heap heap hint to use for memory. Can be NULL
\param type dynamic type (see DYNAMIC_TYPE_ list in types.h)
_Example_
\code
int* tenInts = (int*)wolfSSL_Malloc(sizeof(int)*10);
int* twentyInts = (int*)wolfSSL_Realloc(tenInts, sizeof(int)*20);
\endcode
\sa wolfSSL_Free
\sa wolfSSL_Malloc
\sa wolfSSL_SetAllocators
\sa XMALLOC
\sa XFREE
\sa XREALLOC
*/
void* wolfSSL_Realloc(void *ptr, size_t size, void* heap, int type);
/*!
\ingroup Memory
\brief This function registers the allocation functions used by wolfSSL.
By default, if the system supports it, malloc/free and realloc are used.
Using this function allows the user at runtime to install their own
memory handlers.
\return Success If successful this function will return 0.
\return BAD_FUNC_ARG is the error that will be returned if a
function pointer is not provided.
\param malloc_function memory allocation function for wolfSSL to use.
Function signature must match wolfSSL_Malloc_cb prototype, above.
\param free_function memory free function for wolfSSL to use. Function
signature must match wolfSSL_Free_cb prototype, above.
\param realloc_function memory re-allocation function for wolfSSL to use.
Function signature must match wolfSSL_Realloc_cb prototype, above.
_Example_
\code
static void* MyMalloc(size_t size)
{
// custom malloc function
}
static void MyFree(void* ptr)
{
// custom free function
}
static void* MyRealloc(void* ptr, size_t size)
{
// custom realloc function
}
// Register custom memory functions with wolfSSL
int ret = wolfSSL_SetAllocators(MyMalloc, MyFree, MyRealloc);
if (ret != 0) {
// failed to set memory functions
}
\endcode
\sa none
*/
int wolfSSL_SetAllocators(wolfSSL_Malloc_cb,
wolfSSL_Free_cb,
wolfSSL_Realloc_cb);
/*!
\ingroup Memory
\brief This function is available when static memory feature is used
(--enable-staticmemory). It gives the optimum buffer size for memory
“buckets”. This allows for a way to compute buffer size so that no
extra unused memory is left at the end after it has been partitioned.
The returned value, if positive, is the computed buffer size to use.
\return Success On successfully completing buffer size calculations a
positive value is returned. This returned value is for optimum buffer size.
\return Failure All negative values are considered to be error cases.
\param buffer pointer to buffer
\param size size of buffer
\param type desired type of memory ie WOLFMEM_GENERAL or WOLFMEM_IO_POOL
_Example_
\code
byte buffer[1000];
word32 size = sizeof(buffer);
int optimum;
optimum = wolfSSL_StaticBufferSz(buffer, size, WOLFMEM_GENERAL);
if (optimum < 0) { //handle error case }
printf(“The optimum buffer size to make use of all memory is %d\n”,
optimum);
...
\endcode
\sa wolfSSL_Malloc
\sa wolfSSL_Free
*/
int wolfSSL_StaticBufferSz(byte* buffer, word32 sz, int flag);
/*!
\ingroup Memory
\brief This function is available when static memory feature is used
(--enable-staticmemory). It gives the size of padding needed for each
partition of memory. This padding size will be the size needed to
contain a memory management structure along with any extra for
memory alignment.
\return On successfully memory padding calculation the return value will
be a positive value
\return All negative values are considered error cases.
\param none No parameters.
_Example_
\code
int padding;
padding = wolfSSL_MemoryPaddingSz();
if (padding < 0) { //handle error case }
printf(“The padding size needed for each \”bucket\” of memory is %d\n”,
padding);
// calculation of buffer for IO POOL size is number of buckets
// times (padding + WOLFMEM_IO_SZ)
...
\endcode
\sa wolfSSL_Malloc
\sa wolfSSL_Free
*/
int wolfSSL_MemoryPaddingSz(void);

View File

@@ -0,0 +1,34 @@
/*!
\ingroup openSSL
\brief This function writes a key into a WOLFSSL_BIO structure
in PEM format.
\return SSL_SUCCESS upon success.
\return SSL_FAILURE upon failure.
\param bio WOLFSSL_BIO structure to get PEM buffer from.
\param key key to convert to PEM format.
\param cipher EVP cipher structure.
\param passwd password.
\param len length of password.
\param cb password callback.
\param arg optional argument.
_Example_
\code
WOLFSSL_BIO* bio;
WOLFSSL_EVP_PKEY* key;
int ret;
// create bio and setup key
ret = wolfSSL_PEM_write_bio_PrivateKey(bio, key, NULL, NULL, 0, NULL, NULL);
//check ret value
\endcode
\sa wolfSSL_PEM_read_bio_X509_AUX
*/
int wolfSSL_PEM_write_bio_PrivateKey(WOLFSSL_BIO* bio, WOLFSSL_EVP_PKEY* key,
const WOLFSSL_EVP_CIPHER* cipher,
unsigned char* passwd, int len,
wc_pem_password_cb* cb, void* arg);

View File

@@ -0,0 +1,43 @@
/*!
\ingroup PKCS11
*/
int wc_Pkcs11_Initialize(Pkcs11Dev* dev, const char* library,
void* heap);
/*!
\ingroup PKCS11
*/
void wc_Pkcs11_Finalize(Pkcs11Dev* dev);
/*!
\ingroup PKCS11
*/
int wc_Pkcs11Token_Init(Pkcs11Token* token, Pkcs11Dev* dev,
int slotId, const char* tokenName, const unsigned char *userPin,
int userPinSz);
/*!
\ingroup PKCS11
*/
void wc_Pkcs11Token_Final(Pkcs11Token* token);
/*!
\ingroup PKCS11
*/
int wc_Pkcs11Token_Open(Pkcs11Token* token, int readWrite);
/*!
\ingroup PKCS11
*/
void wc_Pkcs11Token_Close(Pkcs11Token* token);
/*!
\ingroup PKCS11
*/
int wc_Pkcs11StoreKey(Pkcs11Token* token, int type, int clear,
/*!
\ingroup PKCS11
*/
int wc_Pkcs11_CryptoDevCb(int devId, wc_CryptoInfo* info,
void* ctx);

View File

@@ -0,0 +1,613 @@
/*!
\ingroup PKCS7
\brief This function initializes a PKCS7 structure with a DER-formatted
certificate. To initialize an empty PKCS7 structure, one can pass in a NULL
cert and 0 for certSz.
\return 0 Returned on successfully initializing the PKCS7 structure
\return MEMORY_E Returned if there is an error allocating memory
with XMALLOC
\return ASN_PARSE_E Returned if there is an error parsing the cert header
\return ASN_OBJECT_ID_E Returned if there is an error parsing the
encryption type from the cert
\return ASN_EXPECT_0_E Returned if there is a formatting error in the
encryption specification of the cert file
\return ASN_BEFORE_DATE_E Returned if the date is before the certificate
start date
\return ASN_AFTER_DATE_E Returned if the date is after the certificate
expiration date
\return ASN_BITSTR_E Returned if there is an error parsing a bit string
from the certificate
\return ECC_CURVE_OID_E Returned if there is an error parsing the ECC
key from the certificate
\return ASN_UNKNOWN_OID_E Returned if the certificate is using an unknown
key object id
\return ASN_VERSION_E Returned if the ALLOW_V1_EXTENSIONS option is not
defined and the certificate is a V1 or V2 certificate
\return BAD_FUNC_ARG Returned if there is an error processing the
certificate extension
\return ASN_CRIT_EXT_E Returned if an unfamiliar critical extension is
encountered in processing the certificate
\return ASN_SIG_OID_E Returned if the signature encryption type is not
the same as the encryption type of the certificate in the provided file
\return ASN_SIG_CONFIRM_E Returned if confirming the certification
signature fails
\return ASN_NAME_INVALID_E Returned if the certificates name is not
permitted by the CA name constraints
\return ASN_NO_SIGNER_E Returned if there is no CA signer to verify
the certificates authenticity
\param pkcs7 pointer to the PKCS7 structure in which to
store the decoded cert
\param cert pointer to a buffer containing a DER formatted ASN.1
certificate with which to initialize the PKCS7 structure
\param certSz size of the certificate buffer
_Example_
\code
PKCS7 pkcs7;
byte derBuff[] = { }; // initialize with DER-encoded certificate
if ( wc_PKCS7_InitWithCert(&pkcs7, derBuff, sizeof(derBuff)) != 0 ) {
// error parsing certificate into pkcs7 format
}
\endcode
\sa wc_PKCS7_Free
*/
int wc_PKCS7_InitWithCert(PKCS7* pkcs7, byte* cert, word32 certSz);
/*!
\ingroup PKCS7
\brief This function releases any memory allocated by a PKCS7 initializer.
\return none No returns.
\param pkcs7 pointer to the PKCS7 structure to free
_Example_
\code
PKCS7 pkcs7;
// initialize and use PKCS7 object
wc_PKCS7_Free(pkcs7);
\endcode
\sa wc_PKCS7_InitWithCert
*/
void wc_PKCS7_Free(PKCS7* pkcs7);
/*!
\ingroup PKCS7
\brief This function builds the PKCS7 data content type, encoding the
PKCS7 structure into a buffer containing a parsable PKCS7 data packet.
\return Success On successfully encoding the PKCS7 data into the buffer,
returns the index parsed up to in the PKCS7 structure. This index also
corresponds to the bytes written to the output buffer.
\return BUFFER_E Returned if the given buffer is not large enough to hold
the encoded certificate
\param pkcs7 pointer to the PKCS7 structure to encode
\param output pointer to the buffer in which to store the encoded
certificate
\param outputSz size available in the output buffer
_Example_
\code
PKCS7 pkcs7;
int ret;
byte derBuff[] = { }; // initialize with DER-encoded certificate
byte pkcs7Buff[FOURK_BUF];
wc_PKCS7_InitWithCert(&pkcs7, derBuff, sizeof(derBuff));
// update message and data to encode
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
pkcs7.content = data;
pkcs7.contentSz = dataSz;
... etc.
ret = wc_PKCS7_EncodeData(&pkcs7, pkcs7Buff, sizeof(pkcs7Buff));
if ( ret != 0 ) {
// error encoding into output buffer
}
\endcode
\sa wc_PKCS7_InitWithCert
*/
int wc_PKCS7_EncodeData(PKCS7* pkcs7, byte* output,
word32 outputSz);
/*!
\ingroup PKCS7
\brief This function builds the PKCS7 signed data content type, encoding
the PKCS7 structure into a buffer containing a parsable PKCS7
signed data packet.
\return Success On successfully encoding the PKCS7 data into the buffer,
returns the index parsed up to in the PKCS7 structure. This index also
corresponds to the bytes written to the output buffer.
\return BAD_FUNC_ARG Returned if the PKCS7 structure is missing one or
more required elements to generate a signed data packet
\return MEMORY_E Returned if there is an error allocating memory
\return PUBLIC_KEY_E Returned if there is an error parsing the public key
\return RSA_BUFFER_E Returned if buffer error, output too small or input
too large
\return BUFFER_E Returned if the given buffer is not large enough to hold
the encoded certificate
\return MP_INIT_E may be returned if there is an error generating
the signature
\return MP_READ_E may be returned if there is an error generating
the signature
\return MP_CMP_E may be returned if there is an error generating
the signature
\return MP_INVMOD_E may be returned if there is an error generating
the signature
\return MP_EXPTMOD_E may be returned if there is an error generating
the signature
\return MP_MOD_E may be returned if there is an error generating
the signature
\return MP_MUL_E may be returned if there is an error generating
the signature
\return MP_ADD_E may be returned if there is an error generating
the signature
\return MP_MULMOD_E may be returned if there is an error generating
the signature
\return MP_TO_E may be returned if there is an error generating
the signature
\return MP_MEM may be returned if there is an error generating the signature
\param pkcs7 pointer to the PKCS7 structure to encode
\param output pointer to the buffer in which to store the
encoded certificate
\param outputSz size available in the output buffer
_Example_
\code
PKCS7 pkcs7;
int ret;
byte data[] = {}; // initialize with data to sign
byte derBuff[] = { }; // initialize with DER-encoded certificate
byte pkcs7Buff[FOURK_BUF];
wc_PKCS7_InitWithCert(&pkcs7, derBuff, sizeof(derBuff));
// update message and data to encode
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
pkcs7.content = data;
pkcs7.contentSz = dataSz;
pkcs7.hashOID = SHAh;
pkcs7.rng = &rng;
... etc.
ret = wc_PKCS7_EncodeSignedData(&pkcs7, pkcs7Buff, sizeof(pkcs7Buff));
if ( ret != 0 ) {
// error encoding into output buffer
}
wc_PKCS7_Free(&pkcs7);
\endcode
\sa wc_PKCS7_InitWithCert
\sa wc_PKCS7_VerifySignedData
*/
int wc_PKCS7_EncodeSignedData(PKCS7* pkcs7,
byte* output, word32 outputSz);
/*!
\ingroup PKCS7
\brief This function builds the PKCS7 signed data content type, encoding
the PKCS7 structure into a header and footer buffer containing a parsable PKCS7
signed data packet. This does not include the content.
A hash must be computed and provided for the data
\return 0=Success
\return BAD_FUNC_ARG Returned if the PKCS7 structure is missing one or
more required elements to generate a signed data packet
\return MEMORY_E Returned if there is an error allocating memory
\return PUBLIC_KEY_E Returned if there is an error parsing the public key
\return RSA_BUFFER_E Returned if buffer error, output too small or input
too large
\return BUFFER_E Returned if the given buffer is not large enough to hold
the encoded certificate
\return MP_INIT_E may be returned if there is an error generating
the signature
\return MP_READ_E may be returned if there is an error generating
the signature
\return MP_CMP_E may be returned if there is an error generating
the signature
\return MP_INVMOD_E may be returned if there is an error generating
the signature
\return MP_EXPTMOD_E may be returned if there is an error generating
the signature
\return MP_MOD_E may be returned if there is an error generating
the signature
\return MP_MUL_E may be returned if there is an error generating
the signature
\return MP_ADD_E may be returned if there is an error generating
the signature
\return MP_MULMOD_E may be returned if there is an error generating
the signature
\return MP_TO_E may be returned if there is an error generating
the signature
\return MP_MEM may be returned if there is an error generating the signature
\param pkcs7 pointer to the PKCS7 structure to encode
\param hashBuf pointer to computed hash for the content data
\param hashSz size of the digest
\param outputHead pointer to the buffer in which to store the
encoded certificate header
\param outputHeadSz pointer populated with size of output header buffer
and returns actual size
\param outputFoot pointer to the buffer in which to store the
encoded certificate footer
\param outputFootSz pointer populated with size of output footer buffer
and returns actual size
_Example_
\code
PKCS7 pkcs7;
int ret;
byte derBuff[] = { }; // initialize with DER-encoded certificate
byte data[] = {}; // initialize with data to sign
byte pkcs7HeadBuff[FOURK_BUF/2];
byte pkcs7FootBuff[FOURK_BUF/2];
word32 pkcs7HeadSz = (word32)sizeof(pkcs7HeadBuff);
word32 pkcs7FootSz = (word32)sizeof(pkcs7HeadBuff);
enum wc_HashType hashType = WC_HASH_TYPE_SHA;
byte hashBuf[WC_MAX_DIGEST_SIZE];
word32 hashSz = wc_HashGetDigestSize(hashType);
wc_PKCS7_InitWithCert(&pkcs7, derBuff, sizeof(derBuff));
// update message and data to encode
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
pkcs7.content = NULL;
pkcs7.contentSz = dataSz;
pkcs7.hashOID = SHAh;
pkcs7.rng = &rng;
... etc.
// calculate hash for content
ret = wc_HashInit(&hash, hashType);
if (ret == 0) {
ret = wc_HashUpdate(&hash, hashType, data, sizeof(data));
if (ret == 0) {
ret = wc_HashFinal(&hash, hashType, hashBuf);
}
wc_HashFree(&hash, hashType);
}
ret = wc_PKCS7_EncodeSignedData_ex(&pkcs7, hashBuf, hashSz, pkcs7HeadBuff,
&pkcs7HeadSz, pkcs7FootBuff, &pkcs7FootSz);
if ( ret != 0 ) {
// error encoding into output buffer
}
wc_PKCS7_Free(&pkcs7);
\endcode
\sa wc_PKCS7_InitWithCert
\sa wc_PKCS7_VerifySignedData_ex
*/
int wc_PKCS7_EncodeSignedData_ex(PKCS7* pkcs7, const byte* hashBuf,
word32 hashSz, byte* outputHead, word32* outputHeadSz, byte* outputFoot,
word32* outputFootSz);
/*!
\ingroup PKCS7
\brief This function takes in a transmitted PKCS7 signed data message,
extracts the certificate list and certificate revocation list, and then
verifies the signature. It stores the extracted content in the given
PKCS7 structure.
\return 0 Returned on successfully extracting the information
from the message
\return BAD_FUNC_ARG Returned if one of the input parameters is invalid
\return ASN_PARSE_E Returned if there is an error parsing from the
given pkiMsg
\return PKCS7_OID_E Returned if the given pkiMsg is not a signed data type
\return ASN_VERSION_E Returned if the PKCS7 signer info is not version 1
\return MEMORY_E Returned if there is an error allocating memory
\return PUBLIC_KEY_E Returned if there is an error parsing the public key
\return RSA_BUFFER_E Returned if buffer error, output too small or
input too large
\return BUFFER_E Returned if the given buffer is not large enough to
hold the encoded certificate
\return MP_INIT_E may be returned if there is an error generating
the signature
\return MP_READ_E may be returned if there is an error generating
the signature
\return MP_CMP_E may be returned if there is an error generating
the signature
\return MP_INVMOD_E may be returned if there is an error generating
the signature
\return MP_EXPTMOD_E may be returned if there is an error generating
the signature
\return MP_MOD_E may be returned if there is an error generating
the signature
\return MP_MUL_E may be returned if there is an error generating
the signature
\return MP_ADD_E may be returned if there is an error generating
the signature
\return MP_MULMOD_E may be returned if there is an error generating
the signature
\return MP_TO_E may be returned if there is an error generating
the signature
\return MP_MEM may be returned if there is an error generating the signature
\param pkcs7 pointer to the PKCS7 structure in which to store the parsed
certificates
\param pkiMsg pointer to the buffer containing the signed message to verify
and decode
\param pkiMsgSz size of the signed message
_Example_
\code
PKCS7 pkcs7;
int ret;
byte pkcs7Buff[] = {}; // the PKCS7 signature
wc_PKCS7_InitWithCert(&pkcs7, NULL, 0);
// update message and data to encode
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
pkcs7.content = data;
pkcs7.contentSz = dataSz;
... etc.
ret = wc_PKCS7_VerifySignedData(&pkcs7, pkcs7Buff, sizeof(pkcs7Buff));
if ( ret != 0 ) {
// error encoding into output buffer
}
wc_PKCS7_Free(&pkcs7);
\endcode
\sa wc_PKCS7_InitWithCert
\sa wc_PKCS7_EncodeSignedData
*/
int wc_PKCS7_VerifySignedData(PKCS7* pkcs7,
byte* pkiMsg, word32 pkiMsgSz);
/*!
\ingroup PKCS7
\brief This function takes in a transmitted PKCS7 signed data message as
hash/header/footer, then extracts the certificate list and certificate
revocation list, and then verifies the signature. It stores the extracted
content in the given PKCS7 structure.
\return 0 Returned on successfully extracting the information
from the message
\return BAD_FUNC_ARG Returned if one of the input parameters is invalid
\return ASN_PARSE_E Returned if there is an error parsing from the
given pkiMsg
\return PKCS7_OID_E Returned if the given pkiMsg is not a signed data type
\return ASN_VERSION_E Returned if the PKCS7 signer info is not version 1
\return MEMORY_E Returned if there is an error allocating memory
\return PUBLIC_KEY_E Returned if there is an error parsing the public key
\return RSA_BUFFER_E Returned if buffer error, output too small or
input too large
\return BUFFER_E Returned if the given buffer is not large enough to
hold the encoded certificate
\return MP_INIT_E may be returned if there is an error generating
the signature
\return MP_READ_E may be returned if there is an error generating
the signature
\return MP_CMP_E may be returned if there is an error generating
the signature
\return MP_INVMOD_E may be returned if there is an error generating
the signature
\return MP_EXPTMOD_E may be returned if there is an error generating
the signature
\return MP_MOD_E may be returned if there is an error generating
the signature
\return MP_MUL_E may be returned if there is an error generating
the signature
\return MP_ADD_E may be returned if there is an error generating
the signature
\return MP_MULMOD_E may be returned if there is an error generating
the signature
\return MP_TO_E may be returned if there is an error generating
the signature
\return MP_MEM may be returned if there is an error generating the signature
\param pkcs7 pointer to the PKCS7 structure in which to store the parsed
certificates
\param hashBuf pointer to computed hash for the content data
\param hashSz size of the digest
\param pkiMsgHead pointer to the buffer containing the signed message header
to verify and decode
\param pkiMsgHeadSz size of the signed message header
\param pkiMsgFoot pointer to the buffer containing the signed message footer
to verify and decode
\param pkiMsgFootSz size of the signed message footer
_Example_
\code
PKCS7 pkcs7;
int ret;
byte data[] = {}; // initialize with data to sign
byte pkcs7HeadBuff[] = {}; // initialize with PKCS7 header
byte pkcs7FootBuff[] = {}; // initialize with PKCS7 footer
enum wc_HashType hashType = WC_HASH_TYPE_SHA;
byte hashBuf[WC_MAX_DIGEST_SIZE];
word32 hashSz = wc_HashGetDigestSize(hashType);
wc_PKCS7_InitWithCert(&pkcs7, NULL, 0);
// update message and data to encode
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
pkcs7.content = NULL;
pkcs7.contentSz = dataSz;
pkcs7.rng = &rng;
... etc.
// calculate hash for content
ret = wc_HashInit(&hash, hashType);
if (ret == 0) {
ret = wc_HashUpdate(&hash, hashType, data, sizeof(data));
if (ret == 0) {
ret = wc_HashFinal(&hash, hashType, hashBuf);
}
wc_HashFree(&hash, hashType);
}
ret = wc_PKCS7_VerifySignedData_ex(&pkcs7, hashBuf, hashSz, pkcs7HeadBuff,
sizeof(pkcs7HeadBuff), pkcs7FootBuff, sizeof(pkcs7FootBuff));
if ( ret != 0 ) {
// error encoding into output buffer
}
wc_PKCS7_Free(&pkcs7);
\endcode
\sa wc_PKCS7_InitWithCert
\sa wc_PKCS7_EncodeSignedData_ex
*/
int wc_PKCS7_VerifySignedData_ex(PKCS7* pkcs7, const byte* hashBuf,
word32 hashSz, byte* pkiMsgHead, word32 pkiMsgHeadSz, byte* pkiMsgFoot,
word32 pkiMsgFootSz);
/*!
\ingroup PKCS7
\brief This function builds the PKCS7 enveloped data content type, encoding
the PKCS7 structure into a buffer containing a parsable PKCS7 enveloped
data packet.
\return Success Returned on successfully encoding the message in enveloped
data format, returns the size written to the output buffer
\return BAD_FUNC_ARG: Returned if one of the input parameters is invalid,
or if the PKCS7 structure is missing required elements
\return ALGO_ID_E Returned if the PKCS7 structure is using an unsupported
algorithm type. Currently, only DESb and DES3b are supported
\return BUFFER_E Returned if the given output buffer is too small to store
the output data
\return MEMORY_E Returned if there is an error allocating memory
\return RNG_FAILURE_E Returned if there is an error initializing the random
number generator for encryption
\return DRBG_FAILED Returned if there is an error generating numbers with
the random number generator used for encryption
\param pkcs7 pointer to the PKCS7 structure to encode
\param output pointer to the buffer in which to store the encoded
certificate
\param outputSz size available in the output buffer
_Example_
\code
PKCS7 pkcs7;
int ret;
byte derBuff[] = { }; // initialize with DER-encoded certificate
byte pkcs7Buff[FOURK_BUF];
wc_PKCS7_InitWithCert(&pkcs7, derBuff, sizeof(derBuff));
// update message and data to encode
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
pkcs7.content = data;
pkcs7.contentSz = dataSz;
... etc.
ret = wc_PKCS7_EncodeEnvelopedData(&pkcs7, pkcs7Buff, sizeof(pkcs7Buff));
if ( ret != 0 ) {
// error encoding into output buffer
}
\endcode
\sa wc_PKCS7_InitWithCert
\sa wc_PKCS7_DecodeEnvelopedData
*/
int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7,
byte* output, word32 outputSz);
/*!
\ingroup PKCS7
\brief This function unwraps and decrypts a PKCS7 enveloped data content
type, decoding the message into output. It uses the private key of the
PKCS7 object passed in to decrypt the message.
\return On successfully extracting the information from the message,
returns the bytes written to output
\return BAD_FUNC_ARG Returned if one of the input parameters is invalid
\return ASN_PARSE_E Returned if there is an error parsing from the
given pkiMsg
\return PKCS7_OID_E Returned if the given pkiMsg is not an enveloped
data type
\return ASN_VERSION_E Returned if the PKCS7 signer info is not version 0
\return MEMORY_E Returned if there is an error allocating memory
\return ALGO_ID_E Returned if the PKCS7 structure is using an unsupported
algorithm type. Currently, only DESb and DES3b are supported for
encryption, with RSAk for signature generation
\return PKCS7_RECIP_E Returned if there is no recipient found in the
enveloped data that matches the recipient provided
\return RSA_BUFFER_E Returned if there is an error during RSA signature
verification due to buffer error, output too small or input too large.
\return MP_INIT_E may be returned if there is an error during signature
verification
\return MP_READ_E may be returned if there is an error during signature
verification
\return MP_CMP_E may be returned if there is an error during signature
verification
\return MP_INVMOD_E may be returned if there is an error during signature
verification
\return MP_EXPTMOD_E may be returned if there is an error during signature
verification
\return MP_MOD_E may be returned if there is an error during signature
verification
\return MP_MUL_E may be returned if there is an error during signature
verification
\return MP_ADD_E may be returned if there is an error during signature
verification
\return MP_MULMOD_E may be returned if there is an error during signature
verification
\return MP_TO_E may be returned if there is an error during signature
verification
\return MP_MEM may be returned if there is an error during signature
verification
\param pkcs7 pointer to the PKCS7 structure containing the private key with
which to decode the enveloped data package
\param pkiMsg pointer to the buffer containing the enveloped data package
\param pkiMsgSz size of the enveloped data package
\param output pointer to the buffer in which to store the decoded message
\param outputSz size available in the output buffer
_Example_
\code
PKCS7 pkcs7;
byte received[] = { }; // initialize with received enveloped message
byte decoded[FOURK_BUF];
int decodedSz;
// initialize pkcs7 with certificate
// update key
pkcs7.privateKey = key;
pkcs7.privateKeySz = keySz;
decodedSz = wc_PKCS7_DecodeEnvelopedData(&pkcs7, received,
sizeof(received),decoded, sizeof(decoded));
if ( decodedSz != 0 ) {
// error decoding message
}
\endcode
\sa wc_PKCS7_InitWithCert
\sa wc_PKCS7_EncodeEnvelopedData
*/
int wc_PKCS7_DecodeEnvelopedData(PKCS7* pkcs7, byte* pkiMsg,
word32 pkiMsgSz, byte* output,
word32 outputSz);

View File

@@ -0,0 +1,139 @@
/*!
\ingroup Poly1305
\brief This function sets the key for a Poly1305 context structure,
initializing it for hashing. Note: A new key should be set after
generating a message hash with wc_Poly1305Final to ensure security.
\return 0 Returned on successfully setting the key and initializing
the Poly1305 structure
\return BAD_FUNC_ARG Returned if the given key is not 32 bytes long,
or the Poly1305 context is NULL
\param ctx pointer to a Poly1305 structure to initialize
\param key pointer to the buffer containing the key to use for hashing
\param keySz size of the key in the buffer. Should be 32 bytes
_Example_
\code
Poly1305 enc;
byte key[] = { initialize with 32 byte key to use for hashing };
wc_Poly1305SetKey(&enc, key, sizeof(key));
\endcode
\sa wc_Poly1305Update
\sa wc_Poly1305Final
*/
int wc_Poly1305SetKey(Poly1305* poly1305, const byte* key,
word32 kySz);
/*!
\ingroup Poly1305
\brief This function updates the message to hash with the
Poly1305 structure.
\return 0 Returned on successfully updating the message to hash
\return BAD_FUNC_ARG Returned if the Poly1305 structure is NULL
\param ctx pointer to a Poly1305 structure for which to update
the message to hash
\param m pointer to the buffer containing the message which should
be added to the hash
\param bytes size of the message to hash
_Example_
\code
Poly1305 enc;
byte key[] = { }; // initialize with 32 byte key to use for encryption
byte msg[] = { }; // initialize with message to hash
wc_Poly1305SetKey(&enc, key, sizeof(key));
if( wc_Poly1305Update(key, msg, sizeof(msg)) != 0 ) {
// error updating message to hash
}
\endcode
\sa wc_Poly1305SetKey
\sa wc_Poly1305Final
*/
int wc_Poly1305Update(Poly1305* poly1305, const byte* m, word32 bytes);
/*!
\ingroup Poly1305
\brief This function calculates the hash of the input messages
and stores the result in mac. After this is called, the key
should be reset.
\return 0 Returned on successfully computing the final MAC
\return BAD_FUNC_ARG Returned if the Poly1305 structure is NULL
\param ctx pointer to a Poly1305 structure with which to generate the MAC
\param mac pointer to the buffer in which to store the MAC.
Should be POLY1305_DIGEST_SIZE (16 bytes) wide
_Example_
\code
Poly1305 enc;
byte mac[POLY1305_DIGEST_SIZE]; // space for a 16 byte mac
byte key[] = { }; // initialize with 32 byte key to use for encryption
byte msg[] = { }; // initialize with message to hash
wc_Poly1305SetKey(&enc, key, sizeof(key));
wc_Poly1305Update(key, msg, sizeof(msg));
if ( wc_Poly1305Final(&enc, mac) != 0 ) {
// error computing final MAC
}
\endcode
\sa wc_Poly1305SetKey
\sa wc_Poly1305Update
*/
int wc_Poly1305Final(Poly1305* poly1305, byte* tag);
/*!
\ingroup Poly1305
\brief Takes in an initialized Poly1305 struct that has a key
loaded and creates a MAC (tag) using recent TLS AEAD padding scheme.
\return 0 Success
\return BAD_FUNC_ARG Returned if ctx, input, or tag is null or if
additional is null and addSz is greater than 0 or if tagSz is less
than WC_POLY1305_MAC_SZ.
\param ctx Initialized Poly1305 struct to use
\param additional Additional data to use
\param addSz Size of additional buffer
\param input Input buffer to create tag from
\param sz Size of input buffer
\param tag Buffer to hold created tag
\param tagSz Size of input tag buffer (must be at least
WC_POLY1305_MAC_SZ(16))
_Example_
\code
Poly1305 ctx;
byte key[] = { }; // initialize with 32 byte key to use for hashing
byte additional[] = { }; // initialize with additional data
byte msg[] = { }; // initialize with message
byte tag[16];
wc_Poly1305SetKey(&ctx, key, sizeof(key));
if(wc_Poly1305_MAC(&ctx, additional, sizeof(additional), (byte*)msg,
sizeof(msg), tag, sizeof(tag)) != 0)
{
// Handle the error
}
\endcode
\sa wc_Poly1305SetKey
\sa wc_Poly1305Update
\sa wcPoly1305Final
*/
int wc_Poly1305_MAC(Poly1305* ctx, byte* additional, word32 addSz,
byte* input, word32 sz, byte* tag, word32 tagSz);

View File

@@ -0,0 +1,96 @@
/*!
\ingroup PSA
\brief This function enables PSA support on the given context.
\param ctx pointer to the WOLFSSL_CTX object on which the PSA support must be enabled
\return WOLFSSL_SUCCESS on success
\return BAD_FUNC_ARG if ctx == NULL
_Example_
\code
WOLFSSL_CTX *ctx;
ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
if (!ctx)
return NULL;
ret = wolfSSL_CTX_psa_enable(ctx);
if (ret != WOLFSSL_SUCCESS)
printf("can't enable PSA on ctx");
\endcode
\sa wolfSSL_set_psa_ctx
*/
int wolfSSL_CTX_psa_enable(WOLFSSL_CTX *ctx);
/*!
\ingroup PSA
\brief This function setup the PSA context for the given SSL session
\param ssl pointer to the WOLFSSL where the ctx will be enabled
\param ctx pointer to a struct psa_ssl_ctx (must be unique for a ssl session)
\return WOLFSSL_SUCCESS on success
\return BAD_FUNC_ARG if ssl or ctx are NULL
This function setup the PSA context for the TLS callbacks to the given SSL
session. At the end of the session, the resources used by the context
should be freed using wolfSSL_free_psa_ctx().
_Example_
\code
// Create new ssl session
WOLFSSL *ssl;
struct psa_ssl_ctx psa_ctx = { 0 };
ssl = wolfSSL_new(ctx);
if (!ssl)
return NULL;
// setup PSA context
ret = wolfSSL_set_psa_ctx(ssl, ctx);
\endcode
\sa wolfSSL_psa_set_private_key_id
\sa wolfSSL_psa_free_psa_ctx
*/
int wolfSSL_set_psa_ctx(WOLFSSL *ssl, struct psa_ssl_ctx *ctx);
/*!
\ingroup PSA
\brief This function releases the resources used by a PSA context
\param ctx pointer to a struct psa_ssl_ctx
\sa wolfSSL_set_psa_ctx
*/
void wolfSSL_free_psa_ctx(struct psa_ssl_ctx *ctx);
/*!
\ingroup PSA
\brief This function set the private key used by an SSL session
\param ctx pointer to a struct psa_ssl_ctx
\param id PSA id of the key to be used as private key
_Example_
\code
// Create new ssl session
WOLFSSL *ssl;
struct psa_ssl_ctx psa_ctx = { 0 };
psa_key_id_t key_id;
// key provisioning already done
get_private_key_id(&key_id);
ssl = wolfSSL_new(ctx);
if (!ssl)
return NULL;
wolfSSL_psa_set_private_key_id(&psa_ctx, key_id);
wolfSSL_set_psa_ctx(ssl, ctx);
\endcode
\sa wolfSSL_set_psa_ctx
*/
int wolfSSL_psa_set_private_key_id(struct psa_ssl_ctx *ctx,
psa_key_id_t id);

View File

@@ -0,0 +1,170 @@
/*!
\ingroup Password
\brief This function implements the Password Based Key Derivation
Function 1 (PBKDF1), converting an input password with a concatenated salt
into a more secure key, which it stores in output. It allows the user to
select between SHA and MD5 as hash functions.
\return 0 Returned on successfully deriving a key from the input password
\return BAD_FUNC_ARG Returned if there is an invalid hash type given
(valid type are: MD5 and SHA), iterations is less than 1, or the key
length (kLen) requested is greater than the hash length of the provided hash
\return MEMORY_E Returned if there is an error allocating memory for a
SHA or MD5 object
\param output pointer to the buffer in which to store the generated key.
Should be at least kLen long
\param passwd pointer to the buffer containing the password to use for
the key derivation
\param pLen length of the password to use for key derivation
\param salt pointer to the buffer containing the salt to use for
key derivation
\param sLen length of the salt
\param iterations number of times to process the hash
\param kLen desired length of the derived key. Should not be longer
than the digest size of the hash chosen
\param hashType the hashing algorithm to use. Valid choices are WC_MD5 and WC_SHA
_Example_
\code
int ret;
byte key[WC_MD5_DIGEST_SIZE];
byte pass[] = { }; // initialize with password
byte salt[] = { }; // initialize with salt
ret = wc_PBKDF1(key, pass, sizeof(pass), salt, sizeof(salt), 1000,
sizeof(key), WC_MD5);
if ( ret != 0 ) {
// error deriving key from password
}
\endcode
\sa wc_PBKDF2
\sa wc_PKCS12_PBKDF
*/
int wc_PBKDF1(byte* output, const byte* passwd, int pLen,
const byte* salt, int sLen, int iterations, int kLen,
int typeH);
/*!
\ingroup Password
\brief This function implements the Password Based Key Derivation
Function 2 (PBKDF2), converting an input password with a concatenated
salt into a more secure key, which it stores in output. It allows the user
to select any of the supported HMAC hash functions, including: WC_MD5,
WC_SHA, WC_SHA256, WC_SHA384, WC_SHA512, WC_SHA3_224, WC_SHA3_256,
WC_SHA3_384 or WC_SHA3_512
\return 0 Returned on successfully deriving a key from the input password
\return BAD_FUNC_ARG Returned if there is an invalid hash type given or
iterations is less than 1
\return MEMORY_E Returned if there is an allocating memory for
the HMAC object
\param output pointer to the buffer in which to store the generated key.
Should be kLen long
\param passwd pointer to the buffer containing the password to use for
the key derivation
\param pLen length of the password to use for key derivation
\param salt pointer to the buffer containing the salt to use for
key derivation
\param sLen length of the salt
\param iterations number of times to process the hash
\param kLen desired length of the derived key
\param hashType the hashing algorithm to use. Valid choices are: WC_MD5,
WC_SHA, WC_SHA256, WC_SHA384, WC_SHA512, WC_SHA3_224, WC_SHA3_256,
WC_SHA3_384 or WC_SHA3_512
_Example_
\code
int ret;
byte key[64];
byte pass[] = { }; // initialize with password
byte salt[] = { }; // initialize with salt
ret = wc_PBKDF2(key, pass, sizeof(pass), salt, sizeof(salt), 2048, sizeof(key),
WC_SHA512);
if ( ret != 0 ) {
// error deriving key from password
}
\endcode
\sa wc_PBKDF1
\sa wc_PKCS12_PBKDF
*/
int wc_PBKDF2(byte* output, const byte* passwd, int pLen,
const byte* salt, int sLen, int iterations, int kLen,
int typeH);
/*!
\ingroup Password
\brief This function implements the Password Based Key Derivation Function
(PBKDF) described in RFC 7292 Appendix B. This function converts an input
password with a concatenated salt into a more secure key, which it stores
in output. It allows the user to select any of the supported HMAC hash
functions, including: WC_MD5, WC_SHA, WC_SHA256, WC_SHA384, WC_SHA512,
WC_SHA3_224, WC_SHA3_256, WC_SHA3_384 or WC_SHA3_512
\return 0 Returned on successfully deriving a key from the input password
\return BAD_FUNC_ARG Returned if there is an invalid hash type given,
iterations is less than 1, or the key length (kLen) requested is greater
than the hash length of the provided hash
\return MEMORY_E Returned if there is an allocating memory
\return MP_INIT_E may be returned if there is an error during key generation
\return MP_READ_E may be returned if there is an error during key generation
\return MP_CMP_E may be returned if there is an error during key generation
\return MP_INVMOD_E may be returned if there is an error during
key generation
\return MP_EXPTMOD_E may be returned if there is an error during
key generation
\return MP_MOD_E may be returned if there is an error during key generation
\return MP_MUL_E may be returned if there is an error during key generation
\return MP_ADD_E may be returned if there is an error during key generation
\return MP_MULMOD_E may be returned if there is an error during
key generation
\return MP_TO_E may be returned if there is an error during key generation
\return MP_MEM may be returned if there is an error during key generation
\param output pointer to the buffer in which to store the generated key.
Should be kLen long
\param passwd pointer to the buffer containing the password to use for
the key derivation
\param pLen length of the password to use for key derivation
\param salt pointer to the buffer containing the salt to use
for key derivation
\param sLen length of the salt
\param iterations number of times to process the hash
\param kLen desired length of the derived key
\param hashType the hashing algorithm to use. Valid choices are: WC_MD5,
WC_SHA, WC_SHA256, WC_SHA384, WC_SHA512, WC_SHA3_224, WC_SHA3_256,
WC_SHA3_384 or WC_SHA3_512
\param id this is a byte identifier indicating the purpose of key
generation. It is used to diversify the key output, and should be
assigned as follows: ID=1: pseudorandom bits are to be used as key
material for performing encryption or decryption. ID=2: pseudorandom
bits are to be used an IV (Initial Value) for encryption or decryption.
ID=3: pseudorandom bits are to be used as an integrity key for MACing.
_Example_
\code
int ret;
byte key[64];
byte pass[] = { }; // initialize with password
byte salt[] = { }; // initialize with salt
ret = wc_PKCS512_PBKDF(key, pass, sizeof(pass), salt, sizeof(salt), 2048,
sizeof(key), WC_SHA512, 1);
if ( ret != 0 ) {
// error deriving key from password
}
\endcode
\sa wc_PBKDF1
\sa wc_PBKDF2
*/
int wc_PKCS12_PBKDF(byte* output, const byte* passwd, int pLen,
const byte* salt, int sLen, int iterations,
int kLen, int typeH, int purpose);

View File

@@ -0,0 +1,606 @@
/*!
\ingroup QUIC
\brief Callback invoked when secrets are generated during a handshake.
Since QUIC protocol handlers perform the en-/decryption of packets, they
need the negotiated secrets for the levels early_data/handshake/application.
The callback will be invoked several times during a handshake. Either both
or only the read or write secret might be provided. This does not mean the
given encryption level is already in effect.
\return 1 on success, 0 on failure.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param level - the encryption level the secrets are for
\param read_secret - the secret used in decryption at the given level, may be NULL.
\param write_secret - the secret used in encryption at the given level, may be NULL.
\param secret_len - the length of the secret
\sa wolfSSL_set_quic_method
*/
int (*set_encryption_secrets)(WOLFSSL *ssl, WOLFSSL_ENCRYPTION_LEVEL level,
const uint8_t *read_secret,
const uint8_t *write_secret, size_t secret_len);
/*!
\ingroup QUIC
\brief Callback invoked for forwarding handshake CRYPTO data to peer.
The data forwarded this way is not encrypted. It is the job of the QUIC
protocol implementation to do this. Which secrets are to be used
is determined by the encryption level specified.
This callback may be invoked several times during handshake or post handshake
processing. The data may cover a complete CRYPTO record, but may also
be partial. However, the callback will have received all records data before
using another encryption level.
\return 1 on success, 0 on failure.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param level - the encryption level to use for encrypting the data
\param data - the data itself
\param len - the length of the data
\sa wolfSSL_set_quic_method
*/
int (*add_handshake_data)(WOLFSSL *ssl, WOLFSSL_ENCRYPTION_LEVEL level,
const uint8_t *data, size_t len);
/*!
\ingroup QUIC
\brief Callback invoked for advisory flushing of the data to send.
\return 1 on success, 0 on failure.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\sa wolfSSL_set_quic_method
*/
int (*flush_flight)(WOLFSSL *ssl);
/*!
\ingroup QUIC
\brief Callback invoked when an SSL alert happened during processing.
\return 1 on success, 0 on failure.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param level - the encryption level in effect when the alert happened
\param alert - the error
\sa wolfSSL_set_quic_method
*/
int (*send_alert)(WOLFSSL *ssl, WOLFSSL_ENCRYPTION_LEVEL level, uint8_t alert);
/*!
\ingroup QUIC
\brief Activate QUIC protocol for a WOLFSSL_CTX and all derived WOLFSSL instances
by providing the four callbacks required. The CTX needs to be a TLSv1.3 one.
The passed quic_method needs to have a lifetime outlasting the SSL instances.
It is not copied. All callbacks need to be provided.
\return WOLFSSL_SUCCESS If successful.
\param ctx - a pointer to a WOLFSSL_CTX structure, created using wolfSSL_CTX_new().
\param quic_method - the callback structure
\sa wolfSSL_is_quic
\sa wolfSSL_set_quic_method
*/
int wolfSSL_CTX_set_quic_method(WOLFSSL_CTX *ctx, const WOLFSSL_QUIC_METHOD *quic_method);
/*!
\ingroup QUIC
\brief Activate QUIC protocol for a WOLFSSL instance by providing the
four callbacks required. The WOLFSSL needs to be a TLSv1.3 one.
The passed quic_method needs to have a lifetime outlasting the SSL instance.
It is not copied. All callbacks need to be provided.
\return WOLFSSL_SUCCESS If successful.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param quic_method - the callback structure
\sa wolfSSL_is_quic
\sa wolfSSL_CTX_set_quic_method
*/
int wolfSSL_set_quic_method(WOLFSSL *ssl, const WOLFSSL_QUIC_METHOD *quic_method);
/*!
\ingroup QUIC
\brief Check if QUIC has been activated in a WOLFSSL instance.
\return 1 if WOLFSSL is using QUIC.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\sa wolfSSL_CTX_quic_method
\sa wolfSSL_CTX_set_quic_method
*/
int wolfSSL_is_quic(WOLFSSL *ssl);
/*!
\ingroup QUIC
\brief Determine the encryption level for reads currently in use. Meaningful only when
the WOLFSSL instance is using QUIC.
Note that the effective level is always a parameter when passing data back and
forth. Data from a peer might arrive at other levels than reported via this
function.
\return encryption level.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\sa wolfSSL_quic_write_level
*/
WOLFSSL_ENCRYPTION_LEVEL wolfSSL_quic_read_level(const WOLFSSL *ssl);
/*!
\ingroup QUIC
\brief Determine the encryption level for writes currently in use. Meaningful only when
the WOLFSSL instance is using QUIC.
Note that the effective level is always a parameter when passing data back and
forth. Data from a peer might arrive at other levels than reported via this
function.
\return encryption level.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\sa wolfSSL_quic_read_level
*/
WOLFSSL_ENCRYPTION_LEVEL wolfSSL_quic_write_level(const WOLFSSL *ssl);
/*!
\ingroup QUIC
\brief Configure which QUIC version shall be used. Without calling this,
the WOLFSSL will offer both (draft-27 and v1) to a server, resp. accept
both from a client and negotiate the most recent one.
\return WOLFSSL_SUCCESS If successful.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param use_legacy - true if draft-27 shall be used, 0 if only QUICv1 is used.
\sa wolfSSL_set_quic_transport_version
*/
void wolfSSL_set_quic_use_legacy_codepoint(WOLFSSL *ssl, int use_legacy);
/*!
\ingroup QUIC
\brief Configure which QUIC version shall be used.
\return WOLFSSL_SUCCESS If successful.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param version - the TLS Extension defined for the QUIC version.
\sa wolfSSL_set_quic_use_legacy_codepoint
*/
void wolfSSL_set_quic_transport_version(WOLFSSL *ssl, int version);
/*!
\ingroup QUIC
\brief Get the configured QUIC version.
\return TLS Extension of configured version.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\sa wolfSSL_set_quic_use_legacy_codepoint
\sa wolfSSL_set_quic_transport_version
*/
int wolfSSL_get_quic_transport_version(const WOLFSSL *ssl);
/*!
\ingroup QUIC
\brief Set the QUIC transport parameters to use.
\return WOLFSSL_SUCCESS If successful.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param params - the parameter bytes to use
·param params_len - the length of the parameters
\sa wolfSSL_set_quic_use_legacy_codepoint
\sa wolfSSL_set_quic_transport_version
*/
int wolfSSL_set_quic_transport_params(WOLFSSL *ssl, const uint8_t *params, size_t params_len);
/*!
\ingroup QUIC
\brief Get the negotiated QUIC transport version. This will only give
meaningful results when called after the respective TLS extensions have
been seen from the peer.
\return the negotiated version or -1.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\sa wolfSSL_set_quic_use_legacy_codepoint
\sa wolfSSL_set_quic_transport_version
*/
int wolfSSL_get_peer_quic_transport_version(const WOLFSSL *ssl);
/*!
\ingroup QUIC
\brief Get the negotiated QUIC transport parameters. This will only give
meaningful results when called after the respective TLS extensions have
been seen from the peer.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param out_params - the parameters sent be the peer, set to NULL if not available.
\param out_params_len - the length of the parameters sent be the peer, set to 0 if not available
\sa wolfSSL_get_peer_quic_transport_version
*/
void wolfSSL_get_peer_quic_transport_params(const WOLFSSL *ssl, const uint8_t **out_params, size_t *out_params_len);
/*!
\ingroup QUIC
\brief Configure if Early Data is enabled. Intended for servers to signal
this to clients.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param enabled - != 0 iff early data is enabled
*/
void wolfSSL_set_quic_early_data_enabled(WOLFSSL *ssl, int enabled);
/*!
\ingroup QUIC
\brief Get advice on the amount of data that shall be "in flight", e.g. unacknowledged
at the given encryption level. This is the amount of data the WOLFSSL instance
is prepared to buffer.
\return the recommend max data in flight
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param level - the encryption level to inquire about
*/
size_t wolfSSL_quic_max_handshake_flight_len(const WOLFSSL *ssl, WOLFSSL_ENCRYPTION_LEVEL level);
/*!
\ingroup QUIC
\brief Pass decrypted CRYPTO data to the WOLFSSL instance for further processing.
The encryption level between calls is only every allowed to increase and it is
also checked that data records are complete before a change in encryption
level is accepted.
\return WOLFSSL_SUCCESS If successful.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\param level - the level the data was encrypted at
\param data - the data itself
\param len - the length of the data
\sa wolfSSL_process_quic_post_handshake
\sa wolfSSL_quic_read_write
\sa wolfSSL_accept
\sa wolfSSL_connect
*/
int wolfSSL_provide_quic_data(WOLFSSL *ssl, WOLFSSL_ENCRYPTION_LEVEL level, const uint8_t *data, size_t len);
/*!
\ingroup QUIC
\brief Process any CRYPTO records that have been provided after the handshake
has completed. Will fail if called before that.
\return WOLFSSL_SUCCESS If successful.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\sa wolfSSL_provide_quic_data
\sa wolfSSL_quic_read_write
\sa wolfSSL_accept
\sa wolfSSL_connect
*/
WOLFSSL_API int wolfSSL_process_quic_post_handshake(WOLFSSL *ssl);
/*!
\ingroup QUIC
\brief Process any CRYPTO records that have been provided during or after the handshake.
Will progress the handshake if not already complete and otherwise work like
wolfSSL_process_quic_post_handshake().
\return WOLFSSL_SUCCESS If successful.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\sa wolfSSL_provide_quic_data
\sa wolfSSL_quic_read_write
\sa wolfSSL_accept
\sa wolfSSL_connect
*/
int wolfSSL_quic_read_write(WOLFSSL *ssl);
/*!
\ingroup QUIC
\brief Get the AEAD cipher negotiated in the TLS handshake.
\return negotiated cipher or NULL if not determined.
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\sa wolfSSL_quic_aead_is_gcm
\sa wolfSSL_quic_aead_is_ccm
\sa wolfSSL_quic_aead_is_chacha20
\sa wolfSSL_quic_get_aead_tag_len
\sa wolfSSL_quic_get_md
\sa wolfSSL_quic_get_hp
\sa wolfSSL_quic_crypt_new
\sa wolfSSL_quic_aead_encrypt
\sa wolfSSL_quic_aead_decrypt
*/
const WOLFSSL_EVP_CIPHER *wolfSSL_quic_get_aead(WOLFSSL *ssl);
/*!
\ingroup QUIC
\brief Check if the AEAD cipher is GCM.
\return != 0 iff the AEAD cipher is GCM.
\param cipher - the cipher
\sa wolfSSL_quic_get_aead
\sa wolfSSL_quic_aead_is_ccm
\sa wolfSSL_quic_aead_is_chacha20
\sa wolfSSL_quic_get_aead_tag_len
\sa wolfSSL_quic_get_md
\sa wolfSSL_quic_get_hp
\sa wolfSSL_quic_crypt_new
\sa wolfSSL_quic_aead_encrypt
\sa wolfSSL_quic_aead_decrypt
*/
int wolfSSL_quic_aead_is_gcm(const WOLFSSL_EVP_CIPHER *aead_cipher);
/*!
\ingroup QUIC
\brief Check if the AEAD cipher is CCM.
\return != 0 iff the AEAD cipher is CCM.
\param cipher - the cipher
\sa wolfSSL_quic_get_aead
\sa wolfSSL_quic_aead_is_gcm
\sa wolfSSL_quic_aead_is_chacha20
\sa wolfSSL_quic_get_aead_tag_len
\sa wolfSSL_quic_get_md
\sa wolfSSL_quic_get_hp
\sa wolfSSL_quic_crypt_new
\sa wolfSSL_quic_aead_encrypt
\sa wolfSSL_quic_aead_decrypt
*/
int wolfSSL_quic_aead_is_ccm(const WOLFSSL_EVP_CIPHER *aead_cipher);
/*!
\ingroup QUIC
\brief Check if the AEAD cipher is CHACHA20.
\return != 0 iff the AEAD cipher is CHACHA20.
\param cipher - the cipher
\sa wolfSSL_quic_get_aead
\sa wolfSSL_quic_aead_is_ccm
\sa wolfSSL_quic_aead_is_gcm
\sa wolfSSL_quic_get_aead_tag_len
\sa wolfSSL_quic_get_md
\sa wolfSSL_quic_get_hp
\sa wolfSSL_quic_crypt_new
\sa wolfSSL_quic_aead_encrypt
\sa wolfSSL_quic_aead_decrypt
*/
int wolfSSL_quic_aead_is_chacha20(const WOLFSSL_EVP_CIPHER *aead_cipher);
/*!
\ingroup QUIC
\brief Determine the tag length for the AEAD cipher.
\return tag length of AEAD cipher.
\param cipher - the cipher
\sa wolfSSL_quic_get_aead
*/
WOLFSSL_API size_t wolfSSL_quic_get_aead_tag_len(const WOLFSSL_EVP_CIPHER *aead_cipher);
/*!
\ingroup QUIC
\brief Determine the message digest negotiated in the TLS handshake.
\return the message digest negotiated in the TLS handshake
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\sa wolfSSL_quic_get_aead
\sa wolfSSL_quic_get_hp
*/
WOLFSSL_API const WOLFSSL_EVP_MD *wolfSSL_quic_get_md(WOLFSSL *ssl);
/*!
\ingroup QUIC
\brief Determine the header protection cipher negotiated in the TLS handshake.
\return the header protection cipher negotiated in the TLS handshake
\param ssl - a pointer to a WOLFSSL structure, created using wolfSSL_new().
\sa wolfSSL_quic_get_aead
\sa wolfSSL_quic_get_md
*/
const WOLFSSL_EVP_CIPHER *wolfSSL_quic_get_hp(WOLFSSL *ssl);
/*!
\ingroup QUIC
\brief Create a cipher context for en-/decryption.
\return the created context or NULL in case of errors.
\param cipher - the cipher to use in the context.
\param key - the key to use in the context.
\param iv - the iv to use in the context.
\param encrypt - != 0 if for encryption, otherwise decryption
\sa wolfSSL_quic_get_aead
\sa wolfSSL_quic_get_hp
\sa wolfSSL_quic_aead_encrypt
\sa wolfSSL_quic_aead_decrypt
*/
WOLFSSL_EVP_CIPHER_CTX *wolfSSL_quic_crypt_new(const WOLFSSL_EVP_CIPHER *cipher,
const uint8_t *key, const uint8_t *iv, int encrypt);
/*!
\ingroup QUIC
\brief Encrypt the plain text in the given context.
\return WOLFSSL_SUCCESS If successful.
\param dest - destination where encrypted data is to be written
\param aead_ctx - the cipher context to use
\param plain - the plain data to encrypt
\param plainlen - the length of the plain data
\param iv - the iv to use
\param aad - the add to use
\param aadlen - the length of the aad
\sa wolfSSL_quic_get_aead
\sa wolfSSL_quic_get_hp
\sa wolfSSL_quic_crypt_new
\sa wolfSSL_quic_aead_decrypt
*/
int wolfSSL_quic_aead_encrypt(uint8_t *dest, WOLFSSL_EVP_CIPHER_CTX *aead_ctx,
const uint8_t *plain, size_t plainlen,
const uint8_t *iv, const uint8_t *aad, size_t aadlen);
/*!
\ingroup QUIC
\brief Decrypt the cipher text in the given context.
\return WOLFSSL_SUCCESS If successful.
\param dest - destination where plain text is to be written
\param ctx - the cipher context to use
\param enc - the encrypted data to decrypt
\param envlen - the length of the encrypted data
\param iv - the iv to use
\param aad - the add to use
\param aadlen - the length of the aad
\sa wolfSSL_quic_get_aead
\sa wolfSSL_quic_get_hp
\sa wolfSSL_quic_crypt_new
\sa wolfSSL_quic_aead_encrypt
*/
int wolfSSL_quic_aead_decrypt(uint8_t *dest, WOLFSSL_EVP_CIPHER_CTX *ctx,
const uint8_t *enc, size_t enclen,
const uint8_t *iv, const uint8_t *aad, size_t aadlen);
/*!
\ingroup QUIC
\brief Extract a pseudo random key.
\return WOLFSSL_SUCCESS If successful.
\param dest - destination where key is to be written
\param md - message digest to use
\param secret - the secret to use
\param secretlen - the length of the secret
\param salt - the salt to use
\param saltlen - the length of the salt
\sa wolfSSL_quic_hkdf_expand
\sa wolfSSL_quic_hkdf
*/
int wolfSSL_quic_hkdf_extract(uint8_t *dest, const WOLFSSL_EVP_MD *md,
const uint8_t *secret, size_t secretlen,
const uint8_t *salt, size_t saltlen);
/*!
\ingroup QUIC
\brief Expand a pseudo random key into a new key.
\return WOLFSSL_SUCCESS If successful.
\param dest - destination where key is to be written
\param destlen - length of the key to expand
\param md - message digest to use
\param secret - the secret to use
\param secretlen - the length of the secret
\param info - the info to use
\param infolen - the length of the info
\sa wolfSSL_quic_hkdf_extract
\sa wolfSSL_quic_hkdf
*/
int wolfSSL_quic_hkdf_expand(uint8_t *dest, size_t destlen,
const WOLFSSL_EVP_MD *md,
const uint8_t *secret, size_t secretlen,
const uint8_t *info, size_t infolen);
/*!
\ingroup QUIC
\brief Expand and Extract a pseudo random key.
\return WOLFSSL_SUCCESS If successful.
\param dest - destination where key is to be written
\param destlen - length of the key
\param md - message digest to use
\param secret - the secret to use
\param secretlen - the length of the secret
\param salt - the salt to use
\param saltlen - the length of the salt
\param info - the info to use
\param infolen - the length of the info
\sa wolfSSL_quic_hkdf_extract
\sa wolfSSL_quic_hkdf_expand
*/
int wolfSSL_quic_hkdf(uint8_t *dest, size_t destlen,
const WOLFSSL_EVP_MD *md,
const uint8_t *secret, size_t secretlen,
const uint8_t *salt, size_t saltlen,
const uint8_t *info, size_t infolen);

View File

@@ -0,0 +1,328 @@
/*!
\ingroup Random
\brief Init global Whitewood netRandom context
\return 0 Success
\return BAD_FUNC_ARG Either configFile is null or timeout is negative.
\return RNG_FAILURE_E There was a failure initializing the rng.
\param configFile Path to configuration file
\param hmac_cb Optional to create HMAC callback.
\param timeout A timeout duration.
_Example_
\code
char* config = "path/to/config/example.conf";
int time = // Some sufficient timeout value;
if (wc_InitNetRandom(config, NULL, time) != 0)
{
// Some error occurred
}
\endcode
\sa wc_FreeNetRandom
*/
int wc_InitNetRandom(const char* configFile, wnr_hmac_key hmac_cb, int timeout);
/*!
\ingroup Random
\brief Free global Whitewood netRandom context.
\return 0 Success
\return BAD_MUTEX_E Error locking mutex on wnr_mutex
\param none No returns.
_Example_
\code
int ret = wc_FreeNetRandom();
if(ret != 0)
{
// Handle the error
}
\endcode
\sa wc_InitNetRandom
*/
int wc_FreeNetRandom(void);
/*!
\ingroup Random
\brief Gets the seed (from OS) and key cipher for rng. rng->drbg
(deterministic random bit generator) allocated (should be deallocated
with wc_FreeRng). This is a blocking operation.
\return 0 on success.
\return MEMORY_E XMALLOC failed
\return WINCRYPT_E wc_GenerateSeed: failed to acquire context
\return CRYPTGEN_E wc_GenerateSeed: failed to get random
\return BAD_FUNC_ARG wc_RNG_GenerateBlock input is null or sz exceeds
MAX_REQUEST_LEN
\return DRBG_CONT_FIPS_E wc_RNG_GenerateBlock: Hash_gen returned
DRBG_CONT_FAILURE
\return RNG_FAILURE_E wc_RNG_GenerateBlock: Default error. rngs
status originally not ok, or set to DRBG_FAILED
\param rng random number generator to be initialized for use
with a seed and key cipher
_Example_
\code
RNG rng;
int ret;
#ifdef HAVE_CAVIUM
ret = wc_InitRngCavium(&rng, CAVIUM_DEV_ID);
if (ret != 0){
printf(“RNG Nitrox init for device: %d failed”, CAVIUM_DEV_ID);
return -1;
}
#endif
ret = wc_InitRng(&rng);
if (ret != 0){
printf(“RNG init failed”);
return -1;
}
\endcode
\sa wc_InitRngCavium
\sa wc_RNG_GenerateBlock
\sa wc_RNG_GenerateByte
\sa wc_FreeRng
\sa wc_RNG_HealthTest
*/
int wc_InitRng(WC_RNG*);
/*!
\ingroup Random
\brief Copies a sz bytes of pseudorandom data to output. Will
reseed rng if needed (blocking).
\return 0 on success
\return BAD_FUNC_ARG an input is null or sz exceeds MAX_REQUEST_LEN
\return DRBG_CONT_FIPS_E Hash_gen returned DRBG_CONT_FAILURE
\return RNG_FAILURE_E Default error. rngs status originally not
ok, or set to DRBG_FAILED
\param rng random number generator initialized with wc_InitRng
\param output buffer to which the block is copied
\param sz size of output in bytes
_Example_
\code
RNG rng;
int sz = 32;
byte block[sz];
int ret = wc_InitRng(&rng);
if (ret != 0) {
return -1; //init of rng failed!
}
ret = wc_RNG_GenerateBlock(&rng, block, sz);
if (ret != 0) {
return -1; //generating block failed!
}
\endcode
\sa wc_InitRngCavium, wc_InitRng
\sa wc_RNG_GenerateByte
\sa wc_FreeRng
\sa wc_RNG_HealthTest
*/
int wc_RNG_GenerateBlock(WC_RNG* rng, byte* b, word32 sz);
/*!
\ingroup Random
\brief Creates a new WC_RNG structure.
\return WC_RNG structure on success
\return NULL on error
\param heap pointer to a heap identifier
\param nonce pointer to the buffer containing the nonce
\param nonceSz length of the nonce
_Example_
\code
RNG rng;
byte nonce[] = { initialize nonce };
word32 nonceSz = sizeof(nonce);
wc_rng_new(&nonce, nonceSz, &heap);
\endcode
\sa wc_InitRng
\sa wc_rng_free
\sa wc_FreeRng
\sa wc_RNG_HealthTest
*/
WC_RNG* wc_rng_new(byte* nonce, word32 nonceSz, void* heap)
/*!
\ingroup Random
\brief Calls wc_RNG_GenerateBlock to copy a byte of pseudorandom
data to b. Will reseed rng if needed.
\return 0 on success
\return BAD_FUNC_ARG an input is null or sz exceeds MAX_REQUEST_LEN
\return DRBG_CONT_FIPS_E Hash_gen returned DRBG_CONT_FAILURE
\return RNG_FAILURE_E Default error. rngs status originally not
ok, or set to DRBG_FAILED
\param rng: random number generator initialized with wc_InitRng
\param b one byte buffer to which the block is copied
_Example_
\code
RNG rng;
int sz = 32;
byte b[1];
int ret = wc_InitRng(&rng);
if (ret != 0) {
return -1; //init of rng failed!
}
ret = wc_RNG_GenerateByte(&rng, b);
if (ret != 0) {
return -1; //generating block failed!
}
\endcode
\sa wc_InitRngCavium
\sa wc_InitRng
\sa wc_RNG_GenerateBlock
\sa wc_FreeRng
\sa wc_RNG_HealthTest
*/
int wc_RNG_GenerateByte(WC_RNG* rng, byte* b);
/*!
\ingroup Random
\brief Should be called when RNG no longer needed in order to securely
free drgb. Zeros and XFREEs rng-drbg.
\return 0 on success
\return BAD_FUNC_ARG rng or rng->drgb null
\return RNG_FAILURE_E Failed to deallocated drbg
\param rng random number generator initialized with wc_InitRng
_Example_
\code
RNG rng;
int ret = wc_InitRng(&rng);
if (ret != 0) {
return -1; //init of rng failed!
}
int ret = wc_FreeRng(&rng);
if (ret != 0) {
return -1; //free of rng failed!
}
\endcode
\sa wc_InitRngCavium
\sa wc_InitRng
\sa wc_RNG_GenerateBlock
\sa wc_RNG_GenerateByte,
\sa wc_RNG_HealthTest
*/
int wc_FreeRng(WC_RNG*);
/*!
\ingroup Random
\brief Should be called when RNG no longer needed in order to securely
free rng.
\param rng random number generator initialized with wc_InitRng
_Example_
\code
RNG rng;
byte nonce[] = { initialize nonce };
word32 nonceSz = sizeof(nonce);
rng = wc_rng_new(&nonce, nonceSz, &heap);
// use rng
wc_rng_free(&rng);
\endcode
\sa wc_InitRng
\sa wc_rng_new
\sa wc_FreeRng
\sa wc_RNG_HealthTest
*/
WC_RNG* wc_rng_free(WC_RNG* rng);
/*!
\ingroup Random
\brief Creates and tests functionality of drbg.
\return 0 on success
\return BAD_FUNC_ARG entropyA and output must not be null. If reseed
set entropyB must not be null
\return -1 test failed
\param int reseed: if set, will test reseed functionality
\param entropyA: entropy to instantiate drgb with
\param entropyASz: size of entropyA in bytes
\param entropyB: If reseed set, drbg will be reseeded with entropyB
\param entropyBSz: size of entropyB in bytes
\param output: initialized to random data seeded with entropyB if
seedrandom is set, and entropyA otherwise
\param outputSz: length of output in bytes
_Example_
\code
byte output[SHA256_DIGEST_SIZE * 4];
const byte test1EntropyB[] = ....; // test input for reseed false
const byte test1Output[] = ....; // testvector: expected output of
// reseed false
ret = wc_RNG_HealthTest(0, test1Entropy, sizeof(test1Entropy), NULL, 0,
output, sizeof(output));
if (ret != 0)
return -1;//healthtest without reseed failed
if (XMEMCMP(test1Output, output, sizeof(output)) != 0)
return -1; //compare to testvector failed: unexpected output
const byte test2EntropyB[] = ....; // test input for reseed
const byte test2Output[] = ....; // testvector expected output of reseed
ret = wc_RNG_HealthTest(1, test2EntropyA, sizeof(test2EntropyA),
test2EntropyB, sizeof(test2EntropyB),
output, sizeof(output));
if (XMEMCMP(test2Output, output, sizeof(output)) != 0)
return -1; //compare to testvector failed
\endcode
\sa wc_InitRngCavium
\sa wc_InitRng
\sa wc_RNG_GenerateBlock
\sa wc_RNG_GenerateByte
\sa wc_FreeRng
*/
int wc_RNG_HealthTest(int reseed,
const byte* entropyA, word32 entropyASz,
const byte* entropyB, word32 entropyBSz,
byte* output, word32 outputSz);

View File

@@ -0,0 +1,103 @@
/*!
\ingroup RIPEMD
\brief This function initializes a ripemd structure by initializing
ripemds digest, buffer, loLen and hiLen.
\return 0 returned on successful execution of the function. The RipeMd
structure is initialized.
\return BAD_FUNC_ARG returned if the RipeMd structure is NULL.
\param ripemd pointer to the ripemd structure to initialize
_Example_
\code
RipeMd md;
int ret;
ret = wc_InitRipeMd(&md);
if (ret != 0) {
// Failure case.
}
\endcode
\sa wc_RipeMdUpdate
\sa wc_RipeMdFinal
*/
int wc_InitRipeMd(RipeMd*);
/*!
\ingroup RIPEMD
\brief This function generates the RipeMd digest of the data input and
stores the result in the ripemd->digest buffer. After running
wc_RipeMdUpdate, one should compare the generated ripemd->digest to a
known authentication tag to verify the authenticity of a message.
\return 0 Returned on successful execution of the function.
\return BAD_FUNC_ARG Returned if the RipeMd structure is NULL or if data
is NULL and len is not zero. This function should execute if data is NULL
and len is 0.
\param ripemd: pointer to the ripemd structure to be initialized with
wc_InitRipeMd
\param data data to be hashed
\param len sizeof data in bytes
_Example_
\code
const byte* data; // The data to be hashed
....
RipeMd md;
int ret;
ret = wc_InitRipeMd(&md);
if (ret == 0) {
ret = wc_RipeMdUpdate(&md, plain, sizeof(plain));
if (ret != 0) {
// Failure case …
\endcode
\sa wc_InitRipeMd
\sa wc_RipeMdFinal
*/
int wc_RipeMdUpdate(RipeMd* ripemd, const byte* data, word32 len);
/*!
\ingroup RIPEMD
\brief This function copies the computed digest into hash. If there is a
partial unhashed block, this method will pad the block with 0s, and
include that blocks round in the digest before copying to hash. State
of ripemd is reset.
\return 0 Returned on successful execution of the function. The state of
the RipeMd structure has been reset.
\return BAD_FUNC_ARG Returned if the RipeMd structure or hash parameters
are NULL.
\param ripemd pointer to the ripemd structure to be initialized with
wc_InitRipeMd, and containing hashes from wc_RipeMdUpdate. State will
be reset
\param hash buffer to copy digest to. Should be RIPEMD_DIGEST_SIZE bytes
_Example_
\code
RipeMd md;
int ret;
byte digest[RIPEMD_DIGEST_SIZE];
const byte* data; // The data to be hashed
...
ret = wc_InitRipeMd(&md);
if (ret == 0) {
ret = wc_RipeMdUpdate(&md, plain, sizeof(plain));
if (ret != 0) {
// RipeMd Update Failure Case.
}
ret = wc_RipeMdFinal(&md, digest);
if (ret != 0) {
// RipeMd Final Failure Case.
}...
\endcode
\sa none
*/
int wc_RipeMdFinal(RipeMd* ripemd, byte* hash);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,143 @@
/*!
\ingroup SAKKE_Setup
*/
int wc_InitSakkeKey(SakkeKey* key, void* heap, int devId);
/*!
\ingroup SAKKE_Setup
*/
int wc_InitSakkeKey_ex(SakkeKey* key, int keySize, int curveId,
void* heap, int devId);
/*!
\ingroup SAKKE_Setup
*/
void wc_FreeSakkeKey(SakkeKey* key);
/*!
\ingroup SAKKE_Setup
*/
int wc_MakeSakkeKey(SakkeKey* key, WC_RNG* rng);
/*!
\ingroup SAKKE_Setup
*/
int wc_MakeSakkePublicKey(SakkeKey* key, ecc_point* pub);
/*!
\ingroup SAKKE_RSK
*/
int wc_MakeSakkeRsk(SakkeKey* key, const byte* id, word16 idSz,
ecc_point* rsk);
/*!
\ingroup SAKKE_RSK
*/
int wc_ValidateSakkeRsk(SakkeKey* key, const byte* id, word16 idSz,
ecc_point* rsk, int* valid);
/*!
\ingroup SAKKE_RSK
*/
int wc_GenerateSakkeRskTable(const SakkeKey* key,
const ecc_point* rsk, byte* table, word32* len);
/*!
\ingroup SAKKE_Setup
*/
int wc_ExportSakkeKey(SakkeKey* key, byte* data, word32* sz);
/*!
\ingroup SAKKE_Setup
*/
int wc_ImportSakkeKey(SakkeKey* key, const byte* data, word32 sz);
/*!
\ingroup SAKKE_Setup
*/
int wc_ExportSakkePrivateKey(SakkeKey* key, byte* data, word32* sz);
/*!
\ingroup SAKKE_Setup
*/
int wc_ImportSakkePrivateKey(SakkeKey* key, const byte* data,
word32 sz);
/*!
\ingroup SAKKE_RSK
*/
int wc_EncodeSakkeRsk(const SakkeKey* key, ecc_point* rsk,
byte* out, word32* sz, int raw);
/*!
\ingroup SAKKE_RSK
*/
int wc_DecodeSakkeRsk(const SakkeKey* key, const byte* data,
word32 sz, ecc_point* rsk);
/*!
\ingroup SAKKE_RSK
*/
int wc_ImportSakkeRsk(SakkeKey* key, const byte* data, word32 sz);
/*!
\ingroup SAKKE_Setup
*/
int wc_ExportSakkePublicKey(SakkeKey* key, byte* data,
word32* sz, int raw);
/*!
\ingroup SAKKE_Setup
*/
int wc_ImportSakkePublicKey(SakkeKey* key, const byte* data,
word32 sz, int trusted);
/*!
\ingroup SAKKE_Operations
*/
int wc_GetSakkeAuthSize(SakkeKey* key, word16* authSz);
/*!
\ingroup SAKKE_Setup
*/
int wc_SetSakkeIdentity(SakkeKey* key, const byte* id, word16 idSz);
/*!
\ingroup SAKKE_Operations
*/
int wc_MakeSakkePointI(SakkeKey* key, const byte* id, word16 idSz);
/*!
\ingroup SAKKE_Operations
*/
int wc_GetSakkePointI(SakkeKey* key, byte* data, word32* sz);
/*!
\ingroup SAKKE_Operations
*/
int wc_SetSakkePointI(SakkeKey* key, const byte* id, word16 idSz,
const byte* data, word32 sz);
/*!
\ingroup SAKKE_Operations
*/
int wc_GenerateSakkePointITable(SakkeKey* key, byte* table,
word32* len);
/*!
\ingroup SAKKE_Operations
*/
int wc_SetSakkePointITable(SakkeKey* key, byte* table, word32 len);
/*!
\ingroup SAKKE_Operations
*/
int wc_ClearSakkePointITable(SakkeKey* key);
/*!
\ingroup SAKKE_Operations
*/
int wc_MakeSakkeEncapsulatedSSV(SakkeKey* key,
enum wc_HashType hashType, byte* ssv, word16 ssvSz, byte* auth,
word16* authSz);
/*!
\ingroup SAKKE_Operations
*/
int wc_GenerateSakkeSSV(SakkeKey* key, WC_RNG* rng, byte* ssv,
word16* ssvSz);
/*!
\ingroup SAKKE_RSK
*/
int wc_SetSakkeRsk(SakkeKey* key, const ecc_point* rsk, byte* table,
word32 len);
/*!
\ingroup SAKKE_Operations
*/
int wc_DeriveSakkeSSV(SakkeKey* key, enum wc_HashType hashType,
byte* ssv, word16 ssvSz, const byte* auth,
word16 authSz);

Some files were not shown because too many files have changed in this diff Show More