(byte[] publicSeed, byte[] secretSeed, OTSHashAddress otsHashAddress)
| 231 | } |
| 232 | |
| 233 | private void initialize(byte[] publicSeed, byte[] secretSeed, OTSHashAddress otsHashAddress) |
| 234 | { |
| 235 | if (otsHashAddress == null) |
| 236 | { |
| 237 | throw new NullPointerException("otsHashAddress == null"); |
| 238 | } |
| 239 | /* prepare addresses */ |
| 240 | LTreeAddress lTreeAddress = (LTreeAddress)new LTreeAddress.Builder() |
| 241 | .withLayerAddress(otsHashAddress.getLayerAddress()).withTreeAddress(otsHashAddress.getTreeAddress()) |
| 242 | .build(); |
| 243 | HashTreeAddress hashTreeAddress = (HashTreeAddress)new HashTreeAddress.Builder() |
| 244 | .withLayerAddress(otsHashAddress.getLayerAddress()).withTreeAddress(otsHashAddress.getTreeAddress()) |
| 245 | .build(); |
| 246 | |
| 247 | /* iterate indexes */ |
| 248 | for (int indexLeaf = 0; indexLeaf < (1 << treeHeight); indexLeaf++) |
| 249 | { |
| 250 | /* generate leaf */ |
| 251 | otsHashAddress = (OTSHashAddress)new OTSHashAddress.Builder() |
| 252 | .withLayerAddress(otsHashAddress.getLayerAddress()).withTreeAddress(otsHashAddress.getTreeAddress()) |
| 253 | .withOTSAddress(indexLeaf).withChainAddress(otsHashAddress.getChainAddress()) |
| 254 | .withHashAddress(otsHashAddress.getHashAddress()).withKeyAndMask(otsHashAddress.getKeyAndMask()) |
| 255 | .build(); |
| 256 | /* |
| 257 | * import WOTSPlusSecretKey as its needed to calculate the public |
| 258 | * key on the fly |
| 259 | */ |
| 260 | wotsPlus.importKeys(wotsPlus.getWOTSPlusSecretKey(secretSeed, otsHashAddress), publicSeed); |
| 261 | WOTSPlusPublicKeyParameters wotsPlusPublicKey = wotsPlus.getPublicKey(otsHashAddress); |
| 262 | lTreeAddress = (LTreeAddress)new LTreeAddress.Builder().withLayerAddress(lTreeAddress.getLayerAddress()) |
| 263 | .withTreeAddress(lTreeAddress.getTreeAddress()).withLTreeAddress(indexLeaf) |
| 264 | .withTreeHeight(lTreeAddress.getTreeHeight()).withTreeIndex(lTreeAddress.getTreeIndex()) |
| 265 | .withKeyAndMask(lTreeAddress.getKeyAndMask()).build(); |
| 266 | XMSSNode node = XMSSNodeUtil.lTree(wotsPlus, wotsPlusPublicKey, lTreeAddress); |
| 267 | |
| 268 | hashTreeAddress = (HashTreeAddress)new HashTreeAddress.Builder() |
| 269 | .withLayerAddress(hashTreeAddress.getLayerAddress()) |
| 270 | .withTreeAddress(hashTreeAddress.getTreeAddress()).withTreeIndex(indexLeaf) |
| 271 | .withKeyAndMask(hashTreeAddress.getKeyAndMask()).build(); |
| 272 | while (!stack.isEmpty() && stack.peek().getHeight() == node.getHeight()) |
| 273 | { |
| 274 | /* add to authenticationPath if leafIndex == 1 */ |
| 275 | int indexOnHeight = indexLeaf / (1 << node.getHeight()); |
| 276 | if (indexOnHeight == 1) |
| 277 | { |
| 278 | authenticationPath.add(node); |
| 279 | } |
| 280 | /* store next right authentication node */ |
| 281 | if (indexOnHeight == 3 && node.getHeight() < (treeHeight - k)) |
| 282 | { |
| 283 | treeHashInstances.get(node.getHeight()).setNode(node); |
| 284 | } |
| 285 | if (indexOnHeight >= 3 && (indexOnHeight & 1) == 1 && node.getHeight() >= (treeHeight - k) |
| 286 | && node.getHeight() <= (treeHeight - 2)) |
| 287 | { |
| 288 | if (retain.get(node.getHeight()) == null) |
| 289 | { |
| 290 | LinkedList<XMSSNode> queue = new LinkedList<XMSSNode>(); |
no test coverage detected