Returns ``True`` if bcrypt should be used.
352445
def is_enabled():
    """"""
    enabled = getattr(settings, "BCRYPT_ENABLED", True)
    if not enabled:
        return False
    # Are we under a test?
    if hasattr(mail, 'outbox'):
        return getattr(settings, "BCRYPT_ENABLED_UNDER_TEST", False)
    return True
31581
def verify(password, hash):
    
    _, algorithm, cost, salt, password_hash = hash.split("$")

    password = pbkdf2.pbkdf2_hex(password, salt, int(cost) * 500)

    return _safe_str_cmp(password, password_hash)
1350228
private function checkKey()
    {
        if (empty($this->key) || empty($this->authentication)) {
            $key = $this->secureRandomKey();
            $message = 'No binary key provided to encrypt/decrypt data.';

            if ($key !== null) {
                $message .= sprintf(" For example: base64_decode('%s')", base64_encode($key));
            }

            throw new RuntimeException($message);
        }
    }
932442
def btc_is_p2sh_address( address ):
    
    vb = keylib.b58check.b58check_version_byte( address )
    if vb == multisig_version_byte:
        return True
    else:
        return False
205317
def Verify(self):
        
        if not self.Hash.ToBytes() == GetGenesis().Hash.ToBytes():
            return False

        bc = GetBlockchain()

        if not bc.ContainsBlock(self.Index):
            return False

        if self.Index > 0:
            prev_header = GetBlockchain().GetHeader(self.PrevHash.ToBytes())

            if prev_header is None:
                return False

            if prev_header.Index + 1 != self.Index:
                return False

            if prev_header.Timestamp >= self.Timestamp:
                return False

        # this should be done to actually verify the block
        if not Helper.VerifyScripts(self):
            return False

        return True
591385
function bcryptAsm(stdlib, foreign, heap) {
        "use asm";

        var HEAP32 = new stdlib.Uint32Array(heap);

        var BLOWFISH_NUM_ROUNDS = 16;
        var S_offset = 0x0000;          // length 0x1000 octets
        var S1_offset = 0x0400;
        var S2_offset = 0x0800;
        var S3_offset = 0x0C00;
        var P_offset = 0x1000;          // length 0x0048 (72) octets
        var P_last_offset = 0x1044;
        var crypt_ciphertext_offset = 0x1048;    // length 0x0018 (24) octets
        var LR_offset = 0x01060;        // length 8 octets
        var password_offset = 0x1068;   // length 0x0048 (72) octets
        var salt_offset = 0x10b0;       // length 0x0048 (72) octets, 18 uint32
        var P_LEN = 18;
        var S_LEN = 1024;

        function encrypt(offset) {
            offset = offset|0;
            var i = 0;
            var n = 0;
            var L = 0;
            var R = 0;
            var imax = 0;
            imax = P_offset | BLOWFISH_NUM_ROUNDS << 2;
            
            L = HEAP32[offset >> 2]|0;
            R = HEAP32[offset + 4 >> 2]|0;

            L = L ^ HEAP32[P_offset>>2];
            for (i = P_offset; (i|0) < (imax|0);) {
                // Feistel substitution on left word
                i = (i + 4)>>>0;
                R = R ^ (
                    ((HEAP32[(L >>> 22)>>2] >>> 0) +
                    (HEAP32[(S1_offset | (L >>> 14 & 0x3ff))>>2] >>> 0) ^
                    (HEAP32[(S2_offset | (L >>> 6 & 0x3ff))>>2])) +
                    (HEAP32[(S3_offset | (L << 2 & 0x3ff))>>2] >>> 0)
                ) ^ HEAP32[i>>2];

                // Feistel substitution on right word
                i = (i + 4)>>>0;
                L = L ^ (
                    ((HEAP32[(R >>> 22)>>2] >>> 0) +
                    (HEAP32[(S1_offset | (R >>> 14 & 0x3ff))>>2] >>> 0) ^
                    (HEAP32[(S2_offset | (R >>> 6 & 0x3ff))>>2])) +
                    (HEAP32[(S3_offset | (R << 2 & 0x3ff))>>2] >>> 0)
                ) ^ HEAP32[i>>2];
            }
            HEAP32[offset>>2] = R ^ HEAP32[P_last_offset>>2];
            HEAP32[(offset+4)>>2] = L;
        }

        function expandKey(offset) {
            offset = offset|0;
            var i = 0;
            var off = 0;

            off = P_offset|0;
            for (i = 0; (i|0) < (P_LEN|0); i = (i+1)|0) {
                HEAP32[off >> 2] = HEAP32[off >> 2] ^ HEAP32[offset >> 2];
                offset = (offset + 4)|0;
                off = (off + 4)|0;
            }

            HEAP32[LR_offset >> 2] = 0;
            HEAP32[LR_offset + 4 >> 2] = 0;

            off = P_offset;
            for (i = 0; (i|0) < (P_LEN|0); i = (i+2)|0) {
                encrypt(LR_offset);
                HEAP32[off >> 2] = HEAP32[LR_offset >> 2];
                HEAP32[off + 4 >> 2] = HEAP32[LR_offset + 4 >> 2];
                off = (off + 8)|0;
            }

            off = S_offset;
            for (i = 0; (i|0) < (S_LEN|0); i = (i+2)|0) {
                encrypt(LR_offset);
                HEAP32[off >> 2] = HEAP32[LR_offset >> 2];
                HEAP32[off + 4 >> 2] = HEAP32[LR_offset + 4 >> 2];
                off = (off + 8)|0;
            }
        }

        function expandLoop(i, counterEnd, maxIterations) {
            i = i|0;
            counterEnd = counterEnd|0;
            maxIterations = maxIterations|0;
            var j = 0;

            for (j = 0; (j|0) <= (maxIterations|0); j = (j+1)|0) {
                if ((i>>>0) > (counterEnd>>>0)) break;
                expandKey(password_offset);
                expandKey(salt_offset);
                i = (i+1)>>>0;
            }
            return i|0;
        }

        return {
            encrypt: encrypt,
            expandLoop: expandLoop
        };
    }
