1 // Copyright 2017 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 //////////////////////////////////////////////////////////////////////////////// 16 17 package com.google.crypto.tink.hybrid; 18 19 import com.google.crypto.tink.proto.HashType; 20 import java.security.NoSuchAlgorithmException; 21 22 final class HybridUtil { 23 /** 24 * Returns the HMAC algorithm name corresponding to a hash type. 25 * 26 * @param hash the hash type 27 * @return the JCE's HMAC algorithm name for the hash. 28 */ toHmacAlgo(HashType hash)29 public static String toHmacAlgo(HashType hash) throws NoSuchAlgorithmException { 30 switch (hash) { 31 case SHA1: 32 return "HmacSha1"; 33 case SHA224: 34 return "HmacSha224"; 35 case SHA256: 36 return "HmacSha256"; 37 case SHA384: 38 return "HmacSha384"; 39 case SHA512: 40 return "HmacSha512"; 41 default: 42 throw new NoSuchAlgorithmException("hash unsupported for HMAC: " + hash); 43 } 44 } 45 HybridUtil()46 private HybridUtil() {} 47 } 48