国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

openssl3.2 - 官方demo學(xué)習(xí) - kdf - pbkdf2.c

這篇具有很好參考價值的文章主要介紹了openssl3.2 - 官方demo學(xué)習(xí) - kdf - pbkdf2.c。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

openssl3.2 - 官方demo學(xué)習(xí) - kdf - pbkdf2.c

概述

設(shè)置PBKDF2算法的參數(shù), 取key文章來源地址http://www.zghlxwxcb.cn/news/detail-802940.html

筆記

/*!
\file pbkdf2.c
\note 
openssl3.2 - 官方demo學(xué)習(xí) - kdf - pbkdf2.c
設(shè)置PBKDF2算法的參數(shù), 取key
*/

/*
 * Copyright 2021-2023 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the Apache License 2.0 (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#include <stdio.h>
#include <openssl/core_names.h>
#include <openssl/crypto.h>
#include <openssl/kdf.h>
#include <openssl/obj_mac.h>
#include <openssl/params.h>

#include "my_openSSL_lib.h"

/*
 * test vector from
 * https://datatracker.ietf.org/doc/html/rfc7914
 */

/*
 * Hard coding a password into an application is very bad.
 * It is done here solely for educational purposes.
 */
static unsigned char password[] = {
    'P', 'a', 's', 's', 'w', 'o', 'r', 'd'
};

/*
 * The salt is better not being hard coded too.  Each password should have a
 * different salt if possible.  The salt is not considered secret information
 * and is safe to store with an encrypted password.
 */
static unsigned char pbkdf2_salt[] = {
    'N', 'a', 'C', 'l'
};

/*
 * The iteration parameter can be variable or hard coded.  The disadvantage with
 * hard coding them is that they cannot easily be adjusted for future
 * technological improvements appear.
 */
static unsigned int pbkdf2_iterations = 80000;

static const unsigned char expected_output[] = {

    0x4d, 0xdc, 0xd8, 0xf6, 0x0b, 0x98, 0xbe, 0x21,
    0x83, 0x0c, 0xee, 0x5e, 0xf2, 0x27, 0x01, 0xf9,
    0x64, 0x1a, 0x44, 0x18, 0xd0, 0x4c, 0x04, 0x14,
    0xae, 0xff, 0x08, 0x87, 0x6b, 0x34, 0xab, 0x56,
    0xa1, 0xd4, 0x25, 0xa1, 0x22, 0x58, 0x33, 0x54,
    0x9a, 0xdb, 0x84, 0x1b, 0x51, 0xc9, 0xb3, 0x17,
    0x6a, 0x27, 0x2b, 0xde, 0xbb, 0xa1, 0xd0, 0x78,
    0x47, 0x8f, 0x62, 0xb3, 0x97, 0xf3, 0x3c, 0x8d
};

int main(int argc, char **argv)
{
    int ret = EXIT_FAILURE;
    EVP_KDF *kdf = NULL;
    EVP_KDF_CTX *kctx = NULL;
    unsigned char out[64];
    OSSL_PARAM params[5], *p = params;
    OSSL_LIB_CTX *library_context = NULL;

    library_context = OSSL_LIB_CTX_new();
    if (library_context == NULL) {
        fprintf(stderr, "OSSL_LIB_CTX_new() returned NULL\n");
        goto end;
    }

    /* Fetch the key derivation function implementation */
    kdf = EVP_KDF_fetch(library_context, "PBKDF2", NULL);
    if (kdf == NULL) {
        fprintf(stderr, "EVP_KDF_fetch() returned NULL\n");
        goto end;
    }

    /* Create a context for the key derivation operation */
    kctx = EVP_KDF_CTX_new(kdf);
    if (kctx == NULL) {
        fprintf(stderr, "EVP_KDF_CTX_new() returned NULL\n");
        goto end;
    }

    /* Set password */
    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_PASSWORD, password,
                                             sizeof(password));
    /* Set salt */
    *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, pbkdf2_salt,
                                             sizeof(pbkdf2_salt));
    /* Set iteration count (default 2048) */
    *p++ = OSSL_PARAM_construct_uint(OSSL_KDF_PARAM_ITER, &pbkdf2_iterations);
    /* Set the underlying hash function used to derive the key */
    *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
                                            "SHA256", 0);
    *p = OSSL_PARAM_construct_end();

    /* Derive the key */
    if (EVP_KDF_derive(kctx, out, sizeof(out), params) != 1) {
        fprintf(stderr, "EVP_KDF_derive() failed\n");
        goto end;
    }

    if (CRYPTO_memcmp(expected_output, out, sizeof(expected_output)) != 0) {
        fprintf(stderr, "Generated key does not match expected value\n");
        goto end;
    }

    ret = EXIT_SUCCESS;
end:
    EVP_KDF_CTX_free(kctx);
    EVP_KDF_free(kdf);
    OSSL_LIB_CTX_free(library_context);
    return ret;
}

END

