Note: We no longer publish the latest version of our code here. We primarily use a kumc-bmi github organization. The heron ETL repository, in particular, is not public. Peers in the informatics community should see MultiSiteDev for details on requesting access.

source: webrtc/webrtc/test/libtest/helpers/random_encryption.cc @ 0:4bda6873e34c

pub_scrub_3792 tip
Last change on this file since 0:4bda6873e34c was 0:4bda6873e34c, checked in by Michael Prittie <mprittie@…>, 6 years ago

Scrubbed password for publication.

File size: 1.6 KB
Line 
1/*
2 *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/test/libtest/include/random_encryption.h"
12
13#include <math.h>
14#include <stdlib.h>
15
16#include <algorithm>
17
18#include "webrtc/video_engine/vie_defines.h"
19
20static int Saturate(int value, int min, int max) {
21  return std::min(std::max(value, min), max);
22}
23
24RandomEncryption::RandomEncryption(unsigned int rand_seed) {
25  srand(rand_seed);
26}
27
28// Generates some completely random data with roughly the right length.
29void RandomEncryption::GenerateRandomData(unsigned char* out_data, int bytes_in,
30                                          int* bytes_out) {
31  int out_length = MakeUpSimilarLength(bytes_in);
32  for (int i = 0; i < out_length; i++) {
33    // The modulo will skew the random distribution a bit, but I think it
34    // will be random enough.
35    out_data[i] = static_cast<unsigned char>(rand() % 256);
36  }
37  *bytes_out = out_length;
38}
39
40// Makes up a length within +- 50 of the original length, without
41// overstepping the contract for encrypt / decrypt.
42int RandomEncryption::MakeUpSimilarLength(int original_length) {
43  int sign = rand() - RAND_MAX / 2;
44  int length = original_length + sign * rand() % 50;
45
46  return Saturate(length, 0, static_cast<int>(webrtc::kViEMaxMtu));
47}
Note: See TracBrowser for help on using the repository browser.