脚本宝典收集整理的这篇文章主要介绍了OpenEuler树莓派基础实验(无树莓派),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
1.去OpenSSL官网下载最新版本OpenSSL 1.1.1l的源码openssl-1.1.lk.tar.gz,然后把代码上传到openEuler云服务器中。
2.建立两个文件夹,分别放置OpenSSL的源码和安装路径,记住pwd运行的结果3.解压源代码到rocopensslsrc文件夹:
4.查看安装后的版本,确定是最新安装的1.1.1l版
编写一个测试代码test_openssl.c:
#include <stdio.h>
#include <openssl/evp.h>
int main(){
OpenSSL_add_all_algorIThms();
return 0;
}
然后编译运行:
@H_406_38@
BASE64的测试代码testbase64.c :
#include <stdio.h>
#include <string.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
//Base64编码
void tEVP_Encode()
{
EVP_ENCODE_CTX *ctx;
ctx = EVP_ENCODE_CTX_new(); //EVP编码结构体
unsigned char in[1024]; //输入数据缓冲区
int inl; //输入数据长度
char out[2048]={0}; //输出数据缓冲区
int outl; //输出数据长度
FILE *infp; //输入文件句柄
FILE *outfp; //输出文件句柄
infp = fopen("test.dat","rb");//打开待编码的文件
if(infp == NULL)
{
PRintf("Open File "Test.dat" for Read Err.n");
return;
}
outfp = fopen("test.txt","w");//打开编码后保存的文件
if(outfp == NULL)
{
printf("Open File "test.txt" For Write Err.n");
return;
}
EVP_Encodeinit(ctx);//Base64编码初始化
printf("文件"Test.dat" Base64编码后为:n");
//循环读取原文,并调用EVP_EncodeUpdate计算Base64编码
while(1)
{
inl = fread(in,1,1024,infp);
if(inl <= 0)
break;
EVP_EncodeUpdate(ctx,out,&outl,in,inl);//编码
fwrite(out,1,outl,outfp);//输出编码结果到文件
printf("%s",out);
}
EVP_EncodeFinal(ctx,out,&outl);//完成编码,输出最后的数据。
fwrite(out,1,outl,outfp);
printf("%s",out);
fclose(infp);
fclose(outfp);
printf("对文件"Test.dat" Base64编码完成,保存到"test.txt"文件.nnn");
}
//Base64解码
void tEVP_Decode()
{
EVP_ENCODE_CTX *ctx;
ctx = EVP_ENCODE_CTX_new(); //EVP编码结构体
char in[1024]; //输入数据缓冲区
int inl; //输入数据长度
unsigned char out[1024]; //输出数据缓冲区
int outl; //输出数据长度
FILE *infp; //输入文件句柄
FILE *outfp; //输出文件句柄
infp = fopen("test.txt","r");//打开待解码的文件
if(infp == NULL)
{
printf("Open File "Test.txt" for Read Err.n");
return;
}
outfp = fopen("test-1.dat","wb");//打开解码后保存的文件
if(outfp == NULL)
{
printf("Open File "test-1.txt" For Write Err.n");
return;
}
EVP_DecodeInit(ctx);//Base64解码初始化
printf("开始对文件"Test.txt" Base64解码...nn");
//循环读取原文,并调用EVP_DecodeUpdate进行Base64解码
while(1)
{
inl = fread(in,1,1024,infp);
if(inl <= 0)
break;
EVP_DecodeUpdate(ctx,out,&outl,in,inl);//Base64解码
fwrite(out,1,outl,outfp);//输出到文件
}
EVP_DecodeFinal(ctx,out,&outl);//完成解码,输出最后的数据。
fwrite(out,1,outl,outfp);
fclose(infp);
fclose(outfp);
printf("对文件"Test.txt" Base64解码完成,保存为"test-1.dat"nnn");
}
int main()
{
tEVP_Encode();
tEVP_Decode();
return 0;
}
编译运行:
测试中的用到一个test.dat 是个二进制文件.section .data
.align 3
my_data:
.quad 1
.quad 2
.quad 5
.quad 8
.quad 10
.quad 12
my_data_count:
.quad 6
.align 3
print_data:
.string "Big data: %dn"
.section .text
.globl main
main:
stp x29, x30, [sp, -16]!
ldr x0, =my_data
ldr x1, my_data_count
add x4, x0, #40
mov x3, xzr
1:
ldr x2, [x0], #8
cmp x2, x3
csel x3, x2, x3, hi
cmp x0, x4
b.ls 1b
ldr x0, =print_data
mov x1, x3
bl printf
ldp x29, x30, [sp], 16
ret
编译运行:
调试:compare.S文件如下:
.section .text
.globl compare_data
compare_data:
cmp x0, x1
csel x0, x0, x1, hi
ret
main.c文件如下:
#include <stdio.h>
extern int compare_data(int a, int b);
int main()
{
int val;
val = compare_data(5, 6);
printf("big data: %dn", val);
}
编译运行:
compare.c文件如下。
int compare_data(int a, int b)
{
return (a >= b) ? a : b;
}
main.S文件如下。
.section .data
.align 3
print_data:
.string "big data: %dn"
.section .text
.globl main
main:
stp x29, x30, [sp, -16]!
mov x0, #6
mov x1, #5
bl compare_data
mov x1, x0
ldr x0, =print_data
bl printf
ldp x29, x30, [sp], 16
ret
编译运行:
#include <stdio.h>
static int compare_data(int a, int b)
{
int val;
asm volatile (
"cmp %1, %2n"
"csel %0, %1, %2, hin"
: "+r" (val)
: "r" (a), "r" (b)
: "memory");
return val;
}
int main()
{
int val;
val = compare_data(5, 6);
printf("big data: %dn", val);
val = compare_data(6, 4);
printf("big data: %dn", val);
}
编译运行:
以上是脚本宝典为你收集整理的OpenEuler树莓派基础实验(无树莓派)全部内容,希望文章能够帮你解决OpenEuler树莓派基础实验(无树莓派)所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。