当前位置: 首页 > news >正文

新网 网站建立聊城集团网站建设报价

新网 网站建立,聊城集团网站建设报价,港口备案怎么在网站做,wordpress 建站教程 .pdf文章目录 openssl3.2 - 官方demo学习 - signature - EVP_ED_Signature_demo.c概述笔记END openssl3.2 - 官方demo学习 - signature - EVP_ED_Signature_demo.c 概述 ED25519 签名/验签算法, 现在是最好的. 产生ED25519私钥/公钥 用私钥对明文签名, 得到签名数据 用公钥对明文…

文章目录

    • openssl3.2 - 官方demo学习 - signature - EVP_ED_Signature_demo.c
    • 概述
    • 笔记
    • END

openssl3.2 - 官方demo学习 - signature - EVP_ED_Signature_demo.c

概述

ED25519 签名/验签算法, 现在是最好的.
产生ED25519私钥/公钥
用私钥对明文签名, 得到签名数据
用公钥对明文和签名数据进行验签

笔记

/*!
\file EVP_ED_Signature_demo.c
\note
openssl3.2 - 官方demo学习 - signature - EVP_ED_Signature_demo.cED25519 签名/验签算法, 现在是最好的.
产生ED25519私钥/公钥
用私钥对明文签名, 得到签名数据
用公钥对明文和签名数据进行验签
*//*-* Copyright 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*//** This demonstration will calculate and verify an ED25519 signature of* a message using  EVP_DigestSign() and EVP_DigestVerify().*/#include <string.h>
#include <stdio.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/core_names.h>#include "my_openSSL_lib.h"/* A test message to be signed (TBS) */
static const unsigned char hamlet[] ="To be, or not to be, that is the question,\n""Whether tis nobler in the minde to suffer\n""The slings and arrowes of outragious fortune,\n""Or to take Armes again in a sea of troubles,\n";static int demo_sign(EVP_PKEY *priv,const unsigned char *tbs, size_t tbs_len,OSSL_LIB_CTX *libctx,unsigned char **sig_out_value,size_t *sig_out_len)
{int ret = 0;size_t sig_len;unsigned char *sig_value = NULL;EVP_MD_CTX *sign_context = NULL;/* Create a signature context */sign_context = EVP_MD_CTX_new();if (sign_context == NULL) {fprintf(stderr, "EVP_MD_CTX_new failed.\n");goto cleanup;}/** Initialize the sign context using an ED25519 private key* Notice that the digest name must NOT be used.* In this demo we don't specify any additional parameters via* OSSL_PARAM, which means it will use default values.* For more information, refer to doc/man7/EVP_SIGNATURE-ED25519.pod* "ED25519 and ED448 Signature Parameters"*/if (!EVP_DigestSignInit_ex(sign_context, NULL, NULL, libctx, NULL, priv, NULL)) {fprintf(stderr, "EVP_DigestSignInit_ex failed.\n");goto cleanup;}/* Calculate the required size for the signature by passing a NULL buffer. */if (!EVP_DigestSign(sign_context, NULL, &sig_len, tbs, tbs_len)) {fprintf(stderr, "EVP_DigestSign using NULL buffer failed.\n");goto cleanup;}sig_value = OPENSSL_malloc(sig_len);if (sig_value == NULL) {fprintf(stderr, "OPENSSL_malloc failed.\n");goto cleanup;}fprintf(stdout, "Generating signature:\n");if (!EVP_DigestSign(sign_context, sig_value, &sig_len, tbs, tbs_len)) {fprintf(stderr, "EVP_DigestSign failed.\n");goto cleanup;}*sig_out_len = sig_len;*sig_out_value = sig_value;BIO_dump_indent_fp(stdout, sig_value, (int)sig_len, 2);fprintf(stdout, "\n");ret = 1;cleanup:if (!ret)OPENSSL_free(sig_value);EVP_MD_CTX_free(sign_context);return ret;
}static int demo_verify(EVP_PKEY *pub,const unsigned char *tbs, size_t tbs_len,const unsigned char *sig_value, size_t sig_len,OSSL_LIB_CTX *libctx)
{int ret = 0;EVP_MD_CTX *verify_context = NULL;/** Make a verify signature context to hold temporary state* during signature verification*/verify_context = EVP_MD_CTX_new();if (verify_context == NULL) {fprintf(stderr, "EVP_MD_CTX_new failed.\n");goto cleanup;}/* Initialize the verify context with a ED25519 public key */if (!EVP_DigestVerifyInit_ex(verify_context, NULL, NULL,libctx, NULL, pub, NULL)) {fprintf(stderr, "EVP_DigestVerifyInit_ex failed.\n");goto cleanup;}/** ED25519 only supports the one shot interface using EVP_DigestVerify()* The streaming EVP_DigestVerifyUpdate() API is not supported.*/if (!EVP_DigestVerify(verify_context, sig_value, sig_len,tbs, tbs_len)) {fprintf(stderr, "EVP_DigestVerify() failed.\n");goto cleanup;}fprintf(stdout, "Signature verified.\n");ret = 1;cleanup:EVP_MD_CTX_free(verify_context);return ret;
}static int create_key(OSSL_LIB_CTX *libctx,EVP_PKEY **privout, EVP_PKEY **pubout)
{int ret = 0;EVP_PKEY *priv = NULL, *pub = NULL;unsigned char pubdata[32];size_t pubdata_len = 0;/** In this demo we just create a keypair, and extract the* public key. We could also use EVP_PKEY_new_raw_private_key_ex()* to create a key from raw data.*/priv = EVP_PKEY_Q_keygen(libctx, NULL, "ED25519");if (priv == NULL) {fprintf(stderr, "EVP_PKEY_Q_keygen() failed\n");goto end;}if (!EVP_PKEY_get_octet_string_param(priv,OSSL_PKEY_PARAM_PUB_KEY,pubdata,sizeof(pubdata),&pubdata_len)) {fprintf(stderr, "EVP_PKEY_get_octet_string_param() failed\n");goto end;}pub = EVP_PKEY_new_raw_public_key_ex(libctx, "ED25519", NULL, pubdata, pubdata_len);if (pub == NULL) {fprintf(stderr, "EVP_PKEY_new_raw_public_key_ex() failed\n");goto end;}ret = 1;
end:if (ret) {*pubout = pub;*privout = priv;} else {EVP_PKEY_free(priv);}return ret;
}int main(void)
{OSSL_LIB_CTX *libctx = NULL;size_t sig_len = 0;unsigned char *sig_value = NULL;int ret = EXIT_FAILURE;EVP_PKEY *priv = NULL, *pub = NULL;libctx = OSSL_LIB_CTX_new();if (libctx == NULL) {fprintf(stderr, "OSSL_LIB_CTX_new() returned NULL\n");goto cleanup;}if (!create_key(libctx, &priv, &pub)) {fprintf(stderr, "Failed to create key.\n");goto cleanup;}if (!demo_sign(priv, hamlet, sizeof(hamlet), libctx,&sig_value, &sig_len)) {fprintf(stderr, "demo_sign failed.\n");goto cleanup;}if (!demo_verify(pub, hamlet, sizeof(hamlet),sig_value, sig_len, libctx)) {fprintf(stderr, "demo_verify failed.\n");goto cleanup;}ret = EXIT_SUCCESS;cleanup:if (ret != EXIT_SUCCESS)ERR_print_errors_fp(stderr);EVP_PKEY_free(pub);EVP_PKEY_free(priv);OSSL_LIB_CTX_free(libctx);OPENSSL_free(sig_value);return ret;
}

