mirror of
https://github.com/guanzhi/GmSSL.git
synced 2024-02-26 23:08:08 +00:00
Compare commits
14
Commits
v3.1.0-pr1
...
v3.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f48e05164f | ||
|
|
f2c5e77255 | ||
|
|
901eefa223 | ||
|
|
ca47fb21c1 | ||
|
|
48962c9db6 | ||
|
|
5c20425b40 | ||
|
|
78175e4385 | ||
|
|
6e122a4d2b | ||
|
|
79c6b7ce5c | ||
|
|
90c022c803 | ||
|
|
289a9677fe | ||
|
|
dac38a677d | ||
|
|
a58f7db86d | ||
|
|
d0c55842ae |
@@ -300,6 +300,7 @@ add_library(gmssl ${src})
|
||||
|
||||
|
||||
if (WIN32)
|
||||
target_link_libraries(gmssl -lws2_32)
|
||||
elseif (APPLE)
|
||||
target_link_libraries(gmssl dl)
|
||||
target_link_libraries(gmssl "-framework Security")
|
||||
|
||||
+31
@@ -221,3 +221,34 @@ cmake .. -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake -DANDR
|
||||
make
|
||||
```
|
||||
|
||||
## 安装包构建
|
||||
|
||||
依赖cmake工具包中的cpack工具,生成可发布的安装包。
|
||||
|
||||
生成的安装包在`build`目录下。
|
||||
|
||||
### 构建DEB安装包
|
||||
|
||||
```
|
||||
mkdir build; cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||
cpack -G DEB
|
||||
```
|
||||
|
||||
### 构建RPM安装包
|
||||
|
||||
```
|
||||
mkdir build; cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||
cpack -G RPM
|
||||
```
|
||||
|
||||
### 构建`.sh`安装脚本
|
||||
|
||||
```
|
||||
mkdir build; cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||
cpack -G DEB
|
||||
make package
|
||||
```
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ GmSSL是由由北京大学自主开发的国产商用密码开源库,实现了
|
||||
|
||||
## 下载
|
||||
|
||||
* GmSSL的主分支版本为 [GmSSL-3.1.0-RR1](https://github.com/guanzhi/GmSSL/archive/refs/heads/master.zip),主要增加跨平台特性,特别是对Windows/Visual Studio的支持,Windows、Android、iOS平台的开发者需要使用该版本。
|
||||
* GmSSL的主分支版本为 [GmSSL-3.1.0](https://github.com/guanzhi/GmSSL/releases/tag/v3.1.0),主要增加跨平台特性,特别是对Windows/Visual Studio的支持,Windows、Android、iOS平台的开发者需要使用该版本。
|
||||
|
||||
## 编译与安装
|
||||
|
||||
@@ -31,6 +31,8 @@ make test
|
||||
sudo make install
|
||||
```
|
||||
|
||||
在`make install`完成后,GmSSL会在默认安装目录中安装`gmssl`命令行工具,在头文件目录中创建`gmssl`目录,并且在库目录中安装`libgmssl.a`、`libgmssl.so`等库文件。
|
||||
|
||||
### Visual Studio环境编译
|
||||
|
||||
在Visual Studio命令提示符下执行:
|
||||
@@ -42,48 +44,6 @@ cmake .. -G "NMake Makefiles"
|
||||
nmake
|
||||
```
|
||||
|
||||
### iOS编译
|
||||
|
||||
下载 https://github.com/leetal/ios-cmake ,将`ios.toolchain.cmake`文件复制到`build`目录。
|
||||
|
||||
```bash
|
||||
mkdir build; cd build
|
||||
cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../ios.toolchain.cmake -DPLATFORM=OS64
|
||||
cmake --build . --config Release
|
||||
```
|
||||
|
||||
如果出现“error: Signing for "gmssl" requires a development team.”错误,可以用Xcode打开工程文件,在Signing配置中设置Development Team。
|
||||
|
||||
### Android编译
|
||||
|
||||
下载Android NDK,执行
|
||||
|
||||
```bash
|
||||
mkdir build; cd build
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-23
|
||||
make
|
||||
```
|
||||
|
||||
### Linux软件包构建
|
||||
|
||||
依赖于cmake工具包中的cpack工具,目前仅支持构建:
|
||||
* .deb
|
||||
* .rpm
|
||||
* .sh安装脚本
|
||||
|
||||
```bash
|
||||
mkdir build; cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||
# 构建deb软件包
|
||||
cpack -G DEB
|
||||
# 构建rpm软件包
|
||||
cpack -G RPM
|
||||
# 构建.sh安装脚本
|
||||
make package
|
||||
```
|
||||
|
||||
构建的软件包在`build`目录下。
|
||||
|
||||
## 主要功能
|
||||
|
||||
### 密码算法
|
||||
@@ -120,7 +80,7 @@ GmSSL支持Nginx的适配,并提供了Docker实现,具体参见[Nginx-with-G
|
||||
- [X] Add Windows Cygwin support
|
||||
- [X] Add iOS support
|
||||
- [X] Add Android support
|
||||
- [ ] **Version 3.1.0 release**
|
||||
- [x] **Version 3.1.0 release**
|
||||
- [ ] Add GCC specific optimization
|
||||
- [ ] Add X86_64 assembly implementation
|
||||
- [ ] Add GPU implementation
|
||||
|
||||
@@ -1,416 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
|
||||
#include "url_parser.h"
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char *_strnstr(const char *s, size_t s_len, const char *needle)
|
||||
{
|
||||
const char *end = s + s_len;
|
||||
size_t needle_len = strlen(needle);
|
||||
const char *p;
|
||||
|
||||
p = s;
|
||||
while (p < end - needle_len + 1) {
|
||||
if (strncmp(p, needle, needle_len) == 0) {
|
||||
return p;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *find_chars(const char *s, size_t s_len, const char *chars)
|
||||
{
|
||||
const char *end = s + s_len;
|
||||
size_t chars_n = strlen(chars);
|
||||
const char *p;
|
||||
int i;
|
||||
|
||||
p = s;
|
||||
while (p < end) {
|
||||
for (i = 0 ; i < chars_n ; i++) {
|
||||
if (*p == chars[i]) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *find_chars_reverse(const char *s, size_t s_len, const char *chars)
|
||||
{
|
||||
const char *end = s + s_len;
|
||||
size_t chars_n = strlen(chars);
|
||||
const char *p;
|
||||
int i;
|
||||
|
||||
p = end - 1;
|
||||
while (p >= s) {
|
||||
for (i = 0 ; i < chars_n ; i++) {
|
||||
if (*p == chars[i]) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
p--;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int is_alpha(char c)
|
||||
{
|
||||
if ((c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z')) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int is_digit(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9') {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int is_control(char c)
|
||||
{
|
||||
if ((c >= 0x00 && c <= 0x1f) ||
|
||||
c == 0x7f) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *lookup_scheme(const char *s)
|
||||
{
|
||||
const char *p = s;
|
||||
char c;
|
||||
|
||||
if (strlen(s) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!is_alpha(*p)) {
|
||||
return NULL;
|
||||
}
|
||||
p++;
|
||||
|
||||
while (*p != '\0') {
|
||||
c = *p;
|
||||
if (c == ':') {
|
||||
return p;
|
||||
}
|
||||
if (!is_alpha(c) &&
|
||||
!is_digit(c) &&
|
||||
c != '+' &&
|
||||
c != '-' &&
|
||||
c != '.') {
|
||||
return NULL;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int parse_user_password(const char *s, size_t s_len, URL_COMPONENTS *c)
|
||||
{
|
||||
const char *end = s + s_len;
|
||||
const char *found;
|
||||
|
||||
found = _strnstr(s, s_len, ":");
|
||||
if (found) {
|
||||
c->user = strndup(s, found - s);
|
||||
if (c->user == NULL) {
|
||||
return -1; /* ENOMEM */
|
||||
}
|
||||
c->password = strndup(found + 1, end - found - 1);
|
||||
if (c->password == NULL) {
|
||||
return -1; /* ENOMEM */
|
||||
}
|
||||
} else {
|
||||
c->user = strndup(s, s_len);
|
||||
if (c->user == NULL) {
|
||||
return -1; /* ENOMEM */
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_authority(const char *s, size_t s_len, URL_COMPONENTS *c)
|
||||
{
|
||||
const char *end = s + s_len;
|
||||
const char *p, *found, *host_start, *host_end;
|
||||
int port;
|
||||
|
||||
c->port = -1;
|
||||
|
||||
if (s_len == 0) { /* empty authority */
|
||||
return 0;
|
||||
}
|
||||
|
||||
found = _strnstr(s, s_len, "@");
|
||||
if (found) {
|
||||
if (parse_user_password(s, found - s, c) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
host_start = found + 1;
|
||||
} else {
|
||||
host_start = s;
|
||||
}
|
||||
|
||||
if (*host_start == '[') {
|
||||
/* IP-literal host */
|
||||
if (find_chars(host_start + 1, end - host_start - 1, "[")) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
host_end = find_chars(host_start + 1, end - host_start - 1, "]");
|
||||
if (!host_end) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
/* The next character of ']' is termination or ':'. */
|
||||
if (host_end + 1 != end && host_end[1] != ':') {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
host_end++;
|
||||
} else {
|
||||
/* IPv4address / reg-name host */
|
||||
host_end = find_chars_reverse(host_start, end - host_start, ":");
|
||||
if (host_end == NULL) {
|
||||
host_end = end;
|
||||
}
|
||||
if (find_chars(host_start, host_end - host_start, "[]")) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (find_chars(host_start, host_end - host_start, " ")) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ASSERT: host_end == end or *host_end == ':' */
|
||||
|
||||
if (host_end == end) {
|
||||
/* without port number */
|
||||
if (host_start == end) { /* empty host */
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
c->host = strndup(host_start, end - host_start);
|
||||
if (c->host == NULL) {
|
||||
return -1; /* ENOMEM */
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ASSERT: *host_end == ':' */
|
||||
|
||||
/* host and port */
|
||||
|
||||
if (host_start == host_end) { /* empty host */
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (host_end + 1 < end) {
|
||||
p = host_end + 1;
|
||||
port = 0;
|
||||
while (p < end) {
|
||||
if (*p < '0' || *p > '9') {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
port = port * 10 + *p - '0';
|
||||
if (port > 65535) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
p++;
|
||||
}
|
||||
} else {
|
||||
/* empty port number */
|
||||
port = -1;
|
||||
}
|
||||
|
||||
c->host = strndup(host_start, (size_t) (host_end - host_start));
|
||||
if (c->host == NULL) {
|
||||
return -1; /* ENOMEM */
|
||||
}
|
||||
c->port = port;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
URL_COMPONENTS *parse_url(const char *url)
|
||||
{
|
||||
URL_COMPONENTS *c;
|
||||
const char *p;
|
||||
const char *end = url + strlen(url);
|
||||
const char *found;
|
||||
size_t len;
|
||||
|
||||
for (p = url ; p < end ; p++) {
|
||||
if (is_control(*p)) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
c = malloc(sizeof(URL_COMPONENTS));
|
||||
if (!c) {
|
||||
return NULL;
|
||||
}
|
||||
memset(c, 0, sizeof(URL_COMPONENTS));
|
||||
c->port = -1;
|
||||
|
||||
p = url;
|
||||
|
||||
/* lookup scheme */
|
||||
found = lookup_scheme(p);
|
||||
if (found) {
|
||||
c->scheme = strndup(url, (size_t) (found - p));
|
||||
if (c->scheme == NULL) {
|
||||
goto error;
|
||||
}
|
||||
p = found + 1; /* skip a colon */
|
||||
if (p >= end) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(p) >= 2 &&
|
||||
p[0] == '/' && p[1] == '/') {
|
||||
/* authority */
|
||||
p = p + 2;
|
||||
found = find_chars(p, strlen(p), "/?#");
|
||||
if (found == NULL) {
|
||||
len = strlen(p);
|
||||
} else {
|
||||
len = (size_t) (found - p);
|
||||
}
|
||||
if (parse_authority(p, len, c) == -1) {
|
||||
goto error; /* ENOMEM,EINVAL */
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
return c;
|
||||
}
|
||||
|
||||
p = found;
|
||||
}
|
||||
|
||||
if (*p != '?' && *p != '#') {
|
||||
/* path */
|
||||
found = find_chars(p, strlen(p), "?#");
|
||||
found = NULL;
|
||||
if (found == NULL) {
|
||||
c->path = strdup(p);
|
||||
if (c->path == NULL) {
|
||||
goto error;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (found != p) {
|
||||
c->path = strndup(p, (size_t) (found - p));
|
||||
if (c->path == NULL) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
return c;
|
||||
}
|
||||
|
||||
p = found;
|
||||
}
|
||||
|
||||
/* ASSERT: *p is '?' or '#' */
|
||||
#if 0
|
||||
if (*p == '?') {
|
||||
/* query */
|
||||
p = p + 1;
|
||||
found = find_chars(p, strlen(p), "#");
|
||||
if (found == NULL) {
|
||||
c->query = strdup(p);
|
||||
} else {
|
||||
c->query = strndup(p, (size_t) (found - p));
|
||||
}
|
||||
|
||||
if (c->query == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
return c;
|
||||
}
|
||||
|
||||
p = found;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ASSERT: *p is '#' */
|
||||
|
||||
/* fragment */
|
||||
p = p + 1;
|
||||
c->fragment = strdup(p);
|
||||
if (c->fragment == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
return c;
|
||||
|
||||
error:
|
||||
free(c);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void free_url_components(URL_COMPONENTS *c)
|
||||
{
|
||||
if (c->scheme) {
|
||||
free(c->scheme);
|
||||
}
|
||||
if (c->user) {
|
||||
free(c->user);
|
||||
}
|
||||
if (c->password) {
|
||||
free(c->password);
|
||||
}
|
||||
if (c->host) {
|
||||
free(c->host);
|
||||
}
|
||||
if (c->path) {
|
||||
free(c->path);
|
||||
}
|
||||
if (c->query) {
|
||||
free(c->query);
|
||||
}
|
||||
if (c->fragment) {
|
||||
free(c->fragment);
|
||||
}
|
||||
free(c);
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
|
||||
#ifndef URL_PARSER_H
|
||||
#define URL_PARSER_H
|
||||
|
||||
#define URL_PARSER_VERSION 0x00000300 /* 0.0.3 */
|
||||
|
||||
typedef struct url_components {
|
||||
char *scheme;
|
||||
char *user;
|
||||
char *password;
|
||||
char *host;
|
||||
int port;
|
||||
char *path;
|
||||
char *query;
|
||||
char *fragment;
|
||||
} URL_COMPONENTS;
|
||||
|
||||
extern URL_COMPONENTS *parse_url(const char *url);
|
||||
extern void free_url_components(URL_COMPONENTS *c);
|
||||
|
||||
#endif
|
||||
@@ -85,7 +85,9 @@ typedef struct {
|
||||
|
||||
#define SM4_GCM_KEY_SIZE 16
|
||||
#define SM4_GCM_MIN_IV_SIZE 1
|
||||
#define SM4_GCM_DEFAULT_IV_SIZE 12
|
||||
#define SM4_GCM_MAX_IV_SIZE 64
|
||||
#define SM4_GCM_DEFAULT_TAG_SIZE 16
|
||||
|
||||
_gmssl_export int sm4_gcm_encrypt_init(SM4_GCM_CTX *ctx,
|
||||
const uint8_t *key, size_t keylen, const uint8_t *iv, size_t ivlen,
|
||||
|
||||
+4
-1
@@ -164,13 +164,16 @@ typedef struct {
|
||||
uint8_t y[32];
|
||||
} SM2_POINT;
|
||||
|
||||
#define sm2_point_init(P) memset((P),0,sizeof(SM2_POINT))
|
||||
#define sm2_point_set_infinity(P) sm2_point_init(P)
|
||||
int sm2_point_from_octets(SM2_POINT *P, const uint8_t *in, size_t inlen);
|
||||
void sm2_point_to_compressed_octets(const SM2_POINT *P, uint8_t out[33]);
|
||||
void sm2_point_to_uncompressed_octets(const SM2_POINT *P, uint8_t out[65]);
|
||||
int sm2_point_from_octets(SM2_POINT *P, const uint8_t *in, size_t inlen);
|
||||
|
||||
int sm2_point_from_x(SM2_POINT *P, const uint8_t x[32], int y);
|
||||
int sm2_point_from_xy(SM2_POINT *P, const uint8_t x[32], const uint8_t y[32]);
|
||||
int sm2_point_is_on_curve(const SM2_POINT *P);
|
||||
int sm2_point_is_at_infinity(const SM2_POINT *P);
|
||||
int sm2_point_add(SM2_POINT *R, const SM2_POINT *P, const SM2_POINT *Q);
|
||||
int sm2_point_sub(SM2_POINT *R, const SM2_POINT *P, const SM2_POINT *Q);
|
||||
int sm2_point_neg(SM2_POINT *R, const SM2_POINT *P);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
|
||||
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
@@ -26,7 +26,7 @@ Version Public API
|
||||
*/
|
||||
|
||||
#define GMSSL_VERSION_NUM 30100
|
||||
#define GMSSL_VERSION_STR "GmSSL 3.1.0 PR1"
|
||||
#define GMSSL_VERSION_STR "GmSSL 3.1.0"
|
||||
|
||||
_gmssl_export int gmssl_version_num(void);
|
||||
_gmssl_export const char *gmssl_version_str(void);
|
||||
|
||||
@@ -334,7 +334,7 @@ typedef enum {
|
||||
X509_cert_crl_sign,
|
||||
} X509_CERT_TYPE;
|
||||
|
||||
int x509_cert_check(const uint8_t *cert, size_t certlen, int cert_type, int *path_len_constraints);
|
||||
int x509_cert_check(const uint8_t *cert, size_t certlen, int cert_type, int *path_len_constraint);
|
||||
|
||||
/*
|
||||
IssuerAndSerialNumber ::= SEQUENCE {
|
||||
|
||||
@@ -82,6 +82,8 @@ void zuc_mac_init(ZUC_MAC_CTX *ctx, const uint8_t key[ZUC_KEY_SIZE], const uint8
|
||||
void zuc_mac_update(ZUC_MAC_CTX *ctx, const uint8_t *data, size_t len);
|
||||
void zuc_mac_finish(ZUC_MAC_CTX *ctx, const uint8_t *data, size_t nbits, uint8_t mac[ZUC_MAC_SIZE]);
|
||||
|
||||
#define ZUC_EEA_ENCRYPT_NWORDS(nbits) ((nbits + 31)/32)
|
||||
#define ZUC_EEA_ENCRYPT_NBYTES(nbits) (ZUC_EEA_ENCRYPT_NWORDS(nbits)*4)
|
||||
void zuc_eea_encrypt(const ZUC_UINT32 *in, ZUC_UINT32 *out, size_t nbits,
|
||||
const uint8_t key[ZUC_KEY_SIZE], ZUC_UINT32 count, ZUC_UINT5 bearer,
|
||||
ZUC_BIT direction);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <gmssl/sm2.h>
|
||||
#include <gmssl/mem.h>
|
||||
#include <gmssl/asn1.h>
|
||||
#include <gmssl/rand.h>
|
||||
#include <gmssl/error.h>
|
||||
@@ -1088,6 +1089,11 @@ int sm2_point_is_on_curve(const SM2_POINT *P)
|
||||
return sm2_jacobian_point_is_on_curve(&T);
|
||||
}
|
||||
|
||||
int sm2_point_is_at_infinity(const SM2_POINT *P)
|
||||
{
|
||||
return mem_is_zero((uint8_t *)P, sizeof(SM2_POINT));
|
||||
}
|
||||
|
||||
int sm2_point_from_x(SM2_POINT *P, const uint8_t x[32], int y)
|
||||
{
|
||||
SM2_BN _x, _y, _g, _z;
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ void zuc_eea_encrypt(const ZUC_UINT32 *in, ZUC_UINT32 *out, size_t nbits,
|
||||
}
|
||||
|
||||
if (nbits % 32 != 0) {
|
||||
out[nwords - 1] |= (0xffffffff << (32 - (nbits%32)));
|
||||
out[nwords - 1] &= (0xffffffff << (32 - (nbits%32)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+29
-29
@@ -12,6 +12,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmssl/zuc.h>
|
||||
#include <gmssl/error.h>
|
||||
|
||||
|
||||
static void bswap_buf(uint32_t *buf, size_t nwords)
|
||||
@@ -26,9 +27,6 @@ static void bswap_buf(uint32_t *buf, size_t nwords)
|
||||
|
||||
int zuc_test(void)
|
||||
{
|
||||
int err = 0;
|
||||
int i;
|
||||
|
||||
unsigned char key[][16] = {
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
|
||||
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
|
||||
@@ -44,6 +42,7 @@ int zuc_test(void)
|
||||
{0x0657cfa0, 0x7096398b},
|
||||
{0x14f1c272, 0x3279c419},
|
||||
};
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
ZUC_STATE zuc = {{0}};
|
||||
@@ -52,19 +51,19 @@ int zuc_test(void)
|
||||
zuc_generate_keystream(&zuc, 2, buf);
|
||||
if (buf[0] != ciphertext[i][0] || buf[1] != ciphertext[i][1]) {
|
||||
fprintf(stderr, "error generating ZUC key stream on test vector %d\n", i);
|
||||
err++;
|
||||
error_print();
|
||||
return -1;
|
||||
} else {
|
||||
fprintf(stderr, "zuc test %d ok\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* test vector from GM/T 0001.2-2012 */
|
||||
static int zuc_eea_test(void)
|
||||
{
|
||||
int err = 0;
|
||||
unsigned char key[][16] = {
|
||||
{0x17, 0x3d, 0x14, 0xba, 0x50, 0x03, 0x73, 0x1d,
|
||||
0x7a, 0x60, 0x04, 0x94, 0x70, 0xf0, 0x0a, 0x29},
|
||||
@@ -178,21 +177,21 @@ static int zuc_eea_test(void)
|
||||
|
||||
for (i = 0; i < sizeof(key)/sizeof(key[i]); i++) {
|
||||
zuc_eea_encrypt(ibs[i], buf, bits[i], key[i], count[i], bearer[i], direction[i]);
|
||||
if (memcmp(buf, obs[i], (bits[i] + 31)/32) != 0) {
|
||||
if (memcmp(buf, obs[i], ZUC_EEA_ENCRYPT_NBYTES(bits[i])) != 0) {
|
||||
printf("zuc eea test %zu failed\n", i);
|
||||
err++;
|
||||
error_print();
|
||||
return -1;
|
||||
} else {
|
||||
printf("zuc eea test %zu ok\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* test vector from GM/T 0001.3-2012 */
|
||||
static int zuc_eia_test(void)
|
||||
{
|
||||
int err = 0;
|
||||
unsigned char key[][16] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
@@ -274,21 +273,19 @@ static int zuc_eia_test(void)
|
||||
count[i], bearer[i], direction[i]);
|
||||
if (T != mac[i]) {
|
||||
printf("zuc eia test %zu failed\n", i);
|
||||
err++;
|
||||
error_print();
|
||||
return -1;
|
||||
} else {
|
||||
printf("zuc eia test %zu ok\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* from ZUC256 draft */
|
||||
int zuc256_test(void)
|
||||
{
|
||||
int err = 0;
|
||||
int i;
|
||||
|
||||
unsigned char key[][32] = {
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
@@ -317,6 +314,7 @@ int zuc256_test(void)
|
||||
0x7a5be02e,0xc32ba585,0x505af316,0xc2f9ded2,0x7cdbd935,
|
||||
0xe441ce11,0x15fd0a80,0xbb7aef67,0x68989416,0xb8fac8c2}
|
||||
};
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(key)/sizeof(key[0]); i++) {
|
||||
ZUC_STATE zuc_key;
|
||||
@@ -327,18 +325,18 @@ int zuc256_test(void)
|
||||
|
||||
if (memcmp(buf, ciphertext[i], 20) != 0) {
|
||||
printf("zuc256 test %d failed\n", i);
|
||||
err++;
|
||||
error_print();
|
||||
return -1;
|
||||
} else {
|
||||
printf("zuc256 test %d ok\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int zuc256_mac_test(void)
|
||||
{
|
||||
int err = 0;
|
||||
unsigned char key[][32] = {
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
@@ -438,7 +436,8 @@ int zuc256_mac_test(void)
|
||||
zuc256_mac_finish(&ctx, NULL, 0, mac);
|
||||
if (memcmp(mac, tag32[i], 4) != 0) {
|
||||
printf("zuc256 mac test %d 32-bit failed\n", i);
|
||||
err++;
|
||||
error_print();
|
||||
return -1;
|
||||
} else {
|
||||
printf("zuc256 mac test %d 32-bit ok\n", i);
|
||||
}
|
||||
@@ -450,7 +449,8 @@ int zuc256_mac_test(void)
|
||||
zuc256_mac_finish(&ctx, NULL, 0, mac);
|
||||
if (memcmp(mac, tag64[i], 8) != 0) {
|
||||
printf("zuc256 mac test %d 64-bit failed\n", i);
|
||||
err++;
|
||||
error_print();
|
||||
return -1;
|
||||
} else {
|
||||
printf("zuc256 mac test %d 64-bit ok\n", i);
|
||||
}
|
||||
@@ -462,22 +462,22 @@ int zuc256_mac_test(void)
|
||||
zuc256_mac_finish(&ctx, NULL, 0, mac);
|
||||
if (memcmp(mac, tag128[i], 16) != 0) {
|
||||
printf("zuc256 mac test %d 128-bit failed\n", i);
|
||||
err++;
|
||||
error_print();
|
||||
return -1;
|
||||
} else {
|
||||
printf("zuc256 mac test %d 128-bit ok\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int err = 0;
|
||||
err += zuc_test();
|
||||
err += zuc_eea_test();
|
||||
err += zuc_eia_test();
|
||||
err += zuc256_test();
|
||||
err += zuc256_mac_test();
|
||||
return err;
|
||||
if (zuc_test() != 1) { error_print(); return -1; }
|
||||
if (zuc_eea_test() != 1) { error_print(); return -1; }
|
||||
if (zuc_eia_test() != 1) { error_print(); return -1; }
|
||||
if (zuc256_test() != 1) { error_print(); return -1; }
|
||||
if (zuc256_mac_test() != 1) { error_print(); return -1; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -122,7 +122,7 @@ bad:
|
||||
fprintf(stderr, "%s: invalid CRL data or format\n", prog);
|
||||
goto end;
|
||||
}
|
||||
if ((rv = x509_crl_verify_by_ca_cert(crl, crl_len, cacert, cacertlen, SM2_DEFAULT_ID, strlen(SM2_DEFAULT_ID))) < 0) {
|
||||
if ((rv = x509_crl_verify_by_ca_cert(crl, crl_len, cacert, cacertlen, signer_id, signer_id_len)) < 0) {
|
||||
fprintf(stderr, "%s: verification inner error\n", prog);
|
||||
goto end;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user