问题描述
我刚开始与IAR编译器和ARM微控制器的工作。在第一步中,我想用做一个RSA加密我的 AT91SAM7S 的MCU(我知道这是不是一个很好的第一步;!)。)
I'm just started to work with IAR compiler and ARM microControllers. In the first step I want to do an RSA encryption using my AT91SAM7S MCU (I know that this is not a good first step! ;) ).
总之,谷歌搜索后,我发现网站名为 rsa.h
和 rsa.c
实现RSA算法的嵌入式设备。
Anyway, after Googling I found this site containing two files named rsa.h
and rsa.c
that implement RSA algorithm for Embedded devices.
于是我下载这个文件,并把它们放在我的程序的目录,(在同一目录中的的main.c
是)。
So I download this files and put them in the directory of my program, (In the same directory that main.c
is).
现在,当我试图建立和编译这个项目,我遇到以下错误:
Now, when I trying to build and compile this project, I face the following errors :
大厦的配置:4rsa - 调试
更新构建树...
Building configuration: 4rsa - DebugUpdating build tree...
3 file(s) deleted.
Updating build tree...
main.c
Error[Pe020]: identifier "uint64_t" is undefined C:\4rsa\rsa.h 22
Error while running C/C++ Compiler
rsa.c
Fatal Error[Pe005]: could not open source file "cross_studio_io.h" C:\4rsa\rsa.c 22
Error while running C/C++ Compiler
Total number of errors: 2
Total number of warnings: 0
Total number of errors: 2
Total number of warnings: 0
看来我必须下载并添加一些库到我的计划,但我没有哪些库,我需要和我在哪里可以下载他们的任何想法。
It seems that I must download and add some libraries to my program, but I don't have any idea which libraries I am need and where I can download them.
FYI:
这是内容 rsa.h
:
/**************************************************************************/
/*!
\file rsa.h
\author Kyle Loudon
modified: microBuilder.eu
\date 4 January, 2010
\version 1.0
Basic RSA-encryption using 64-bit math (32-bit keys).
Based on the examples from "Mastering Algorithms with C" by
Kyle Loudon (O'Reilly, 1999).
*/
/**************************************************************************/
#include <stdlib.h>
#ifndef _RSA_H_
#define _RSA_H_
/* In a secure implementation, huge_t should be at least 400 decimal digits, *
* instead of the 20 provided by a 64-bit value. This means that key values *
* can be no longer than 10 digits in length in the current implementation. */
typedef uint64_t huge_t;
/* Structure for RSA public keys. */
typedef struct rsaPubKey_s
{
huge_t e;
huge_t n;
}
rsaPubKey_t;
/* Define a structure for RSA private keys. */
typedef struct rsaPriKey_s
{
huge_t d;
huge_t n;
}
rsaPriKey_t;
void rsaTest();
void rsaEncrypt(huge_t plaintext, huge_t *ciphertext, rsaPubKey_t pubkey);
void rsaDecrypt(huge_t ciphertext, huge_t *plaintext, rsaPriKey_t prikey);
#endif
这是内容 rsa.c
:
/**************************************************************************/
/*!
\file rsa.c
\author Kyle Loudon
modified: microBuilder.eu
\date 4 January, 2010
\version 1.0
Basic RSA-encryption using 64-bit math (32-bit keys).
Based on the examples from "Mastering Algorithms with C" by
Kyle Loudon (O'Reilly, 1999).
Note: The rsaTest function uses debug_printf in Rowley Associate's
Crossworks for ARM. If you wish to use an alternative means to
display the test results, cross_studio_io.h can be removed from the
include list, and debug_printf can be renamed to a different
output method.
*/
/**************************************************************************/
#include <cross_studio_io.h>
#include "rsa.h"
static huge_t modexp(huge_t a, huge_t b, huge_t n)
{
huge_t y;
y = 1;
/* Compute pow(a, b) % n using the binary square and multiply method. */
while (b != 0)
{
/* For each 1 in b, accumulate y. */
if (b & 1)
{
y = (y * a) % n;
}
/* Square a for each bit in b. */
a = (a * a) % n;
/* Prepare for the next bit in b. */
b = b >> 1;
}
return y;
}
void rsaTest()
{
huge_t rsaOrig, rsaDecrypted, rsaEncrypted;
rsaPubKey_t publicKey;
rsaPriKey_t privateKey;
int i;
debug_printf("Encrypting with RSA\n");
// Values based on 64-bit math (huge_t = unsigned long long)
// which will result in more secure encryption, but also
// increases the size of the encrypted text
publicKey.e = 21;
publicKey.n = 16484947;
privateKey.d = 15689981;
privateKey.n = 16484947;
// Alternative values with 32-bit math (huge_t = unsigned long)
// or when smaller encrypted text is desired
// publicKey.e = 17;
// publicKey.n = 209;
// privateKey.d = 53;
// privateKey.n = 209;
debug_printf("d=%lld, e=%lld, n=%lld\n",
privateKey.d, publicKey.e, publicKey.n);
for (i = 0; i < 128; i++)
{
rsaOrig = i;
rsaEncrypt(rsaOrig, &rsaEncrypted, publicKey);
rsaDecrypt(rsaEncrypted, &rsaDecrypted, privateKey);
if (rsaOrig == rsaDecrypted)
{
debug_printf("In=%5lld, Encrypted=%10lld, Out=%5lld (OK)\n",
rsaOrig, rsaEncrypted, rsaDecrypted);
}
else
{
debug_printf("In=%5lld, Encrypted=%10lld, Out=%5lld (ERROR)\n",
rsaOrig, rsaEncrypted, rsaDecrypted);
}
}
}
void rsaEncrypt(huge_t plaintext, huge_t *ciphertext, rsaPubKey_t pubkey)
{
*ciphertext = modexp(plaintext, pubkey.e, pubkey.n);
return;
}
void rsaDecrypt(huge_t ciphertext, huge_t *plaintext, rsaPriKey_t prikey)
{
*plaintext = modexp(ciphertext, prikey.d, prikey.n);
return;
}
这是我的IAR IDE输出:
And this is my IAR IDE output:
我该如何处理这些错误?
How can I handle these errors?
请帮我开始使用此设备。
先谢谢了。
Please help me to getting started with this device.Thanks in advance.
推荐答案
rsa.h
编写不当。它需要包括 stdint.h
。这是不相关的IAR,ARM或其他任何东西。
rsa.h
is incorrectly written. It needs to include stdint.h
. This is not related to IAR, ARM or anything else.
这篇关于错误IAR编译器&QUOT;#包括&QUOT; preprocessor指挥&QUOT;的typedef&QUOT;命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!