Giter Site home page Giter Site logo

Comments (3)

punkvv avatar punkvv commented on June 1, 2024

sm2加密需要支持长数据加密+1

from gmssl.

guanzhi avatar guanzhi commented on June 1, 2024

实际上GmSSL设计时考虑了这个需求,默认就不必须做DER编码。SM2_KEY, SM2_SIGNATURESM2_CIPHERTEXT这几个类型的内部数据已经做了序列化了,可以直接复制到内存里或者复制到文件里,即使在大小端不同的CPU之间传输也不会出现错误。

from gmssl.

lizheng2018CC avatar lizheng2018CC commented on June 1, 2024

实际上GmSSL设计时考虑了这个需求,默认就不必须做DER编码。SM2_KEY, SM2_SIGNATURESM2_CIPHERTEXT这几个类型的内部数据已经做了序列化了,可以直接复制到内存里或者复制到文件里,即使在大小端不同的CPU之间传输也不会出现错误。

可是源码里面并没有直接将SM2_CIPHERTEXT 暴露给用户,用户还是需要阅读和修改源码才能得到非der编码的数组,不妨给函数参数加一个控制der编码的标志位,控制输出数组中的内容是否是der编码过的。并且还是希望1、sm2加密需要支持长数据加密;2、对私钥的加密也可关闭;3、sm4 EBC加密(虽然我已经实现了);

int sm2_encrypt(const SM2_KEY *key, const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen)
{
	SM2_CIPHERTEXT C;

	if (!key || !in || !out || !outlen) {
		error_print();
		return -1;
	}
	if (!inlen) {
		error_print();
		return -1;
	}

	if (sm2_do_encrypt(key, in, inlen, &C) != 1) {
		error_print();
		return -1;
	}
	*outlen = 0;
	if (sm2_ciphertext_to_der(&C, &out, outlen) != 1) {
		error_print();
		return -1;
	}
	return 1;
}

from gmssl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.