Ai
30 Star 131 Fork 0

Gitee 极速下载/OpenSSL

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/openssl/openssl
克隆/下载
lms_key.c 2.96 KB
一键复制 编辑 原始数据 按行查看 历史
Bob Beck 提交于 2025-12-09 15:08 +08:00 . 4.0-POST-CLANG-FORMAT-WEBKIT
/*
* Copyright 2025 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 <openssl/core_dispatch.h>
#include "crypto/lms.h"
#include <string.h>
/**
* @brief Create a new LMS_KEY object
*
* @param libctx A OSSL_LIB_CTX object used for fetching algorithms.
* @returns The new LMS_KEY object on success, or NULL on malloc failure
*/
LMS_KEY *ossl_lms_key_new(OSSL_LIB_CTX *libctx)
{
LMS_KEY *ret = OPENSSL_zalloc(sizeof(LMS_KEY));
if (ret != NULL)
ret->libctx = libctx;
return ret;
}
/**
* @brief Destroy a LMS_KEY object
*/
void ossl_lms_key_free(LMS_KEY *lmskey)
{
LMS_PUB_KEY *pub;
if (lmskey == NULL)
return;
pub = &lmskey->pub;
OPENSSL_free(pub->encoded);
OPENSSL_free(lmskey);
}
/**
* @brief Are 2 LMS public keys equal?
*
* To be equal the keys must have the same LMS_PARAMS, LM_OTS_PARAMS and
* encoded public keys.
*
* @param key1 A LMS_KEY object
* @param key2 A LMS_KEY object
* @param selection Only OSSL_KEYMGMT_SELECT_PUBLIC_KEY is supported
* @returns 1 if the keys are equal otherwise it returns 0.
*/
int ossl_lms_key_equal(const LMS_KEY *key1, const LMS_KEY *key2, int selection)
{
int ok = 1;
if (key1->lms_params != key2->lms_params
|| key1->ots_params != key2->ots_params)
return 0;
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) {
if (key1->pub.encodedlen != key2->pub.encodedlen)
return 0;
ok = (key1->pub.encodedlen == 0)
|| (memcmp(key1->pub.encoded, key2->pub.encoded,
key1->pub.encodedlen)
== 0);
}
return ok;
}
/**
* @brief Is a LMS_KEY valid.
*
* @param key A LMS_KEY object
* @param selection Currently only supports |OSSL_KEYMGMT_SELECT_PUBLIC_KEY|
* @returns 1 if a LMS_KEY contains valid key data.
*/
int ossl_lms_key_valid(const LMS_KEY *key, int selection)
{
if (key == NULL)
return 0;
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
return key->pub.encoded != NULL && key->pub.encodedlen != 0;
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
return 0; /* a private key that doesn't exist can't be valid */
return 1;
}
/**
* @brief Does a LMS_KEY object contain a public key.
*
* @param key A LMS_KEY object
* @param selection Currently only supports |OSSL_KEYMGMT_SELECT_PUBLIC_KEY|
* @returns 1 if a LMS_KEY contains public key data, or 0 otherwise.
*/
int ossl_lms_key_has(const LMS_KEY *key, int selection)
{
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
return (key != NULL) && (key->pub.K != NULL);
/* There is no private key currently */
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
return 0;
return 1;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/mirrors/openssl.git
git@gitee.com:mirrors/openssl.git
mirrors
openssl
OpenSSL
master

搜索帮助