到了這里,關(guān)于openssl3.2 - 官方demo學(xué)習(xí) - kdf - pbkdf2.c的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • openssl3.2 - 官方demo學(xué)習(xí) - certs

    打開官方demos的certs目錄, 沒看到.c. 茫然了一下. 官方在這個目錄中要展示啥呢? 看了readme, 懂了. 原來官方在這個目錄中, 要展示如何使用openssl.exe的命令行來操作證書(建立證書, 證書入庫, 吊銷證書, 查詢證書). 官方通過3個.sh來展示證書操作. mkcerts.sh - 一組操作, 用來建立證書

    2024年02月01日
    瀏覽(50)
  • openssl3.2 - 官方demo學(xué)習(xí) - test - certs

    openssl3.2 - 官方demo學(xué)習(xí) - test - certs

    官方demos目錄有證書操作的例子 已經(jīng)做了筆記 openssl3.2 - 官方demo學(xué)習(xí) - certs 但是這個demos/certs目錄的腳本, 并沒有演示如何操作PKCS12證書. 在官方給的程序例子中, 有操作PKCS12證書的工程, 但是卻沒有配套的PKCS12證書. 這咋弄? 翻了一下openssl源碼工程, 發(fā)現(xiàn)測試目錄中有2個腳本

    2024年01月18日
    瀏覽(145)
  • openssl3.2 - 官方demo學(xué)習(xí) - sconnect.c

    TLS客戶端 - 使用根證書, 非阻塞, 向服務(wù)器要東西. 開始一個新demo學(xué)習(xí)時, 要從頭配置包含路徑, 麻煩. 直接拷貝上一個實現(xiàn)工程, 換掉實現(xiàn).c方便一些. 換的新demo實現(xiàn), 要加入庫包含和頭包含, 麻煩, 做一個公用頭文件, 直接include方便一些.

    2024年02月01日
    瀏覽(21)
  • openssl3.2 - 官方demo學(xué)習(xí) - saccept.c

    建立TLSServer(使用了證書, 和證書中的私鑰), 接收客戶端的連接, 并將客戶端發(fā)來的信息打印到屏幕 筆記

    2024年01月20日
    瀏覽(48)
  • openssl3.2 - 官方demo學(xué)習(xí) - cipher - aesgcm.c

    openssl3.2 - 官方demo學(xué)習(xí) - cipher - aesgcm.c

    AES-256-GCM 在這個實驗中驗證了EVP_CIPHER_fetch()中算法名稱字符串的來源定位. 在工程中配置環(huán)境變量PATH, 且合并環(huán)境. 這樣就不用將openSSL的DLL和配置文件拷貝到工程里面了. 提交代碼時, 就能節(jié)省很多空間. 配置工程調(diào)試時, 也順暢多了.

    2024年01月22日
    瀏覽(46)
  • openssl3.2 - 官方demo學(xué)習(xí) - smime - smenc.c

    讀取X509證書, 用PKCS7加密明文(證書 + 明文 + 3DES_CBC), 保存為MIME格式的密文 openssl API的命名含義 BIO_new_file “new” a “file”, return a “BIO” object PEM_read_bio_X509() Read a certificate in PEM format from a BIO data format is “PEM”, “read” from “bio”, return a object type is “X509”

    2024年01月20日
    瀏覽(25)
  • openssl3.2 - 官方demo學(xué)習(xí) - mac - gmac.c

    使用GMAC算法, 設(shè)置參數(shù)(指定加密算法 e.g. AES-128-GCM, 設(shè)置iv) 用key執(zhí)行初始化, 然后對明文生成MAC數(shù)據(jù) 官方注釋給出建議, key, iv最好不要硬編碼出現(xiàn)在程序中

    2024年01月16日
    瀏覽(43)
  • openssl3.2 - 官方demo學(xué)習(xí) - smime - smver.c

    對于簽名文件(不管是單獨簽名, 還是聯(lián)合簽名), 都要用頂層證書進行驗簽(靠近根CA的證書) 讀證書文件, 得到x509*, 添加到證書容器 讀取簽名密文, 得到pkcs7*和密文的bio 進行pkcs7驗簽, 并將驗簽得到的簽名的明文寫到文件.

    2024年01月19日
    瀏覽(40)
  • openssl3.2 - 官方demo學(xué)習(xí) - mac - siphash.c

    MAC算法為 SIPHASH, 設(shè)置參數(shù)(C-rounds, D-rounds, 也可以不設(shè)置, 有默認(rèn)值) 用key初始化MAC算法, 算明文的MAC值

    2024年01月19日
    瀏覽(54)
  • openssl3.2 - 官方demo學(xué)習(xí) - smime - smdec.c

    從pem證書中得到x509*和私鑰, 用私鑰和證書解密MIME格式的PKCS7密文, 并保存解密后的明文 MIME的數(shù)據(jù)操作, 都是PKCS7相關(guān)的

    2024年01月18日
    瀏覽(53)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包