Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhih authored Dec 31, 2021
1 parent d35c0dd commit a389333
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# 前文

本项目由`lpilp`大佬以下项目fork而来

[https://github.com/lpilp/phpsm2sm3sm4](https://github.com/lpilp/phpsm2sm3sm4)

### 注意点

* 本项目是为了适配`php5.6`而做的修改,`php:7.2`及以上不建议使用
* 由于官方打包的`windows``php`都是`32`位的,所以在本项目的`位运算`中,会导致溢出`PHP_INT_MAX`内核常量

#### 如何查看php是否32位

1. 输出`PHP_INT_SIZE`,如果返回是 4 就是 32 位的,如果返回是 8 就是 64 位的
2. 输出`PHP_INT_MAX`, 64 位的会返回 `9223372036854775807`

#### 如何避免`32`位的`位预算溢出`问题?有两种办法

1. 改换`64`位的`php`(线上项目估计换不了, `windows`也难以自己编译`64`位的`php`)
2.`位运算`改成使用`gmp`扩展,如以下代码示例

```php
//以下两句代码是一样的效果
$r = gmp_intval(gmp_div(128, gmp_pow(2, 3)));//$r = 16

$r = 128 >> 3;//$r = 16
```

------

# php sm2 sm3 sm4 国密算法整理
* php版本的国密sm2的签名算法,非对称加解密算法(非对称加密刚上线,目前测试无问题,不能保证兼容其他语言,有问题可以提issues),sm3的hash, sm4的对称加解密,要求PHP7,打开gmp支持
* 目前如果服务器配套的使用的是openssl 1.1.1x, 目前到1.1.1.l(L) ,sm3,sm4都可以直接用openssl_xxx系列函数直接实现,不必大量的代码,但不支持sm2的签名,sm2的加解密
Expand Down

0 comments on commit a389333

Please sign in to comment.