[tests] Convert line endings from CR LF to LF

pull/1860/head
Daniele Forsi IU5HKX 2025-08-16 22:00:59 +02:00 zatwierdzone przez Nate Bargmann
rodzic 8dc20bb270
commit 014b34e674
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: FB2C5130D55A8819
1 zmienionych plików z 126 dodań i 126 usunięć

Wyświetl plik

@ -1,126 +1,126 @@
/* Borrowed for Hamlib from: /* Borrowed for Hamlib from:
* String Crypt Test (Linux) * String Crypt Test (Linux)
* Copyright (C) 2012, 2015 * Copyright (C) 2012, 2015
* *
* Author: Paul E. Jones <paulej@packetizer.com> * Author: Paul E. Jones <paulej@packetizer.com>
* *
* This software is licensed as "freeware." Permission to distribute * This software is licensed as "freeware." Permission to distribute
* this software in source and binary forms is hereby granted without a * this software in source and binary forms is hereby granted without a
* fee. THIS SOFTWARE IS PROVIDED 'AS IS' AND WITHOUT ANY EXPRESSED OR * fee. THIS SOFTWARE IS PROVIDED 'AS IS' AND WITHOUT ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* THE AUTHOR SHALL NOT BE HELD LIABLE FOR ANY DAMAGES RESULTING FROM * THE AUTHOR SHALL NOT BE HELD LIABLE FOR ANY DAMAGES RESULTING FROM
* THE USE OF THIS SOFTWARE, EITHER DIRECTLY OR INDIRECTLY, INCLUDING, * THE USE OF THIS SOFTWARE, EITHER DIRECTLY OR INDIRECTLY, INCLUDING,
* BUT NOT LIMITED TO, LOSS OF DATA OR DATA BEING RENDERED INACCURATE. * BUT NOT LIMITED TO, LOSS OF DATA OR DATA BEING RENDERED INACCURATE.
* *
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
//#include <Wincrypt.h> //#include <Wincrypt.h>
#else #else
#include <unistd.h> #include <unistd.h>
#endif #endif
#include "AESStringCrypt.h" #include "AESStringCrypt.h"
#include "password.h" #include "password.h"
#include "../src/misc.h" #include "../src/misc.h"
#if defined(_WIN32) #if defined(_WIN32)
// gmtime_r can be defined by mingw // gmtime_r can be defined by mingw
#ifndef gmtime_r #ifndef gmtime_r
static struct tm *gmtime_r(const time_t *t, struct tm *r) static struct tm *gmtime_r(const time_t *t, struct tm *r)
{ {
// gmtime is threadsafe in windows because it uses TLS // gmtime is threadsafe in windows because it uses TLS
const struct tm *theTm = gmtime(t); const struct tm *theTm = gmtime(t);
if (theTm) if (theTm)
{ {
*r = *theTm; *r = *theTm;
return r; return r;
} }
else else
{ {
return 0; return 0;
} }
} }
#endif // gmtime_r #endif // gmtime_r
#endif // _WIN32 #endif // _WIN32
// using tv_usec with a sleep gives a fairly good random number // using tv_usec with a sleep gives a fairly good random number
static int my_rand(int max) static int my_rand(int max)
{ {
time_t t; time_t t;
struct timeval tv; struct timeval tv;
struct tm result; struct tm result;
t = time(NULL); t = time(NULL);
gmtime_r(&t, &result); gmtime_r(&t, &result);
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
hl_usleep(100); hl_usleep(100);
int val = tv.tv_usec % max; int val = tv.tv_usec % max;
return val; return val;
} }
void rig_make_key(char key[33]) void rig_make_key(char key[33])
{ {
const char *all = const char *all =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123467890!@#$%^&*()_=~<>/?"; "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123467890!@#$%^&*()_=~<>/?";
int max = strlen(all); int max = strlen(all);
int i; int i;
for (i = 0; i < 32; ++i) for (i = 0; i < 32; ++i)
{ {
key[i] = all[my_rand(max)]; key[i] = all[my_rand(max)];
} }
key[32] = 0; key[32] = 0;
} }
int main() int main()
{ {
char key1[33]; char key1[33];
char key2[33]; char key2[33];
char plaintext[33]; char plaintext[33];
unsigned char ciphertext[1024]; unsigned char ciphertext[1024];
int ciphertext_length; int ciphertext_length;
int plaintext_length; int plaintext_length;
memset(ciphertext, 0, sizeof(ciphertext)); memset(ciphertext, 0, sizeof(ciphertext));
rig_make_key(key1); rig_make_key(key1);
rig_make_key(key2); rig_make_key(key2);
printf("key1=%s\n", key1); printf("key1=%s\n", key1);
printf("key2=%s\n", key2); printf("key2=%s\n", key2);
ciphertext_length = AESStringCrypt((unsigned char *) key1, ciphertext_length = AESStringCrypt((unsigned char *) key1,
strlen(key1), strlen(key1),
(unsigned char *) key2, (unsigned char *) key2,
strlen(key2), strlen(key2),
(unsigned char *) ciphertext); (unsigned char *) ciphertext);
for (int i = 0; i < ciphertext_length; ++i) { printf("%02x", ciphertext[i]); } for (int i = 0; i < ciphertext_length; ++i) { printf("%02x", ciphertext[i]); }
printf("\n"); printf("\n");
if (ciphertext_length == AESSTRINGCRYPT_ERROR) if (ciphertext_length == AESSTRINGCRYPT_ERROR)
{ {
printf("Error encrypting the string\n"); printf("Error encrypting the string\n");
} }
printf("Ciphertext length: %d\n", ciphertext_length); printf("Ciphertext length: %d\n", ciphertext_length);
memset(plaintext, 0, sizeof(plaintext)); memset(plaintext, 0, sizeof(plaintext));
printf("Decrypting...\n"); printf("Decrypting...\n");
plaintext_length = AESStringDecrypt((unsigned char *) key1, plaintext_length = AESStringDecrypt((unsigned char *) key1,
strlen(key1), strlen(key1),
(unsigned char *) ciphertext, (unsigned char *) ciphertext,
ciphertext_length, ciphertext_length,
(unsigned char *) plaintext); (unsigned char *) plaintext);
if (plaintext_length == AESSTRINGCRYPT_ERROR) if (plaintext_length == AESSTRINGCRYPT_ERROR)
{ {
printf("Error decrypting the string\n"); printf("Error decrypting the string\n");
} }
printf("Decrypted plaintext length: %d, %s\n", plaintext_length, plaintext); printf("Decrypted plaintext length: %d, %s\n", plaintext_length, plaintext);
} }