Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7f2739

Browse files
committed
First update
1 parent 6461c3b commit a7f2739

File tree

7 files changed

+1718
-52
lines changed

7 files changed

+1718
-52
lines changed

.gitignore

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,35 @@
1-
# Prerequisites
2-
*.d
3-
4-
# Object files
5-
*.o
6-
*.ko
7-
*.obj
8-
*.elf
9-
10-
# Linker output
11-
*.ilk
12-
*.map
13-
*.exp
14-
15-
# Precompiled Headers
16-
*.gch
17-
*.pch
18-
19-
# Libraries
20-
*.lib
21-
*.a
22-
*.la
231
*.lo
24-
25-
# Shared objects (inc. Windows DLLs)
26-
*.dll
27-
*.so
28-
*.so.*
29-
*.dylib
30-
31-
# Executables
32-
*.exe
33-
*.out
34-
*.app
35-
*.i*86
36-
*.x86_64
37-
*.hex
38-
39-
# Debug files
40-
*.dSYM/
41-
*.su
42-
*.idb
43-
*.pdb
44-
45-
# Kernel Module Compile Results
46-
*.mod*
47-
*.cmd
48-
.tmp_versions/
49-
modules.order
50-
Module.symvers
51-
Mkfile.old
52-
dkms.conf
2+
*.la
3+
.libs
4+
acinclude.m4
5+
aclocal.m4
6+
autom4te.cache
7+
build
8+
config.guess
9+
config.h
10+
config.h.in
11+
config.log
12+
config.nice
13+
config.status
14+
config.sub
15+
configure
16+
configure.ac
17+
configure.in
18+
include
19+
install-sh
20+
libtool
21+
ltmain.sh
22+
Makefile
23+
Makefile.fragments
24+
Makefile.global
25+
Makefile.objects
26+
missing
27+
mkinstalldirs
28+
modules
29+
run-tests.php
30+
tests/*/*.diff
31+
tests/*/*.out
32+
tests/*/*.php
33+
tests/*/*.exp
34+
tests/*/*.log
35+
tests/*/*.sh

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
11
# GmSSL-PHP
2-
PHP binding to the GmSSL library.
2+
3+
The GmSSL extension is the binding to the GmSSL C library. GmSSL provides functions of Chinese SM2, SM3, SM4, SM9, ZUC crypto algorithms.
4+
5+
6+
GmSSL Functions
7+
8+
* `gmssl_version_num` - Get version number of the GmSSL C library
9+
* `gmssl_version_str` - Get version string of the GmSSL C library
10+
* `gmssl_rand_bytes` - Generate cryptographic secure random bytes
11+
* `gmssl_sm3` - Calculate the SM3 digest of a message
12+
* `gmssl_sm3_hmac` - Calculate the HMAC-SM3 MAC tag of a message
13+
* `gmssl_sm3_pbkdf2` - Extract key material from a password by using KBKDF2-HMAC-SM3
14+
* `gmssl_sm4_cbc_encrypt` - Encrypt message using SM4-CBC mode (with padding)
15+
* `gmssl_sm4_cbc_decrypt` - Decrypt SM4-CBC (with padding) ciphertext
16+
* `gmssl_sm4_ctr_encrypt` - Encrypt/decrypt message with SM4-CTR mode
17+
* `gmssl_sm4_gcm_encrypt` - Encrypt message using SM4-GCM mode
18+
* `gmssl_sm4_gcm_decrypt` - Decrypt SM4-GCM ciphertext
19+
* `gmssl_zuc_encrypt` - Encrypt/decrypt message using ZUC stream cipher
20+
* `gmssl_sm2_key_generate` - Generate SM2 Keypair
21+
* `gmssl_sm2_private_key_info_encrypt_to_pem` - Export SM2 private key to password encrypted PEM file
22+
* `gmssl_sm2_private_key_info_decrypt_from_pem` - Import SM2 private key from password encrypted PEM file
23+
* `gmssl_sm2_public_key_info_to_pem` - Export SM2 public key to PEM file
24+
* `gmssl_sm2_public_key_info_from_pem` - Import SM2 public key from PEM file
25+
* `gmssl_sm2_sign` - Sign message (not digest) and generate SM2 signature
26+
* `gmssl_sm2_verify` - Verify SM2 signature
27+
* `gmssl_sm2_encrypt` - Encrypt short secret message with SM2 public key
28+
* `gmssl_sm2_decrypt` - Decrypt SM2 ciphertext with SM2 private key
29+
* `gmssl_sm9_sign_master_key_generate` - Generate SM9 signing master key
30+
* `gmssl_sm9_sign_master_key_extract_key` - Extract the signing private key from SM9 master key with signer's ID
31+
* `gmssl_sm9_sign_master_key_info_encrypt_to_pem` - Export SM9 signing master key to encrypted PEM file
32+
* `gmssl_sm9_sign_master_key_info_decrypt_from_pem` - Import SM9 signing master key from encrypted PEM file
33+
* `gmssl_sm9_sign_master_public_key_to_pem` - Export SM9 signing master public key to file
34+
* `gmssl_sm9_sign_master_public_key_from_pem` - Import SM9 signing master public key from file
35+
* `gmssl_sm9_sign_key_info_encrypt_to_pem` - Export user's SM9 signing key to encrypted PEM file
36+
* `gmssl_sm9_sign_key_info_decrypt_from_pem` - Import user's SM9 signing key from encrypted PEM file
37+
* `gmssl_sm9_sign` - Sign message with user's SM9 signing key
38+
* `gmssl_sm9_verify` - Verify SM9 signature of message with signer's ID
39+
* `gmssl_sm9_enc_master_key_generate` - Generate SM9 encryption master key
40+
* `gmssl_sm9_enc_master_key_extract_key` - Extract the encryption private key from SM9 master key with user's ID
41+
* `gmssl_sm9_enc_master_key_info_encrypt_to_pem` - Export SM9 encryption master key to encrypted PEM file
42+
* `gmssl_sm9_enc_master_key_info_decrypt_from_pem` - Import SM9 encryption master key from encrypted PEM file
43+
* `gmssl_sm9_enc_master_public_key_to_pem` - Export SM9 encryption master public key to file
44+
* `gmssl_sm9_enc_master_public_key_from_pem` - Import SM9 encryption master public key from file
45+
* `gmssl_sm9_enc_key_info_encrypt_to_pem` - Export user's SM9 encryption key to encrypted PEM file
46+
* `gmssl_sm9_enc_key_info_decrypt_from_pem` - Import user's SM9 encryption key from encrypted PEM file
47+
* `gmssl_sm9_encrypt` - Encrypt short message with recipient's ID
48+
* `gmssl_sm9_decrypt` - Decrypt SM9 ciphertext with user's SM9 private key
49+
50+
51+

