aboutsummaryrefslogtreecommitdiff
path: root/act/act_v0/act_v0.h
blob: c499a9287c9708bb09838775a453058e95229dc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright 2023 Google LLC.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef PRIVATE_JOIN_AND_COMPUTE_ANONYMOUS_COUNTING_TOKENS_ACT_V0_ACT_V0_H_
#define PRIVATE_JOIN_AND_COMPUTE_ANONYMOUS_COUNTING_TOKENS_ACT_V0_ACT_V0_H_

#include <memory>
#include <string>
#include <tuple>
#include <vector>

#include "act/act.h"
#include "act/act.pb.h"
#include "private_join_and_compute/util/status.inc"

namespace private_join_and_compute {
namespace anonymous_counting_tokens {

// An implementation of vO Anonymous Counting Tokens.
class AnonymousCountingTokensV0 : public AnonymousCountingTokens {
 public:
  static std::unique_ptr<AnonymousCountingTokens> Create();

  // Returns a fresh set of Server parameters corresponding to these
  // SchemeParameters. Fails with InvalidArgument if the parameters don't
  // correspond to ACT v0.
  StatusOr<ServerParameters> GenerateServerParameters(
      const SchemeParameters& scheme_parameters) override;

  // Returns a fresh set of Client parameters corresponding to these
  // SchemeParameters and ServerPublicParameters. Fails with InvalidArgument if
  // the parameters don't correspond to ACT v0.
  StatusOr<ClientParameters> GenerateClientParameters(
      const SchemeParameters& scheme_parameters,
      const ServerPublicParameters& server_public_parameters) override;

  // Verifies the consistency of the  ClientPublicParameters with the Server and
  // scheme parameters. Fails with InvalidArgument if the parameters don't
  // correspond to ACT v0.
  Status CheckClientParameters(
      const SchemeParameters& scheme_parameters,
      const ClientPublicParameters& client_public_parameters,
      const ServerPublicParameters& server_public_parameters,
      const ServerPrivateParameters& server_private_parameters) override;

  // Returns a tuple of client_fingerprints, TokensRequest and
  // TokensRequestPrivateState for the given set of messages. Fails with
  // InvalidArgument if the parameters don't correspond to ACT v0.
  StatusOr<std::tuple<std::vector<std::string>, TokensRequest,
                      TokensRequestPrivateState>>
  GenerateTokensRequest(
      absl::Span<const std::string> messages,
      const SchemeParameters& scheme_parameters,
      const ClientPublicParameters& client_public_parameters,
      const ClientPrivateParameters& client_private_parameters,
      const ServerPublicParameters& server_public_parameters) override;

  // Returns OkStatus on a valid request. Fails with InvalidArgument if the
  // parameters don't correspond to ACT v0.
  Status CheckTokensRequest(
      absl::Span<const std::string> client_fingerprints,
      const TokensRequest& tokens_request,
      const SchemeParameters& scheme_parameters,
      const ClientPublicParameters& client_public_parameters,
      const ServerPublicParameters& server_public_parameters,
      const ServerPrivateParameters& server_private_parameters) override;

  // Returns the TokensResponse. Fails with InvalidArgument if the parameters
  // don't correspond to ACT v0.
  StatusOr<TokensResponse> GenerateTokensResponse(
      const TokensRequest& tokens_request,
      const SchemeParameters& scheme_parameters,
      const ClientPublicParameters& client_public_parameters,
      const ServerPublicParameters& server_public_parameters,
      const ServerPrivateParameters& server_private_parameters) override;

  // Returns OkStatus on a valid response. Fails with InvalidArgument if the
  // parameters don't correspond to ACT v0.
  Status VerifyTokensResponse(
      absl::Span<const std::string> messages,
      const TokensRequest& tokens_request,
      const TokensRequestPrivateState& tokens_request_private_state,
      const TokensResponse& tokens_response,
      const SchemeParameters& scheme_parameters,
      const ClientPublicParameters& client_public_parameters,
      const ClientPrivateParameters& client_private_parameters,
      const ServerPublicParameters& server_public_parameters) override;

  // Returns a vector of tokens corresponding to the supplied messages. Fails
  // with InvalidArgument if the parameters don't correspond to ACT v0.
  StatusOr<std::vector<Token>> RecoverTokens(
      absl::Span<const std::string> messages,
      const TokensRequest& tokens_request,
      const TokensRequestPrivateState& tokens_request_private_state,
      const TokensResponse& tokens_response,
      const SchemeParameters& scheme_parameters,
      const ClientPublicParameters& client_public_parameters,
      const ClientPrivateParameters& client_private_parameters,
      const ServerPublicParameters& server_public_parameters) override;

  // Returns OkStatus on valid tokens. Fails with InvalidArgument if the
  // parameters don't correspond to ACT v0.
  Status VerifyToken(
      std::string m, const Token& token,
      const SchemeParameters& scheme_parameters,
      const ServerPublicParameters& server_public_parameters,
      const ServerPrivateParameters& server_private_parameters) override;

 protected:
  AnonymousCountingTokensV0() = default;
};

}  // namespace anonymous_counting_tokens
}  // namespace private_join_and_compute

#endif  // PRIVATE_JOIN_AND_COMPUTE_ANONYMOUS_COUNTING_TOKENS_ACT_V0_ACT_V0_H_