GMSSL is compiled under windows using vs2010

Posted by kaisellgren on Wed, 29 May 2019 10:21:53 +0200

Introduction to GMSSL

Project Home Page: http://gmssl.org/
github: https://github.com/guanzhi/GmSSL

GMSSL windows + vs2010 compilation

Compile and install: http://gmssl.org/docs/install.html
Windows is compiled as follows:

Compilation error

1. base58.c error C2057: Constant expression should be entered
The following errors were made:
Cryptobase58base58.c(81): error C2057: Constant expression should be entered
Cryptobase58base58.c(81): error C2466: cannot allocate arrays of constant size 0
Cryptobase58base58.c(81): error C2133:'outi': unknown size

The error code is:

int base58_decode(const char *b58, size_t b58sz, void *bin, size_t *binszp)
{
    size_t binsz = *binszp;
    const unsigned char *b58u = (void*)b58;
    unsigned char *binu = bin;
    size_t outisz = (binsz + 3) / 4;
    uint32_t outi[outisz];
    uint64_t t;
    uint32_t c;
    size_t i, j;

Solution:
vs does not support using variables to define array sizes, so it is sufficient to change outi to malloc assignments.

int base58_decode(const char *b58, size_t b58sz, void *bin, size_t *binszp)
{
    size_t binsz = *binszp;
    const unsigned char *b58u = (void*)b58;
    unsigned char *binu = bin;
    size_t outisz = (binsz + 3) / 4;
    uint32_t *outi = (uint32_t *)malloc(outisz);//Change to malloc
    uint64_t t;
    uint32_t c;
    size_t i, j;

2. base58.c: error C2065:'ssize_t': undeclared identifier
The following errors were made:
Cryptobase58base58.c(173): error C2065:'ssize_t': undeclared identifier
Cryptobase58base58.c(173): error C2146: syntax error: missing ";" (before identifier "i")
The error code is:

int base58_encode(const void *data, size_t binsz, char *b58, size_t *b58sz)
{
    const uint8_t *bin = data;
    int carry;
    ssize_t i, j, high, zcount = 0;

Solution:
ssize_t is defined in BaseTsd.h, the file is in the Windows SDK directory, and the header file is introduced in base58.c.

#if defined(_MSC_VER)
#include <BaseTsd.h>
#endif

3.base58.c error C2275:'uint8_t': Illegal use of this type as an expression
The following errors were made:
Cryptobase58base58.c(185): error C2275:'uint8_t': Illegal use of this type as an expression

The error code is:

int base58_encode(const void *data, size_t binsz, char *b58, size_t *b58sz)
{
    const uint8_t *bin = data;
    int carry;
    ssize_t i, j, high, zcount = 0;
    size_t size;

    while (zcount < binsz && !bin[zcount])
        ++zcount;

    size = (binsz - zcount) * 138 / 100 + 1;
    uint8_t buf[size];
    memset(buf, 0, size);

Solution:
vs does not support using variables to define array sizes, so buf is changed to malloc assignment
Since the declaration of variables is placed at the beginning of a function in c, the buf declaration is placed at the beginning of a function

int base58_encode(const void *data, size_t binsz, char *b58, size_t *b58sz)
{
    const uint8_t *bin = data;
    unsigned char *buf = NULL;
    int carry;
    ssize_t i, j, high, zcount = 0;
    size_t size;

    while (zcount < binsz && !bin[zcount])
        ++zcount;

    size = (binsz - zcount) * 138 / 100 + 1;
    buf = (unsigned char *)malloc(size);//Change to malloc

4.ffx.c fatal error C1083: Cannot open include file:'inttypes.h': No such file or directory
Solution:
Reference resources This article

Place the downloaded inttypes.h in the same directory as ffx.c and change the reference to quotation marks

#include <stdio.h>
#include <ctype.h>
#include <string.h>
//#include <inttypes.h>
#include "inttypes.h"

5.saf_ec.c(94): error C2275:'EVP_PKEY_CTX': Illegal use of this type as an expression
Anything that encounters an error where this type is illegal as an expression is because the life of the variable is not placed at the beginning of the function
Solution:
Just place the declaration at the beginning of the function

6.error LNK2001: unresolved external symbol speck_expand16
The following errors were made:
Libcrypto-1_1.def: error LNK2001: unresolved external symbol speck_expand16
Libcrypto-1_1.def: error LNK2001: unresolved external symbol speck_expand32
Libcrypto-1_1.def: error LNK2001: unresolved external symbol speck_expand64
Libcrypto.lib: fatal error LNK1120: 3 unresolved external commands

Solution:
Delete the declarations of speck_expand16,speck_expand32,speck_expand64 in includeopensslspeck.h
Execute perl util/mkdef.pl crypto update to regenerate libcrypto.num

Topics: Windows github SDK