1119252
def scrypt_mcf(scrypt, password, salt=None, N=SCRYPT_N, r=SCRYPT_r, p=SCRYPT_p,
               prefix=SCRYPT_MCF_PREFIX_DEFAULT):
    
    if isinstance(password, unicode):
        password = password.encode('utf8')
    elif not isinstance(password, bytes):
        raise TypeError('password must be a unicode or byte string')
    if salt is not None and not isinstance(salt, bytes):
        raise TypeError('salt must be a byte string')
    if salt is not None and not (1 <= len(salt) <= 16):
        raise ValueError('salt must be 1-16 bytes')
    if r > 255:
        raise ValueError('scrypt_mcf r out of range [1,255]')
    if p > 255:
        raise ValueError('scrypt_mcf p out of range [1,255]')
    if N > 2**31:
        raise ValueError('scrypt_mcf N out of range [2,2**31]')
    if b'\0' in password:
        raise ValueError('scrypt_mcf password must not contain zero bytes')

    if prefix == SCRYPT_MCF_PREFIX_s1:
        if salt is None:
            salt = os.urandom(16)
        hash = scrypt(password, salt, N, r, p)
        return _scrypt_mcf_encode_s1(N, r, p, salt, hash)
    elif prefix == SCRYPT_MCF_PREFIX_7 or prefix == SCRYPT_MCF_PREFIX_ANY:
        if salt is None:
            salt = os.urandom(32)
        salt = _cb64enc(salt)
        hash = scrypt(password, salt, N, r, p, 32)
        return _scrypt_mcf_encode_7(N, r, p, salt, hash)
    else:
        raise ValueError("Unrecognized MCF format")
1325613
def check_password(raw_password, enc_password):
    
    l = enc_password.split('$')
    #only password of built-in user can split to 3
    if len(l)==3:
        algo, salt, hsh = l
        return hsh == get_hexdigest(algo, salt, raw_password)
    else:
        return False
