From 7b1a37bd91ea0d708ce168d00aab3c9248d0e5a1 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Wed, 6 Aug 2014 11:21:38 -0700 Subject: [PATCH] Make registration ID optionally extended. --- .../org/whispersystems/libaxolotl/util/KeyHelper.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/util/KeyHelper.java b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/util/KeyHelper.java index 9a393aa5d7..3a2909223f 100644 --- a/libaxolotl/src/main/java/org/whispersystems/libaxolotl/util/KeyHelper.java +++ b/libaxolotl/src/main/java/org/whispersystems/libaxolotl/util/KeyHelper.java @@ -38,11 +38,18 @@ public class KeyHelper { * Generate a registration ID. Clients should only do this once, * at install time. * + * @param extendedRange By default (false), the generated registration + * ID is sized to require the minimal possible protobuf + * encoding overhead. Specify true if the caller needs + * the full range of MAX_INT at the cost of slightly + * higher encoding overhead. * @return the generated registration ID. */ - public static int generateRegistrationId() { + public static int generateRegistrationId(boolean extendedRange) { try { - return SecureRandom.getInstance("SHA1PRNG").nextInt(16380) + 1; + SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); + if (extendedRange) return secureRandom.nextInt(Integer.MAX_VALUE - 1) + 1; + else return secureRandom.nextInt(16380) + 1; } catch (NoSuchAlgorithmException e) { throw new AssertionError(e); }