config.m4

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
dnl config.m4 for extension gmssl
2+
3+
dnl Comments in this file start with the string 'dnl'.
4+
dnl Remove where necessary.
5+
6+
dnl If your extension references something external, use 'with':
7+
8+
dnl PHP_ARG_WITH([gmssl],
9+
dnl [for gmssl support],
10+
dnl [AS_HELP_STRING([--with-gmssl],
11+
dnl [Include gmssl support])])
12+
13+
dnl Otherwise use 'enable':
14+
15+
PHP_ARG_ENABLE([gmssl],
16+
[whether to enable gmssl support],
17+
[AS_HELP_STRING([--enable-gmssl],
18+
[Enable gmssl support])],
19+
[no])
20+
21+
if test "$PHP_GMSSL" != "no"; then
22+
dnl Write more examples of tests here...
23+
24+
dnl Remove this code block if the library does not support pkg-config.
25+
dnl PKG_CHECK_MODULES([LIBFOO], [foo])
26+
dnl PHP_EVAL_INCLINE($LIBFOO_CFLAGS)
27+
dnl PHP_EVAL_LIBLINE($LIBFOO_LIBS, GMSSL_SHARED_LIBADD)
28+
29+
dnl If you need to check for a particular library version using PKG_CHECK_MODULES,
30+
dnl you can use comparison operators. For example:
31+
dnl PKG_CHECK_MODULES([LIBFOO], [foo >= 1.2.3])
32+
dnl PKG_CHECK_MODULES([LIBFOO], [foo < 3.4])
33+
dnl PKG_CHECK_MODULES([LIBFOO], [foo = 1.2.3])
34+
35+
dnl Remove this code block if the library supports pkg-config.
36+
dnl --with-gmssl -> check with-path
37+
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
38+
dnl SEARCH_FOR="/include/gmssl.h" # you most likely want to change this
39+
dnl if test -r $PHP_GMSSL/$SEARCH_FOR; then # path given as parameter
40+
dnl GMSSL_DIR=$PHP_GMSSL
41+
dnl else # search default path list
42+
dnl AC_MSG_CHECKING([for gmssl files in default path])
43+
dnl for i in $SEARCH_PATH ; do
44+
dnl if test -r $i/$SEARCH_FOR; then
45+
dnl GMSSL_DIR=$i
46+
dnl AC_MSG_RESULT(found in $i)
47+
dnl fi
48+
dnl done
49+
dnl fi
50+
dnl
51+
dnl if test -z "$GMSSL_DIR"; then
52+
dnl AC_MSG_RESULT([not found])
53+
dnl AC_MSG_ERROR([Please reinstall the gmssl distribution])
54+
dnl fi
55+
56+
dnl Remove this code block if the library supports pkg-config.
57+
dnl --with-gmssl -> add include path
58+
dnl PHP_ADD_INCLUDE($GMSSL_DIR/include)
59+
60+
dnl Remove this code block if the library supports pkg-config.
61+
dnl --with-gmssl -> check for lib and symbol presence
62+
dnl LIBNAME=GMSSL # you may want to change this
63+
dnl LIBSYMBOL=GMSSL # you most likely want to change this
64+
65+
dnl If you need to check for a particular library function (e.g. a conditional
66+
dnl or version-dependent feature) and you are using pkg-config:
67+
dnl PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL,
68+
dnl [
69+
dnl AC_DEFINE(HAVE_GMSSL_FEATURE, 1, [ ])
70+
dnl ],[
71+
dnl AC_MSG_ERROR([FEATURE not supported by your gmssl library.])
72+
dnl ], [
73+
dnl $LIBFOO_LIBS
74+
dnl ])
75+
76+
dnl If you need to check for a particular library function (e.g. a conditional
77+
dnl or version-dependent feature) and you are not using pkg-config:
78+
PHP_CHECK_LIBRARY(gmssl, gmssl_version_str,
79+
[
80+
PHP_ADD_LIBRARY_WITH_PATH(gmssl, , GMSSL_SHARED_LIBADD)
81+
AC_DEFINE(HAVE_GMSSL_FEATURE, 1, [ ])
82+
],[
83+
AC_MSG_ERROR([FEATURE not supported by your gmssl library.])
84+
],[
85+
-L$GMSSL_DIR/$PHP_LIBDIR -lm
86+
])
87+
88+
PHP_SUBST(GMSSL_SHARED_LIBADD)
89+
90+
dnl In case of no dependencies
91+
AC_DEFINE(HAVE_GMSSL, 1, [ Have gmssl support ])
92+
93+
PHP_NEW_EXTENSION(gmssl, gmssl.c, $ext_shared)
94+
fi

config.w32

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG_ENABLE('gmssl', 'gmssl support', 'no');
2+
3+
if (PHP_GMSSL != 'no') {
4+
AC_DEFINE('HAVE_GMSSL', 1, 'gmssl support enabled');
5+
6+
EXTENSION('gmssl', 'gmssl.c', null, '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
7+
}

0 commit comments

Comments
 (0)