OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * FNV1A64 Hash |
| 3 * http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param |
| 4 * |
| 5 * ***** BEGIN LICENSE BLOCK ***** |
| 6 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 7 * |
| 8 * The contents of this file are subject to the Mozilla Public License Version |
| 9 * 1.1 (the "License"); you may not use this file except in compliance with |
| 10 * the License. You may obtain a copy of the License at |
| 11 * http://www.mozilla.org/MPL/ |
| 12 * |
| 13 * Software distributed under the License is distributed on an "AS IS" basis, |
| 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 15 * for the specific language governing rights and limitations under the |
| 16 * License. |
| 17 * |
| 18 * The Original Code is the Netscape security libraries. |
| 19 * |
| 20 * The Initial Developer of the Original Code is |
| 21 * Netscape Communications Corporation. |
| 22 * Portions created by the Initial Developer are Copyright (C) 1994-2000 |
| 23 * the Initial Developer. All Rights Reserved. |
| 24 * |
| 25 * Contributor(s): |
| 26 * Adam Langley, Google Inc. |
| 27 * |
| 28 * Alternatively, the contents of this file may be used under the terms of |
| 29 * either the GNU General Public License Version 2 or later (the "GPL"), or |
| 30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| 31 * in which case the provisions of the GPL or the LGPL are applicable instead |
| 32 * of those above. If you wish to allow use of your version of this file only |
| 33 * under the terms of either the GPL or the LGPL, and not to allow others to |
| 34 * use your version of this file under the terms of the MPL, indicate your |
| 35 * decision by deleting the provisions above and replace them with the notice |
| 36 * and other provisions required by the GPL or the LGPL. If you do not delete |
| 37 * the provisions above, a recipient may use your version of this file under |
| 38 * the terms of any one of the MPL, the GPL or the LGPL. |
| 39 * |
| 40 * ***** END LICENSE BLOCK ***** */ |
| 41 |
| 42 /* $Id: fnv1a64.c,v 1.0 2010/08/09 13:00:00 agl%google.com Exp $ */ |
| 43 |
| 44 #include "prtypes.h" |
| 45 #include "prnetdb.h" |
| 46 |
| 47 /* Older versions of Visual C++ don't support the 'ull' suffix. */ |
| 48 #ifdef _MSC_VER |
| 49 static const PRUint64 FNV1A64_OFFSET_BASIS = 14695981039346656037ui64; |
| 50 static const PRUint64 FNV1A64_PRIME = 1099511628211ui64; |
| 51 #else |
| 52 static const PRUint64 FNV1A64_OFFSET_BASIS = 14695981039346656037ull; |
| 53 static const PRUint64 FNV1A64_PRIME = 1099511628211ull; |
| 54 #endif |
| 55 |
| 56 void FNV1A64_Init(PRUint64* digest) { |
| 57 *digest = FNV1A64_OFFSET_BASIS; |
| 58 } |
| 59 |
| 60 void FNV1A64_Update(PRUint64* digest, const unsigned char *data, |
| 61 unsigned int length) { |
| 62 unsigned int i; |
| 63 |
| 64 for (i = 0; i < length; i++) { |
| 65 *digest ^= data[i]; |
| 66 *digest *= FNV1A64_PRIME; |
| 67 } |
| 68 } |
| 69 |
| 70 void FNV1A64_Final(PRUint64 *digest) { |
| 71 *digest = PR_htonll(*digest); |
| 72 } |
OLD | NEW |