def __init__(self, input_shape, residual_shape, featmaps): super(ProjectionShortcut, self).__init__() self.input_shape = input_shape self.residual_shape = residual_shape [N_in, C_in, H_out, W_out] = residual_shape pH = compute_padding(H_out, input_shape[ROW_AXIS], 1, 2) pW = compute_padding(W_out, input_shape[COL_AXIS], 1, 2) convArgs_ = convArgs.copy() convArgs_['padding'] = (pH, pW) self.conv = ModelConv2D(in_channels=input_shape[CHANNEL_AXIS], out_channels=featmaps, kernel_size=(1, 1), stride=(2, 2), **convArgs_) self.output_shape = [N_in, C_in + self.conv.out_channels*n_divs, H_out, W_out]
def compute_premaster_secret(self, username, salt, verifier, client_A, scs=DEFAULT_SECRETSIZE): '''Calculates server premaster secret''' l = self.N.bit_length() padded_client_A = compute_padding(client_A, l) padded_server_B = compute_padding(self.B, l) u = obj_to_int(compute_hash(padded_client_A, padded_server_B)) self.premaster_secret = pow(client_A * pow(verifier, u, self.N), self.b, self.N) return self.premaster_secret
def __init__(self, input_shape, filter_size, featmaps, shortcut, convArgs, bnArgs, actArgs): super(ResidualBlock, self).__init__() self.input_shape = input_shape self.featmaps = featmaps self.shortcut_type = shortcut pad_type = convArgs['padding'] convArgs_ = convArgs.copy() [N_in, num_features1, H_in, W_in] = input_shape if opts.use_group_norm: self.bn1 = GroupNormBlock(num_channels=num_features1) else: self.bn1 = ModelBN(num_features=num_features1, **bnArgs) self.act = Activation(actArgs['activation']) if self.shortcut_type == 'regular': convArgs_['padding'] = (1, 1) if pad_type is 'same' else (0, 0) stride = (1, 1) H_out = H_in W_out = W_in elif self.shortcut_type == 'projection': H_out = int(np.ceil(H_in / 2)) W_out = int(np.ceil(W_in / 2)) pH = compute_padding(H_out, H_in, filter_size[0], 2) pW = compute_padding(W_out, W_in, filter_size[-1], 2) convArgs_['padding'] = (pH, pW) stride = (2, 2) self.conv1 = ModelConv2D(in_channels=num_features1, out_channels=featmaps, kernel_size=filter_size, stride=stride, **convArgs_) # self.bn2 = ModelBN(num_features=self.conv1.out_channels*n_divs, **bnArgs) if opts.use_group_norm: self.bn2 = GroupNormBlock(num_channels=self.conv1.out_channels*n_divs) else: self.bn2 = ModelBN(num_features=self.conv1.out_channels*n_divs, **bnArgs) convArgs_['padding'] = (1, 1) if pad_type is 'same' else (0, 0) self.conv2 = ModelConv2D(in_channels=self.conv1.out_channels * n_divs, out_channels=featmaps, kernel_size=filter_size, stride=(1, 1), **convArgs_) residual_shape = [N_in, featmaps, H_out, W_out] if shortcut == 'regular': self.shortcut = IdentityShortcut(input_shape, residual_shape) elif shortcut == 'projection': self.shortcut = ProjectionShortcut(input_shape, residual_shape, featmaps) self.output_shape = self.shortcut.output_shape self.residual_shape = residual_shape
def compute_premaster_secret(self, salt, server_B): '''Calculates client premaster secret''' server_B = obj_to_int(server_B) l = self.N.bit_length() padded_client_A = compute_padding(self.A, l) padded_server_B = compute_padding(server_B, l) u = obj_to_int(compute_hash(padded_client_A, padded_server_B)) x = self._compute_x(salt, self.username, self.password) padded_g = compute_padding(self.g, l) k = obj_to_int(compute_hash(self.N, padded_g)) t1 = server_B - k * pow(self.g, x, self.N) t2 = self.a + u * x self.premaster_secret = pow(t1, t2, self.N) return self.premaster_secret
def compute_server_values(self, username, verifier, byte_size=DEFAULT_SECRETSIZE): '''Calculates server values''' l = self.N.bit_length() self.b = obj_to_int(get_randombytes(byte_size)) k = obj_to_int(compute_hash(self.N, compute_padding(self.g, l))) self.B = (k * verifier + pow(self.g, self.b, self.N)) % self.N return self.B
def __init__(self, input_shape, featmaps, filter_size, actArgs, bnArgs, block_i=1): super(LearnVectorBlock, self).__init__() self.block_i = block_i self.input_shape = input_shape [_, num_features1, H_in, W_in] = input_shape out_channels = featmaps self.bn1 = BatchNorm2d(num_features=num_features1, **bnArgs) self.act = Activation(**actArgs) in_channels1 = self.bn1.num_features pH = compute_padding(H_in, H_in, filter_size[0], 1) pW = compute_padding(W_in, W_in, filter_size[-1], 1) padding1 = (pH, pW) self.conv1 = Conv2d(in_channels=in_channels1, out_channels=featmaps, kernel_size=filter_size, bias=False, padding=padding1) in_channels2 = self.conv1.out_channels self.bn2 = BatchNorm2d(num_features=in_channels2, **bnArgs) self.conv2 = Conv2d(in_channels=in_channels2, out_channels=featmaps, kernel_size=filter_size, bias=False, padding=padding1) self.output_shape = [None, featmaps, H_in, W_in]
def compute_premaster_secret(self, salt, server_B): ''' Calculates client premaster secret u = SHA1(PAD(A) | PAD(B)) k = SHA1(N | PAD(g)) x = SHA1(s | SHA1(I | ":" | P)) <premaster secret> = (B - (k * g^x)) ^ (a + (u * x)) % N ''' server_B = obj_to_int(server_B) l = self.N.bit_length() padded_client_A = compute_padding(self.A, l) padded_server_B = compute_padding(server_B, l) u = obj_to_int(compute_hash(padded_client_A, padded_server_B)) x = self._compute_x(salt, self.username, self.password) padded_g = compute_padding(self.g, l) k = obj_to_int(compute_hash(self.N, padded_g)) t1 = server_B - k * pow(self.g, x, self.N) t2 = self.a + u * x self.premaster_secret = pow(t1, t2, self.N) return self.premaster_secret