diff --git a/README.md b/README.md index 858421dc..9def6502 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,39 @@ make test sudo make install ``` +### Visual Studio环境编译 + +在Visual Studio命令提示符下执行: + +```bash +mkdir build +cd build +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 +``` + ## 主要功能 ### 密码算法 @@ -68,3 +101,4 @@ GmSSL支持Nginx的适配,并提供了Docker实现,具体参见[Nginx-with-G - [ ] Add GCM cipher suites - [ ] Release official open interfaces - [ ] **Version 3.2.0 release** + diff --git a/tests/hmactest.c b/tests/hmactest.c index 6efb1128..5b7c289f 100644 --- a/tests/hmactest.c +++ b/tests/hmactest.c @@ -84,25 +84,27 @@ struct { int test_hmac(const DIGEST *digest, const char *key_hex, const char *data_hex, const char *hmac_hex) { HMAC_CTX ctx; - uint8_t key = malloc(strlen(key_hex)/2); // FIXME: malloc - uint8_t data = malloc(strlen(data_hex)/2); - uint8_t hmac = malloc(strlen(hmac_hex) / 2); + uint8_t *key = (uint8_t *)malloc(strlen(key_hex)/2); + uint8_t *data = (uint8_t *)malloc(strlen(data_hex)/2); + uint8_t *hmac = (uint8_t *)malloc(strlen(hmac_hex) / 2); + size_t keylen, datalen, hmaclen; uint8_t buf[64]; - size_t len; + size_t buflen; - hex_to_bytes(key_hex, strlen(key_hex), key, &len); - hex_to_bytes(data_hex, strlen(data_hex), data, &len); - hex_to_bytes(hmac_hex, strlen(hmac_hex), hmac, &len); + hex_to_bytes(key_hex, strlen(key_hex), key, &keylen); + hex_to_bytes(data_hex, strlen(data_hex), data, &datalen); + hex_to_bytes(hmac_hex, strlen(hmac_hex), hmac, &hmaclen); - hmac_init(&ctx, digest, key, sizeof(key)); - hmac_update(&ctx, data, sizeof(data)); - hmac_finish(&ctx, buf, &len); + hmac_init(&ctx, digest, key, keylen); + hmac_update(&ctx, data, datalen); + hmac_finish(&ctx, buf, &buflen); - if (len != sizeof(hmac) || memcmp(buf, hmac, sizeof(hmac)) != 0) { + if (buflen != hmaclen || memcmp(buf, hmac, hmaclen) != 0) { printf("failed\n"); return 0; } printf("ok\n"); + if (key) free(key); if (data) free(data); if (hmac) free(hmac);