Неопределенная ссылка SHA_Update. OpenSSL в C - PullRequest
0 голосов
/ 11 июля 2020

Я изучаю OpenSSL, чтобы получить ha sh файла в C. Когда я компилирую код, я получаю эту неопределенную ссылочную ошибку в SHA_Update и SHA_Final

Вот код:

#include <openssl/sha.h>
#include <stdio.h>
#include <fcntl.h>

#define BUFF_SIZE 256

int main(int argc, char* argv[]) {
   int fd;
   char buff[BUFF_SIZE];
   int i = 0;

   SHA_CTX sha_ctx;
   unsigned char sha_hash[SHA_DIGEST_LENGTH];

   SHA1_Init(&sha_ctx);

   fd = open(argv[1], O_RDONLY, 0);
   do {
      i = read(fd, buff, i);
      SHA_Update(&sha_ctx, buff, i);
   } while(i > 0);
   close(fd);

   SHA_Final(sha_hash, &sha_ctx);

   printf("\n Hash of the file: %s \n\n", argv[1]);
   for(i = 0; i < SHA_DIGEST_LENGTH; ++i) {
      printf("%x", sha_hash[i]);
   }
   printf("\n\n");
   return 0;
}

Для компиляции я использовал:

gcc -g hash.c -lcrypto

1 Ответ

0 голосов
/ 11 июля 2020

Имена функций: SHA1_Update и SHA1_Final (у вас были SHA_Update и SHA_Final, видите пропущенный 1?)

...