END

http://www.yayakq.cn/news/22042/

相关文章:

  • 宜城市城乡建设局网站上线了建站怎么收费
  • 网站 锚点链接怎么做湛江高端网站建设
  • 福建两学一做网站厦门网站开发平台
  • 网站开发的主要工作做网站去除视频广告
  • 做外贸怎样浏览国外网站wordpress 教程主题
  • 网站注阿里云备案 网站备案域名
  • 肇庆网站开发公司建网站服务器是什么东西
  • 温州网站制作公司国家商标注册官网
  • 贵阳公司网页网站建设网站模板免费下载
  • 移动网站用什么建设网络seo哈尔滨
  • 网站管理工作是具体应该怎么做近一周的新闻大事热点
  • 建设网站纳什么税.net企业网站
  • 深圳网站建设价格wordpress注册会员无法收到邮件
  • 网页网站设计阿里巴巴网站开发信在哪
  • 网站建设大致价格2017深圳招聘信息最新招聘2023
  • 万柳网站建设卡二卡三卡四精品
  • 网站添加flash网络规划设计师书籍
  • 为什么做网站要服务器 和域名广告联盟wordpress
  • 有没有什么免费网站本地wordpress数据
  • 大连企业网站排名北京工商注册信息查询
  • 网站建设捌金手指花总十四黑龙江省建设主管部门网站
  • 网站设计详细设计有关西安的网页设计
  • 网站建设和网络推广外包诸暨公司做网站
  • 广西南宁网站公司东莞企业网络建设方案
  • 福州市台江区网站有哪些网页制作的软件
  • 手机html网站开发工具中国建设银行网站江苏分行
  • 中国建设银行巴黎分行网站在线头像制作免费软件
  • 哪个网站做公司业务广告效果好wordpress php开发
  • asp.net企业网站源码wordpress虚拟商品主题
  • 河池网站制作东莞企业网站推广技巧