如何在不进行散列的情况下使用DSA? Openssl + C.

时间:2014-04-12 21:28:30

标签: c openssl

我想知道我是否可以在没有哈希的情况下使用DSA ...我在下面写了这段代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/dsa.h>

int main(int argc, char **argv)
{
    int bits = 1024;
    unsigned char *buff = (unsigned char*)malloc(sizeof(unsigned char) * 102409209);
    unsigned int digestLength = 0, signSize = 0;
    digestLength = strlen(buff);

    DSA *dsaKey = NULL;

    if((dsaKey = DSA_generate_parameters(bits, NULL, 0, NULL, NULL, NULL, NULL)) == NULL)
    {
        exit(-1);
    }

    if(DSA_generate_key(dsaKey) != 1)
    {
        exit(-1);
    }

    unsigned char* sign = (unsigned char*)calloc(DSA_size(dsaKey), sizeof(unsigned char));

    int ret = DSA_sign(0, buff, digestLength, sign, &signSize, dsaKey);
    if(ret != 1)
    {
        printf("DSA sign error!\n");
    }

    int is_valid = DSA_verify(0, buff, digestLength, sign, signSize, dsaKey);
    if(is_valid != 1)
    {
        printf("DSA verify error!\n");
    }

    if(dsaKey != NULL)
        DSA_free(dsaKey);
    free(buff);
    free(sign);

    return 0;
}

但我甚至不知道如何检查它是否正确。使用哈希它很简单 - 首先我计算哈希值,然后签名/验证它。但没有哈希?

0 个答案:

没有答案