update go-api

GetDigestNames() and GetCipherNames get supported algorithms with
callbacks.
This commit is contained in:
Zhi Guan
2018-08-04 20:27:43 +08:00
parent 9d6ad55623
commit abedd1b0f4
8 changed files with 160 additions and 244 deletions

View File

@@ -2,7 +2,41 @@
package gmssl
/*
#include <string.h>
#include <openssl/evp.h>
#include <openssl/crypto.h>
static void cb_cipher_names_len(const EVP_CIPHER *cipher, const char *from,
const char *to, void *x) {
if (cipher) {
*((int *)x) += strlen(EVP_CIPHER_name(cipher)) + 1;
}
}
static void cb_cipher_names(const EVP_CIPHER *cipher, const char *from,
const char *to, void *x) {
if (cipher) {
if (strlen((char *)x) > 0) {
strcat((char *)x, ":");
}
strcat((char *)x, EVP_CIPHER_name(cipher));
}
}
static char *get_cipher_names(void) {
char *ret = NULL;
int len = 0;
EVP_CIPHER_do_all_sorted(cb_cipher_names_len, &len);
if (!(ret = OPENSSL_zalloc(len))) {
return NULL;
}
EVP_CIPHER_do_all_sorted(cb_cipher_names, ret);
return ret;
}
static void _OPENSSL_free(void *addr) {
OPENSSL_free(addr);
}
*/
import "C"
@@ -10,159 +44,13 @@ import (
"errors"
"unsafe"
"runtime"
"strings"
)
/* generated by `gmssl list -cipher-algorithms | sort -f | uniq -i` */
func GetCipherNames() []string {
return []string{
"AES-128-CBC",
"AES-128-CBC-HMAC-SHA1",
"AES-128-CBC-HMAC-SHA256",
"AES-128-CFB",
"AES-128-CFB1",
"AES-128-CFB8",
"AES-128-CTR",
"AES-128-ECB",
"AES-128-OCB",
"AES-128-OFB",
"AES-128-XTS",
"AES-192-CBC",
"AES-192-CFB",
"AES-192-CFB1",
"AES-192-CFB8",
"AES-192-CTR",
"AES-192-ECB",
"AES-192-OCB",
"AES-192-OFB",
"AES-256-CBC",
"AES-256-CBC-HMAC-SHA1",
"AES-256-CBC-HMAC-SHA256",
"AES-256-CFB",
"AES-256-CFB1",
"AES-256-CFB8",
"AES-256-CTR",
"AES-256-ECB",
"AES-256-OCB",
"AES-256-OFB",
"AES-256-XTS",
"AES128",
"aes128-wrap",
"AES192",
"aes192-wrap",
"AES256",
"aes256-wrap",
"BF",
"BF-CBC",
"BF-CFB",
"BF-ECB",
"BF-OFB",
"blowfish",
"CAMELLIA-128-CBC",
"CAMELLIA-128-CFB",
"CAMELLIA-128-CFB1",
"CAMELLIA-128-CFB8",
"CAMELLIA-128-CTR",
"CAMELLIA-128-ECB",
"CAMELLIA-128-OFB",
"CAMELLIA-192-CBC",
"CAMELLIA-192-CFB",
"CAMELLIA-192-CFB1",
"CAMELLIA-192-CFB8",
"CAMELLIA-192-CTR",
"CAMELLIA-192-ECB",
"CAMELLIA-192-OFB",
"CAMELLIA-256-CBC",
"CAMELLIA-256-CFB",
"CAMELLIA-256-CFB1",
"CAMELLIA-256-CFB8",
"CAMELLIA-256-CTR",
"CAMELLIA-256-ECB",
"CAMELLIA-256-OFB",
"CAMELLIA128",
"CAMELLIA192",
"CAMELLIA256",
"CAST",
"CAST-cbc",
"CAST5-CBC",
"CAST5-CFB",
"CAST5-ECB",
"CAST5-OFB",
"ChaCha20",
"ChaCha20-Poly1305",
"DES",
"DES-CBC",
"DES-CFB",
"DES-CFB1",
"DES-CFB8",
"DES-ECB",
"DES-EDE",
"DES-EDE-CBC",
"DES-EDE-CFB",
"DES-EDE-ECB",
"DES-EDE-OFB",
"DES-EDE3",
"DES-EDE3-CBC",
"DES-EDE3-CFB",
"DES-EDE3-CFB1",
"DES-EDE3-CFB8",
"DES-EDE3-ECB",
"DES-EDE3-OFB",
"DES-OFB",
"DES3",
"des3-wrap",
"DESX",
"DESX-CBC",
"id-aes128-CCM",
"id-aes128-GCM",
"id-aes128-wrap",
"id-aes128-wrap-pad",
"id-aes192-CCM",
"id-aes192-GCM",
"id-aes192-wrap",
"id-aes192-wrap-pad",
"id-aes256-CCM",
"id-aes256-GCM",
"id-aes256-wrap",
"id-aes256-wrap-pad",
"id-smime-alg-CMS3DESwrap",
"IDEA",
"IDEA-CBC",
"IDEA-CFB",
"IDEA-ECB",
"IDEA-OFB",
"RC2",
"rc2-128",
"rc2-40",
"RC2-40-CBC",
"rc2-64",
"RC2-64-CBC",
"RC2-CBC",
"RC2-CFB",
"RC2-ECB",
"RC2-OFB",
"RC4",
"RC4-40",
"RC4-HMAC-MD5",
"SEED",
"SEED-CBC",
"SEED-CFB",
"SEED-ECB",
"SEED-OFB",
"SMS4",
"SMS4-CBC",
"SMS4-CCM",
"SMS4-CFB",
"SMS4-CFB1",
"SMS4-CFB8",
"SMS4-CTR",
"SMS4-ECB",
"SMS4-GCM",
"SMS4-OCB",
"SMS4-OFB",
"SMS4-WRAP",
"SMS4-WRAP-PAD",
"SMS4-XTS",
}
cnames := C.get_cipher_names()
defer C._OPENSSL_free(unsafe.Pointer(cnames))
return strings.Split(C.GoString(cnames), ":")
}
func GetCipherKeyLength(name string) (int, error) {