689853
def crypt(self, data, crypt_type):
        """"""

        # Error check the data
        if not data:
            return ''
        if len(data) % self.block_size != 0:
            if crypt_type == des.DECRYPT: # Decryption must work on 8 byte blocks
                raise ValueError("Invalid data length, data must be a multiple of " + str(self.block_size) + " bytes\n" + data + ".")
            if not self.getPadding():
                raise ValueError("Invalid data length, data must be a multiple of " + str(self.block_size) + " bytes\n. Try setting the optional padding character")
            else:
                data += (self.block_size - (len(data) % self.block_size)) * self.getPadding()
            # print "Len of data: %f" % (len(data) / self.block_size)

        if self.getMode() == CBC:
            if self.getIV():
                iv = self.__String_to_BitList(self.getIV())
            else:
                raise ValueError("For CBC mode, you must supply the Initial Value (IV) for ciphering")

        # Split the data into blocks, crypting each one seperately
        i = 0
        result = []
        while i < len(data):
            block = self.__String_to_BitList(data[i:i+8])

            # Xor with IV if using CBC mode
            if self.getMode() == CBC:
                if crypt_type == des.ENCRYPT:
                    block = list(map(lambda x, y: x ^ y, block, iv))

                processed_block = self.__des_crypt(block, crypt_type)

                if crypt_type == des.DECRYPT:
                    processed_block = list(map(lambda x, y: x ^ y, processed_block, iv))
                    iv = block
                else:
                    iv = processed_block
            else:
                processed_block = self.__des_crypt(block, crypt_type)


            # Add the resulting crypted block to our list
            result.append(self.__BitList_to_String(processed_block))
            i += 8

        # Return the full crypted string
        if _pythonMajorVersion < 3:
            return ''.join(result)
        else:
            return bytes.fromhex('').join(result)
415189
public boolean isMature() {
        if (!isCoinBase())
            return true;

        if (getConfidence().getConfidenceType() != ConfidenceType.BUILDING)
            return false;

        return getConfidence().getDepthInBlocks() >= params.getSpendableCoinbaseDepth();
    }
995345
def bcrypt_set_password(self, raw_password):
    
    if not is_enabled() or raw_password is None:
        _set_password(self, raw_password)
    else:
        salt = bcrypt.gensalt(get_rounds())
        self.password = 'bc$' + bcrypt.hashpw(smart_str(raw_password), salt)
1074631
def verify(self, chksum):
        
        total = 0

        # Add together all bytes
        for byte in self.data:
            total += byteToInt(byte)

        # Add checksum too
        total += byteToInt(chksum)

        # Only keep low bits
        total &= 0xFF

        # Check result
        return total == 0xFF
643816
def check_power(self):
    """"""
    packet = bytearray(16)
    packet[0] = 1
    response = self.send_packet(0x6a, packet)
    err = response[0x22] | (response[0x23] << 8)
    if err == 0:
      payload = self.decrypt(bytes(response[0x38:]))
      if type(payload[0x4]) == int:
        if payload[0x4] == 1 or payload[0x4] == 3 or payload[0x4] == 0xFD:
          state = True
        else:
          state = False
      else:
        if ord(payload[0x4]) == 1 or ord(payload[0x4]) == 3 or ord(payload[0x4]) == 0xFD:
          state = True
        else:
          state = False
      return state
32425
def decrypt(self, encrypted):
        
        fernet = Fernet(self.decryption_cipher_key)
        return fernet.decrypt(encrypted)
570031
function encryptPassword(password, callback) {
        bcrypt.gen_salt(workFactor, function(err, salt) {
            if (err) callback(err);
            
            bcrypt.encrypt(password, salt, function(err, hashedPassword) {
                if (err) callback(err);
                
                callback(null, hashedPassword);
            });
        });
    }
1082807
public boolean isPassphraseProtected() {
		ByteArrayReader bar = new ByteArrayReader(keyblob);

		try {
			String type = bar.readString();

			if (type.equals("none")) {
				return false;
			}

			if (type.equalsIgnoreCase("3des-cbc")) {
				return true;
			}
		} catch (IOException ioe) {
		} finally {
			try {
				bar.close();
			} catch (IOException e) {
			}
		}

		return false;
	}
1349002
def decrypt(self, value):
        """"""
        try:
            value, timestamp, signature = value.split("|")
        except ValueError:
            return None
        if check_signature(signature, self.secret, value + timestamp, encoding=self.encoding):
            return base64.b64decode(value).decode(self.encoding)