(Name name, int hashAlg, int iterations, byte [] salt)
| 224 | } |
| 225 | |
| 226 | static byte [] |
| 227 | hashName(Name name, int hashAlg, int iterations, byte [] salt) |
| 228 | throws NoSuchAlgorithmException |
| 229 | { |
| 230 | MessageDigest digest; |
| 231 | switch (hashAlg) { |
| 232 | case Digest.SHA1: |
| 233 | digest = MessageDigest.getInstance("sha-1"); |
| 234 | break; |
| 235 | default: |
| 236 | throw new NoSuchAlgorithmException("Unknown NSEC3 algorithm" + |
| 237 | "identifier: " + |
| 238 | hashAlg); |
| 239 | } |
| 240 | byte [] hash = null; |
| 241 | for (int i = 0; i <= iterations; i++) { |
| 242 | digest.reset(); |
| 243 | if (i == 0) |
| 244 | digest.update(name.toWireCanonical()); |
| 245 | else |
| 246 | digest.update(hash); |
| 247 | if (salt != null) |
| 248 | digest.update(salt); |
| 249 | hash = digest.digest(); |
| 250 | } |
| 251 | return hash; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Hashes a name with the parameters of this NSEC3 record. |
no test coverage detected