2015-08-17 4 views
0

Je viens de commencer à travailler avec le compilateur IAR et les microcontrôleurs ARM. Dans la première étape, je veux faire un cryptage RSA en utilisant mon MCU AT91SAM7S (je sais que ce n'est pas une bonne première étape!;)). Quoi qu'il en soit, après Googling j'ai trouvé this site contenant deux fichiers nommés rsa.h et rsa.c qui implémentent l'algorithme RSA pour les périphériques embarqués.Erreur dans le compilateur IAR pour la commande du préprocesseur "#include" et la commande "typedef"

Donc je télécharge ces fichiers et les mets dans le répertoire de mon programme, (Dans le même répertoire que main.c est). Maintenant

, quand j'essaie de construire et compiler ce projet, je fais face à des erreurs suivantes:

configuration du bâtiment: 4rsa - Mise à jour de débogage arbre de construction ...

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 

Il semble que je Je dois télécharger et ajouter des bibliothèques à mon programme, mais je n'ai aucune idée de quelles bibliothèques j'ai besoin et où je peux les télécharger.


Pour votre information:

Ceci est contenu 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 

Ceci est contenu 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; 
} 

Et voici ma sortie IAR IDE:

enter image description here

Comment puis-je gérer ces erreurs?

S'il vous plaît aidez-moi à démarrer avec cet appareil. Merci d'avance.

+0

Pour le premier problème, vous devez inclure '' qui définit les [types entiers à largeur fixe] (http://en.cppreference.com/w/c/types/integer). Cependant, si le compilateur ne supporte pas, par exemple, Types 64 bits, vous n'aurez pas le type 'unt64_t'. –

+0

En ce qui concerne le fichier d'en-tête manquant, peut-être que c'est dans un emplacement non standard? Avez-vous essayé de le chercher? –

Répondre

0

rsa.h est incorrectement écrit. Il doit inclure stdint.h. Ce n'est pas lié à IAR, ARM ou autre chose.