LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-30-2004, 07:21 PM   #1
Nerox
Member
 
Registered: Jul 2004
Location: Spain
Posts: 111

Rep: Reputation: 20
Create a hash with any data


Hi, i would want to know how to create a hash of a data.

I've already know crypt() and how to create a md5 hash with it, but problems come when any byte is equal to zero, because de crypt function declaration is:

char * crypt(const char * key , const char *salt);

e.g:

struct data{
int x;
int y;
int z;
}

struct data var1;
var1.x = 5;
var1.y = 0;
var1.z = 5;

hash = crypt((char *) &var1, "$1$");
/*the hash is: (for example) $1$ZH$YGGYInw6oH0P29Ze6hlo.1

again, with different data, (pay attention to var2.z)

*/

struct data var2;
var2.x = 5;
var2.y = 0;
var2.z = 115;

hash = crypt((char *) &var2, "$1$");

/*the hash will be the same, since var2.z parameter which is different from first, is not passed, because var2.y is null-byte, and the string ends */

Could anybody show me another function to create a hash which i can pass null-byte data??

Thanks In Advance
 
Old 07-30-2004, 09:31 PM   #2
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Yeah, it looks like crypt() was intended for use with ASCII passwords, so a null value isn't really possible. Check out mhash. Haven't used it, but it looks something like what you want.
 
Old 07-31-2004, 03:13 AM   #3
RobertP
Member
 
Registered: Jan 2004
Location: Manitoba, Canada
Distribution: Debian
Posts: 453

Rep: Reputation: 32
If you just need a simple, quick and dirty hash, you can add or xor the bytes.
 
Old 07-31-2004, 09:15 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Does this help?
"man 3 sha" or "man md5"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create MD5 hash from string trouby Linux - General 9 02-07-2012 08:08 PM
get my data back after mdadm --create RicoCarmen Linux - General 1 10-23-2005 08:18 PM
Create ISO files from audio, data and video cds Bateman Linux - General 4 06-19-2005 04:02 AM
Cannot mount CD-R to create a backup data CD ccin1492 Linux - Hardware 8 11-24-2004 02:15 PM
how to create a partition for swapping data between win2000pro and red hat 9.0? Mephisto3285 Linux - Newbie 3 07-04-2003 06:11 PM


All times are GMT -5. The time now is 04:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration