1 // Copyright 2021 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 #include "tink/experimental/pqcrypto/signature/util/enums.h" 18 19 namespace crypto { 20 namespace tink { 21 namespace util { 22 23 namespace pb = google::crypto::tink; 24 25 // static SubtleToProto(subtle::DilithiumSeedExpansion expansion)26pb::DilithiumSeedExpansion EnumsPqcrypto::SubtleToProto( 27 subtle::DilithiumSeedExpansion expansion) { 28 switch (expansion) { 29 case subtle::DilithiumSeedExpansion::SEED_EXPANSION_SHAKE: 30 return pb::DilithiumSeedExpansion::SEED_EXPANSION_SHAKE; 31 case subtle::DilithiumSeedExpansion::SEED_EXPANSION_AES: 32 return pb::DilithiumSeedExpansion::SEED_EXPANSION_AES; 33 default: 34 return pb::DilithiumSeedExpansion::SEED_EXPANSION_UNKNOWN; 35 } 36 } 37 38 // static ProtoToSubtle(pb::DilithiumSeedExpansion expansion)39subtle::DilithiumSeedExpansion EnumsPqcrypto::ProtoToSubtle( 40 pb::DilithiumSeedExpansion expansion) { 41 switch (expansion) { 42 case pb::DilithiumSeedExpansion::SEED_EXPANSION_SHAKE: 43 return subtle::DilithiumSeedExpansion::SEED_EXPANSION_SHAKE; 44 case pb::DilithiumSeedExpansion::SEED_EXPANSION_AES: 45 return subtle::DilithiumSeedExpansion::SEED_EXPANSION_AES; 46 default: 47 return subtle::DilithiumSeedExpansion::SEED_EXPANSION_UNKNOWN; 48 } 49 } 50 51 // static SubtleToProto(subtle::SphincsHashType type)52pb::SphincsHashType EnumsPqcrypto::SubtleToProto(subtle::SphincsHashType type) { 53 switch (type) { 54 case subtle::SphincsHashType::HARAKA: 55 return pb::SphincsHashType::HARAKA; 56 case subtle::SphincsHashType::SHA256: 57 return pb::SphincsHashType::SHA256; 58 case subtle::SphincsHashType::SHAKE256: 59 return pb::SphincsHashType::SHAKE256; 60 default: 61 return pb::SphincsHashType::HASH_TYPE_UNSPECIFIED; 62 } 63 } 64 65 // static ProtoToSubtle(pb::SphincsHashType type)66subtle::SphincsHashType EnumsPqcrypto::ProtoToSubtle(pb::SphincsHashType type) { 67 switch (type) { 68 case pb::SphincsHashType::HARAKA: 69 return subtle::SphincsHashType::HARAKA; 70 case pb::SphincsHashType::SHA256: 71 return subtle::SphincsHashType::SHA256; 72 case pb::SphincsHashType::SHAKE256: 73 return subtle::SphincsHashType::SHAKE256; 74 default: 75 return subtle::SphincsHashType::HASH_TYPE_UNSPECIFIED; 76 } 77 } 78 79 // static SubtleToProto(subtle::SphincsVariant variant)80pb::SphincsVariant EnumsPqcrypto::SubtleToProto( 81 subtle::SphincsVariant variant) { 82 switch (variant) { 83 case subtle::SphincsVariant::ROBUST: 84 return pb::SphincsVariant::ROBUST; 85 case subtle::SphincsVariant::SIMPLE: 86 return pb::SphincsVariant::SIMPLE; 87 default: 88 return pb::SphincsVariant::VARIANT_UNSPECIFIED; 89 } 90 } 91 92 // static ProtoToSubtle(pb::SphincsVariant variant)93subtle::SphincsVariant EnumsPqcrypto::ProtoToSubtle( 94 pb::SphincsVariant variant) { 95 switch (variant) { 96 case pb::SphincsVariant::ROBUST: 97 return subtle::SphincsVariant::ROBUST; 98 case pb::SphincsVariant::SIMPLE: 99 return subtle::SphincsVariant::SIMPLE; 100 default: 101 return subtle::SphincsVariant::VARIANT_UNSPECIFIED; 102 } 103 } 104 105 // static SubtleToProto(subtle::SphincsSignatureType type)106pb::SphincsSignatureType EnumsPqcrypto::SubtleToProto( 107 subtle::SphincsSignatureType type) { 108 switch (type) { 109 case subtle::SphincsSignatureType::FAST_SIGNING: 110 return pb::SphincsSignatureType::FAST_SIGNING; 111 case subtle::SphincsSignatureType::SMALL_SIGNATURE: 112 return pb::SphincsSignatureType::SMALL_SIGNATURE; 113 default: 114 return pb::SphincsSignatureType::SIG_TYPE_UNSPECIFIED; 115 } 116 } 117 118 // static ProtoToSubtle(pb::SphincsSignatureType type)119subtle::SphincsSignatureType EnumsPqcrypto::ProtoToSubtle( 120 pb::SphincsSignatureType type) { 121 switch (type) { 122 case pb::SphincsSignatureType::FAST_SIGNING: 123 return subtle::SphincsSignatureType::FAST_SIGNING; 124 case pb::SphincsSignatureType::SMALL_SIGNATURE: 125 return subtle::SphincsSignatureType::SMALL_SIGNATURE; 126 default: 127 return subtle::SphincsSignatureType::SIG_TYPE_UNSPECIFIED; 128 } 129 } 130 131 } // namespace util 132 } // namespace tink 133 } // namespace crypto 134