Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.security.hpke;
import static com.yahoo.security.ArrayUtils.concat;
import static com.yahoo.security.hpke.Constants.HPKE_V1_LABEL;
/**
* Utilities for labeled KDF expand/extract used by both DHKEM and HPKE
*
* @author vekterli
*/
class LabeledKdfUtils {
/**
* Section 4 Cryptographic Dependencies:
*
*
*
* We take in the KDF and suite ID explicitly, to allow method reuse between KEM and HPKE.
*/
static byte[] labeledExpandForSuite(Kdf kdf, byte[] prk, byte[] suiteId, byte[] label, byte[] info, int nBytesToExpand/*L*/) {
byte[] labeledInfo = concat(i2osp2((short)nBytesToExpand), HPKE_V1_LABEL, suiteId, label, info);
return kdf.expand(prk, labeledInfo, nBytesToExpand);
}
/**
*
* I2OSP(n, w):
* Convert non-negative integer n to a w-length, big-endian byte string,
* as described in [RFC8017].
*
*
* We provide a simple 2OSP(n, 2) specialization since we don't need to
* encode arbitrary BigIntegers for labels.
*/
static byte[] i2osp2(short v) {
return new byte[] { (byte)(v >>> 8), (byte)(v & 0xff) };
}
}