c++ - How to resolve this: invalid conversion from 'const char*' to 'const uint8_t* -


i installed sha library: https://github.com/cathedrow/cryptosuite. want implement hmac256 using arduino ide 1.6.7 installed on win. 10 , controller atmega328.

i copied example given in webpage. still new , want test , try. wrote code in arduino ide.

#include "sha256.h"  void setup() {     // put setup code here, run once:     uint8_t *hash;     //static const char hash[450]={};     //const char *hash; hash={};     sha256.inithmac("hash key",8); // key, , length of key in bytes     sha256.print("this message hash");     hash = sha256.resulthmac();     //serial.print(hash,hex); }  void loop() {     // put main code here, run repeatedly: } 

i got error:

invalid conversion 'const char*' 'const uint8_t* {aka const unsigned char*}' [-fpermissive]

i not know why happens. example primitive taken library site. can help?

edit: tried change line from:

sha256.inithmac((const uint8_t*)"hash key",8); 

to:

sha256.inithmac((const uint8_t*)"hash key",8); 

but again, compilation fails. says:

arduino: 1.6.7 (windows 10), board: "arduino/genuino uno"

in file included c:\program files (x86)\arduino\hardware\arduino\avr\cores\arduino/arduino.h:28:0,

             c:\users\e\documents\arduino\libraries\sha\sha1_config.h:13,               c:\users\e\documents\arduino\libraries\sha\sha1.h:4,               c:\users\e\documents\arduino\libraries\sha\sha1.cpp:1: 

c:\users\e\documents\arduino\libraries\sha\sha1.cpp:8:25: error: variable 'sha1initstate' must const in order put read-only section means of 'attribute((progmem))'

uint8_t sha1initstate[] progmem = {

                     ^ 

exit status 1 error compiling.

this report have more information "show verbose output during compilation" enabled in file > preferences.

the inithmac function signature is:

void inithmac(const uint8_t* secret, int secretlength); 

but use const char* secret.

solution

try cast secret variable const uint8_t* (or const unsigned char*):

sha256.inithmac((const uint8_t*)"hash key",8); 

update

to solve new compilation error, add const in front of declarations containing progmem in library sources. insance:

in sha/sha1.cpp (line 11)

const uint8_t sha1initstate[] progmem = { 

in sha/sha256.cpp (line 6)

const uint32_t sha256k[] progmem = { 

in sha/sha256.cpp (line 11):

const uint8_t sha256initstate[] progmem = { 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -