 |
|
|
 |
|
 |
Thank you for the example exe file! I used it and it works well for my purposes.
|
|
|
|
 |
|
 |
I haven't had a chance to investigate fully yet, but it appears that if you're compiling on a Linux machine and you #include <string>, and then #include "SHA1.h" afterward, you get the following linker error: undefined reference to `CSHA1::Update(unsigned char*, unsigned long)' The workaround for me was to just move the #include "SHA1.h" above the #include <string> and the error went away. Russell
|
|
|
|
 |
|
 |
I had the same issue on Mac OS (10.5).
Remark the following section in SHA1.h, that will help. I don't know the impact on a 64 bit system though.
//#if (ULONG_MAX == 0xFFFFFFFF)
//#define UINT_32 unsigned long
//#else
#define UINT_32 unsigned int
//#endif
Regards,
Bruno
|
|
|
|
 |
|
 |
Using .NET ComputeHash with a UTF8 encoding gets me the same hash that your code produces. When I switch the ComputeHash encoding to UTF16 I get a different hash. Is there a way to alter your code to work with the UTF16 encoding?
Thanks in advance.
jchambers@mcomi.com
|
|
|
|
 |
|
 |
Hash algorithms like SHA-1 work with bytes, not with characters. This allows the algorithms to be used with arbitrary data (like image files, ...) and not only with text messages.
Therefore, there is no way to "make SHA-1 work with UTF-16". SHA-1 just sees a stream of bytes, it doesn't know anything about the type of the data. By using different encodings, you get different byte streams and consequently different hashes, which is actually good because the byte stream *has* changed.
If you want to get the UTF-8 hashes of UTF-16 text, you first need to convert the text from its UTF-16 representation to the UTF-8 format and then hash it. The other way round, if you want to get UTF-16 hashes of UTF-8 text, you first need to convert it to UTF-16 and then hash it. Because of the mass of different encodings and conversion complexity, no helper functions will be added to the hash algorithm class (the hash algorithm doesn't have anything to do with encodings anyway!). You must do the conversion on your own, for example using the libiconv[^] library.
Best regards
Dominik
|
|
|
|
 |
|
 |
I run the program with C++ builder 6,
and check the memory leak with CodeGuard,
when i hash a string,like "123456",
the error msg is:
Error 00019. 0x140100 (Thread 0x0A54):
Pointer underrun: 0x0012F658, that is at offset 8 in local block
0x0012F650(=[ebp-0x1C] @Project1.exe:0x01:007BD1) (size 8).
memcpy(0x0012FEC4, 0x0012F658, 0x0 [0])
Call Tree:
0x00408904(=Project1.exe:0x01:007904) D:\temp\csha1_demo\CSHA1ClassSource\SHA1.cpp#154
0x00408BD1(=Project1.exe:0x01:007BD1) D:\temp\csha1_demo\CSHA1ClassSource\SHA1.cpp#217
0x00401399(=Project1.exe:0x01:000399) D:\temp\csha1_demo\CSHA1Test.cpp#58
0x00401237(=Project1.exe:0x01:000237) D:\temp\csha1_demo\CSHA1Test.cpp#30
0x3267DB86(=CC3260MT.DLL:0x01:07CB86)
------------------------------------------
code is here:memcpy(&m_buffer[j], &data[i], len - i);
missile
|
|
|
|
 |
|
 |
It's not an overrun bug, but a underrun warning.
This problem only occurs in C++ Builder and is non-critical. It has been fixed already for the next version (I just didn't have the time yet to release it).
Thanks anyway and best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
 |
|
 |
Using the SHA1CryptoServiceProvider ComputeHash() method gives a totally different hash value than produced by your sample code.
What gives?
|
|
|
|
 |
|
 |
I've verified the results of my CSHA1 class against the official test vectors - with success.
So most probably you're using CSHA1 or SHA1CryptoServiceProvider incorrectly. Can you post the code you used for testing?
Best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
 |
|
 |
I managed to work out what I was doing wrong. I coded the C++ code correctly, but used the wrong encoding (ASCIIEncoding) in the VB .NET test program. Using UTF8Encoding soon sorted the problem.
Thanks for replying anyway.
|
|
|
|
 |
|
 |
Hi Dominik,
I also have false result when I compare with net:
string (10xa):
aaaaaaaaaa
your code gives:
BF81DA007527DFB85D331E7532FD604B7291CE8F
Here are on line results:
http://hash.online-convert.com/sha1-generator[^]
3495ff69d34671d1e15b33a63c1379fdedd3a32a
and:
http://www.fileformat.info/tool/hash.htm?text=aaaaaaaaaa[^]
3495ff69d34671d1e15b33a63c1379fdedd3a32a
So, both sites gives me the same result:
3495ff69d34671d1e15b33a63c1379fdedd3a32a
and your code gives:
BF81DA007527DFB85D331E7532FD604B7291CE8F
Could you tell me where I am wrong.
Thank you
Vlada
|
|
|
|
 |
|
 |
My CSHA1 class also gives 3495ff69d34671d1e15b33a63c1379fdedd3a32a, not BF81DA007527DFB85D331E7532FD604B7291CE8F. Just try the demo application (CSHA1Test.exe) and you'll see.
Best regards
Dominik
|
|
|
|
 |
|
 |
THIS IS TRUE!
hm,
that means that my compiler is doing something wierd.
I will check and come back to you.
Thank you very much for prompt response
Vlada
|
|
|
|
 |
|
 |
Dear Dominik,
you are absolutelly right.
For some reason when I compiled your project I got wrong data,
but when I implemented your class in my code, everything is ok and I get:
3495ff69d34671d1e15b33a63c1379fdedd3a32a
for
aaaaaaaaaa
Thank you VERY much, and sorry for inconviniance
Vlada
|
|
|
|
 |
|
 |
Hi,
I have checking the linker, the class locations etc...but likethe previous thread "adding iostream and fstream" once I include #include the compiler cannot find the Update functions. This problem is preplexing because whether or not I change the namespace I see this error. Also, the compiler recognizes all the other SHA1.h functions fine. I would appreciate if someone can help me with this. Here is the error I get:
---------------------
$ make
g++ -g -Wall -c CSHA1Test.cpp
g++ SHA1.o CSHA1Test.o -o csha1
CSHA1Test.o(.text+0x71): In function `HashString()':
/home/betamaz/courses/cs290f/CSHA1/CSHA1Test.cpp:59: undefined reference to `CSHA1::Update(unsigned char*, unsigned long)'
collect2: ld returned 1 exit status
---------------------
and I've tried different linking mechanisms, but the result is all the same. I believe I am linking it correctly:
CPP = g++
CPPFLAGS = -g -Wall -c
RM = rm -f
all: csha1
clean:
-rm CSHA1Test.o SHA1.o csha1
csha1: SHA1.o CSHA1Test.o
$(CPP) SHA1.o CSHA1Test.o -o csha1
SHA1.o: SHA1.cpp SHA1.h
$(CPP) $(CPPFLAGS) SHA1.cpp
CSHA1Test.o: CSHA1Test.cpp CSHA1Test.h SHA1.h
$(CPP) $(CPPFLAGS) CSHA1Test.cpp
---------------------
Just in case you need more information: For simplicity, I've placed the SHA1.cpp/h files in the same directory as CSHA1Test.cpp and here is the change in CSHA1Test.cpp that creates the compiler error:
#define WIN32_LEAN_AND_MEAN
#include
#include // Needed for strlen(...)
#include
//using namespace std;
#include "CSHA1Test.h" // Test driver header file
#include "SHA1.h" // The CSHA1 class
int main(int argc, char *argv[])
{
//...everything else is the same
---------------------
Thanks in advance.
|
|
|
|
 |
|
 |
Hi
I had a similar problem (relating to the linker and not to the compiler -- I was getting a "undefined reference to" message from the linker).
RESOLUTION: ensure that SHA1.h is the first include before every other #include statement in your source code (client application). This worked for me while using latest version of g++ on Linux.
POSSIBLE CAUSE: I guess that there should be two independent causes to result in this problem. Let your code that depends on SHA1.cpp be called the client application.
1. the iostream library, or some other library that it uses, defines UINT_32 and UINT_8, if they are not already defined, to be unsigned long while SHA1.cpp defines it to unsigned int on Linux
2. g++ compiles SHA1.cpp first and independently of the client application both depending on SHA1.h.
So the object file from SHA1.cpp has definition for UINT_32 as unsigned int while the object file for the client application has definition for UINT_32 as unsigned long. Since C++ is a more strongly typed language that C, it thinks that foo(unsigned int) and foo(unsinged long) are two different functions -- which is essential for function overloading purposes. later program can potentially define it to be unsigned long. Clearly the signatures of all functions would potentially become incompatible.
COMMENT: The resolution is not a nice one but works for me. A better resolution would be to rework the following part of SHA1.h so that it resolves things properly on non-microsoft platforms as well.
#ifndef UINT_32
#ifdef _MSC_VER
#define UINT_8 unsigned __int8
#define UINT_32 unsigned __int32
#else
#define UINT_8 unsigned char
#if (ULONG_MAX == 0xFFFFFFFF)
#define UINT_32 unsigned long
#else
#define UINT_32 unsigned int
#endif
#endif
#endif
Regards,
Kapali
Kapali Viswanthan
|
|
|
|
 |
|
 |
bonjour tout le monde
j'ai essayer de compiler SHA1 mais j'ai pas pu l'exécuter VSC++, je trouve ce message d'erreur:
--------------------Configuration: SHA1 - Win32 Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/SHA1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
SHA1.exe - 2 error(s), 0 warning(s)
help!!!!please...........
|
|
|
|
 |
|
 |
Hi,
Firstly love the code and have used it in a few of my personal projects now.
But I just started to use it today and I made a few minor changes to your API.
void Update(UINT_8 *data, UINT_32 len);
bool HashFile(char *szFileName);
void Transform(UINT_32 *state, UINT_8 *buffer);
changed to
void Update(const UINT_8 *data, UINT_32 len);
bool HashFile(const char *szFileName);
void Transform(UINT_32 *state, const UINT_8 *buffer);
The difference being that data, szFileName and buffer are now all const pointers, rather than non const. Since you don't actually change what data these pointers point to it is safe to make them const, and in my opinion is good to do this so that programmers know that their buffers aren't going to be altered. Also this made it easier to use std::string's c_str() method which returns a const char*, thus I now don't have to cast away the constness.
Either way thanks for the great code.
Andrew
-- modified at 10:31 Tuesday 10th January, 2006
I just noticed someone else posted about this a few months ago. Sorry for the dup.
|
|
|
|
 |
|
 |
The spirit of open source is alive and kicking...
Amir
|
|
|
|
 |
|
 |
good job! I gave you 5 cause my app now works excellent with your code!
best regards
zoz
|
|
|
|
 |
|
 |
Hi
I was wanting to utilise this algorithm in a project that #includes iostream and fstream, but am getting an error saying
[Linker error] undefined reference to `CSHA1::Update(unsigned char*, unsigned long)'
If I remove these includes everything works fine. I am a long way into the project and don't want to have to recode using stdio.h -- is there an obvious reason as to why I'm having these problems??
thanks
|
|
|
|
 |
|
 |
I've noticed the same problem when using this class on Ubuntu 6.06
(but I didn't know the reason for it).
On the other side, the class links fine on Fedora (FC5 and FC6T3).
Miroslav Rajcic
|
|
|
|
 |
|
 |
Just noticed more recent post with the fix: moving SHA1 #include to the top of the code resolved the issue.
Miroslav Rajcic
|
|
|
|
 |
|
 |
I solved this problem by changing following lines.
#include <memory> // Needed for memset and memcpy
#ifdef SHA1_UTILITY_FUNCTIONS
#include <cstdio> // Needed for file access and sprintf
#include <cstring> // Needed for strcat and strcpy
#endif
good luck.
-- modified at 3:48 Wednesday 1st November, 2006
|
|
|
|
 |