SHA-1: Difference between revisions

m
Line 374:
Using Windows API. See [https://msdn.microsoft.com/en-us/library/aa379886.aspx CryptAcquireContext], [https://msdn.microsoft.com/en-us/library/aa379908.aspx CryptCreateHash], [https://msdn.microsoft.com/en-us/library/aa380202.aspx CryptHashData] and [https://msdn.microsoft.com/en-us/library/aa379947.aspx CryptGetHashParam] on MSDN.
 
<lang fortran>module sha1_msha1_mod
use kernel32
use advapi32
Line 390:
integer(BYTE) :: hash(SHA1LEN)
integer(UINT64) :: filesize
 
dwStatus = 0
filesize = 0
hFile = CreateFile(trim(name) // char(0), GENERIC_READ, FILE_SHARE_READ, NULL, &
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL)
 
if (hFile == INVALID_HANDLE_VALUE) then
dwStatus = GetLastError()
Line 401:
return
end if
if (CryptAcquireContext(hProv, NULL, NULL, PROV_RSA_FULL, &
CRYPT_VERIFYCONTEXT) == FALSE) then
dwStatus = GetLastError()
print *, "CryptAcquireContext failed."
goto 3
end if
if (CryptCreateHash(hProv, CALG_SHA1, 0_ULONG_PTR, 0_DWORD, hHash) == FALSE) then
 
dwStatus = GetLastError()
print *, "CryptCreateHash failed."
go to 2
end if
do
status = ReadFile(hFile, loc(buffer), BUFLEN, loc(nRead), NULL)
if (status == FALSE .or. nRead == 0) exit
filesize = filesize + nRead
Line 427:
end if
end do
if (status == FALSE) then
dwStatus = GetLastError()
Line 433:
go to 1
end if
nRead = SHA1LEN
if (CryptGetHashParam(hHash, HP_HASHVAL, hash, nRead, 0) == FALSE) then
Line 439:
print *, "CryptGetHashParam failed.", status, nRead, dwStatus
end if
1 status = CryptDestroyHash(hHash)
2 status = CryptReleaseContext(hProv, 0)
Line 445:
end subroutine
end module
 
program sha1
use sha1_msha1_mod
implicit none
integer :: n, m, i, j
Line 454:
integer(BYTE) :: hash(SHA1LEN)
integer(UINT64) :: filesize
n = command_argument_count()
do i = 1, n
Anonymous user