xref: /aosp_15_r20/external/federated-compute/fcp/secagg/shared/compute_session_id.h (revision 14675a029014e728ec732f129a32e299b2da0601)
1 /*
2  * Copyright 2018 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef FCP_SECAGG_SHARED_COMPUTE_SESSION_ID_H_
18 #define FCP_SECAGG_SHARED_COMPUTE_SESSION_ID_H_
19 
20 #include <string>
21 
22 #include "fcp/secagg/shared/secagg_messages.pb.h"
23 
24 namespace fcp {
25 namespace secagg {
26 
27 inline constexpr int kSha256Length = 32;
28 
29 // A SessionId is the id of a given SecAgg session. Every session's SessionId
30 // should be unique.
31 typedef struct SessionId {
32   std::string data;
33 } SessionId;
34 
35 // Computes the session ID for a specific protocol session given the first
36 // message (ShareKeysRequest) sent by the server.
37 //
38 // The session id is computed as a SHA-256 hash of the concatenation of all the
39 // PairOfPublicKeys inside the request message (in the same order in which they
40 // appear in the message). More specifically, for each PairOfPublicKeys inside
41 // the message, the following are concatenated to the input of the hash
42 // function:
43 //
44 // - The length of the prng ECDH public key
45 // - The prng ECDH public key
46 // - The length of the encryption ECDH public key
47 // - The encryption ECDH public key
48 //
49 // Lengths are prepended to the keys so that the encoding is not ambiguous and
50 // there are no unexpected collisions.
51 //
52 // The output of this method is 32 bytes long.
53 SessionId ComputeSessionId(const ShareKeysRequest& request);
54 
55 }  // namespace secagg
56 }  // namespace fcp
57 
58 #endif  // FCP_SECAGG_SHARED_COMPUTE_SESSION_ID_H_
59