Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Script Library
 SHA-1 Function

Author  Topic 

SamC
White Water Yakist

3467 Posts

Posted - 2006-02-07 : 10:21:56
Anyone know of an open-source SQL stored proc that'll do SHA-1 hash?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-02-07 : 10:29:01
would md5 work? we use that.

EDIT:
i think that pwdencrypt('stuff') uses sha1.
EDIT 2:
here's the article:
http://www.alleged.org.uk/pdc/2003/sqlserver.html


Go with the flow & have fun! Else fight the flow
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-02-07 : 10:44:57
This is where I normal kick off for Encryption stuff:

http://pajhome.org.uk/crypt/md5/

There's a link on there for a SQL solution to http://wonko.com/xpcrypt/ - which is dead but it pops up again on http://www.15seconds.com/component/pg000272.htm

Kristen
Go to Top of Page

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2006-02-07 : 10:59:00
FWIW, here's an extended stored procedure implementing MD5: http://www.codeproject.com/database/xp_md5.asp

--
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt? http://www.insidesql.de/blogs
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2006-02-07 : 11:00:13
quote:
Originally posted by Kristen

This is where I normal kick off for Encryption stuff:

http://pajhome.org.uk/crypt/md5/

There's a link on there for a SQL solution to http://wonko.com/xpcrypt/ - which is dead but it pops up again on http://www.15seconds.com/component/pg000272.htm


The xp_crypt is now at http://www.activecrypt.com/products.html

but I didn't want to install a dll. Seems like a T-SQL SP wouldn't be *too* hard to write based on PAJ's (http://pajhome.org.uk/crypt/md5/sha1src.html) JavaScript implementation of SHA-1. The trick would be to translate the looping structures into set-based SQL for efficent execution.

Any takers?
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2006-02-07 : 11:07:02
quote:
Originally posted by Frank Kalis

FWIW, here's an extended stored procedure implementing MD5: http://www.codeproject.com/database/xp_md5.asp

Another (very good) C++ implementation.

There is probably a very good reason why these hash functions are not written in T-SQL.

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-02-07 : 11:43:48
quote:
Originally posted by SamC

quote:
Originally posted by Kristen

This is where I normal kick off for Encryption stuff:

http://pajhome.org.uk/crypt/md5/

There's a link on there for a SQL solution to http://wonko.com/xpcrypt/ - which is dead but it pops up again on http://www.15seconds.com/component/pg000272.htm


The xp_crypt is now at http://www.activecrypt.com/products.html

but I didn't want to install a dll. Seems like a T-SQL SP wouldn't be *too* hard to write based on PAJ's (http://pajhome.org.uk/crypt/md5/sha1src.html) JavaScript implementation of SHA-1. The trick would be to translate the looping structures into set-based SQL for efficent execution.

Any takers?



We have been using xp_crypt for several years with no problem.

You do have to pay for it, but it provides a number of hash and encryption stored procedures.

There is also a free version that does MD5, DES, SHA1, SHA-256, and SHA-512 hashes.




CODO ERGO SUM
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-02-07 : 17:17:54
I gotta subscribe to this...we are unraveling som eproblem with that on OS/390...

Thanks for bringing this up Sam



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-02-08 : 03:14:21
"eProblem"

They're the only type of problems I get these days



Kristen
Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2006-02-08 : 03:55:48
It's probably worth pointing out that, in strict cryptographical terms, both MD5 and SHA-1 have been shown to be broken:

http://en.wikipedia.org/wiki/SHA-1#Cryptanalysis_of_SHA-1
http://en.wikipedia.org/wiki/Xiaoyun_Wang
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2006-02-08 : 09:35:06
quote:
Originally posted by Arnold Fribble

It's probably worth pointing out that, in strict cryptographical terms, both MD5 and SHA-1 have been shown to be broken:

http://en.wikipedia.org/wiki/SHA-1#Cryptanalysis_of_SHA-1
http://en.wikipedia.org/wiki/Xiaoyun_Wang
Arnold - I like the follow up but...
quote:
In early 2005, Rijmen and Oswald published an attack on a reduced version of SHA-1 — 53 out of 80 rounds — which finds collisions with a complexity of fewer than 2**80 operations
2**80 is a large number...

I am still intreagued by the idea of a T-SQL implementation of SHA-1. NIST's paper on SHA-N algorithms isn't rocket science. While easy to implement in non-set based languages, there are several items in the loops which a set-based language could take advantage of: Initialization of W(i) for example.

Of most concern is the lack of boolean operators in SQL (I should say boolean operators which transform data.), e.g. XOR or ROTL (rotate left) which could be implemented with integer arithmetic, but begins to dampen spirit, not to mention the performance
Go to Top of Page

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2006-02-08 : 09:43:16
You might want to check out these threads:
http://snipurl.com/mccq
http://snipurl.com/mcco

--
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt? http://www.insidesql.de/blogs
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2006-02-08 : 11:06:59
quote:
Originally posted by Frank Kalis

You might want to check out these threads:
http://snipurl.com/mccq
http://snipurl.com/mcco
Learn something new all the time...

bitwise SQL operators:
quote:

& (Bitwise AND) Bitwise AND (two operands).
| (Bitwise OR) Bitwise OR (two operands).
^ (Bitwise Exclusive OR) Bitwise exclusive OR (two operands).


And... a nice SHA-1 T-SQL function by Steve Kass, suitable for password encryption (strings of 55 bytes or less). Could be written using set operations?
Go to Top of Page

Frank Kalis
Constraint Violating Yak Guru

413 Posts

Posted - 2006-02-09 : 03:16:43
quote:

...
Could be written using set operations?
...


Try it out! Once you're done, I would love to have a copy.


--
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt? http://www.insidesql.de/blogs
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2006-02-09 : 07:55:46
quote:
Originally posted by Frank Kalis

Try it out! Once you're done, I would love to have a copy.

I get stumped with a vector initialized with 16 values, the remaining 64 values are calculated: W(i) = f(W(i-16))

Values of W 17 .. 79 are undefined and an INSERT statement takes the values "as they are" as opposed to "as they are calculated". Calculating W(79) references W(79-16), a value which is undefined. It'll take a loop, not an INSERT to calculate all the values. Unless there's a trick to get around this problem.

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-02-09 : 15:58:24
Me too, put me on the list



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page
   

- Advertisement -