/*
* sha1.c
*
- * Copyright (C) 2012 Eric Biggers
- *
* Parts of this file are based on public domain code written by Steve Reid.
+ */
+
+/*
+ * Copyright (C) 2012 Eric Biggers
*
- * wimlib - Library for working with WIM files
+ * This file is part of wimlib, a library for working with WIM files.
*
- * This library is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option) any
- * later version.
+ * wimlib is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
*
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
*
- * You should have received a copy of the GNU Lesser General Public License along
- * with this library; if not, write to the Free Software Foundation, Inc., 59
- * Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with wimlib; if not, see http://www.gnu.org/licenses/.
*/
#include "util.h"
for (i = 0; i < SHA1_HASH_SIZE; i++) {
md[i] = (u8)((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
}
-
- i = 0;
- memset(context->buffer, 0, 64);
- memset(context->state, 0, 20);
- memset(context->count, 0, 8);
- memset(finalcount, 0, 8); /* SWR */
-
- sha1_transform(context->state, context->buffer);
}
void sha1_buffer(const void *buffer, size_t len, void *md)
}
-/* Calculates the SHA1 message digest given the name of a file.
- * @buf must point to a buffer of length 20 bytes into which the message digest
- * is written.
+/* Calculates the SHA1 message digest given the name of a file. @md must point
+ * to a buffer of length 20 bytes into which the message digest is written.
*/
int sha1sum(const char *filename, void *md)
{
fp = fopen(filename, "rb");
if (!fp) {
- ERROR("Cannot open the file `%s' for reading: %m\n", filename);
+ ERROR_WITH_ERRNO("Cannot open the file `%s' for reading",
+ filename);
return WIMLIB_ERR_OPEN;
}
ret = sha1_stream(fp, md);
+ if (ret != 0) {
+ ERROR_WITH_ERRNO("Error calculating SHA1 message digest of "
+ "`%s'", filename);
+ }
fclose(fp);
return ret;
}